Skip to content

Commit 3c9545d

Browse files
Merge branch '11.4' into 11.5
2 parents 6b4e234 + f3d9714 commit 3c9545d

File tree

53 files changed

+575
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+575
-418
lines changed

src/Event/Value/Test/Issue/TestTrigger.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ public function isTest(): true
2424
return true;
2525
}
2626

27-
/**
28-
* Your own code triggers an issue in your own code.
29-
*/
30-
public function isSelf(): true
31-
{
32-
return true;
33-
}
34-
3527
public function asString(): string
3628
{
3729
return 'issue triggered by test code';

src/Runner/IssueFilter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function shouldBeProcessed(DeprecationTriggered|ErrorTriggered|NoticeTrig
4444
return false;
4545
}
4646

47-
if ($this->source->ignoreSelfDeprecations() && $event->trigger()->isSelf()) {
47+
if ($this->source->ignoreSelfDeprecations() &&
48+
($event->trigger()->isTest() || $event->trigger()->isSelf())) {
4849
return false;
4950
}
5051

src/Runner/TestResult/Issue.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace PHPUnit\TestRunner\TestResult\Issues;
1111

12+
use function array_keys;
13+
use function count;
1214
use PHPUnit\Event\Code\Test;
1315

1416
/**
@@ -134,4 +136,10 @@ public function stackTrace(): ?string
134136
{
135137
return $this->stackTrace;
136138
}
139+
140+
public function triggeredInTest(): bool
141+
{
142+
return count($this->triggeringTests) === 1 &&
143+
$this->file === $this->triggeringTests[array_keys($this->triggeringTests)[0]]['test']->file();
144+
}
137145
}

src/TextUI/Output/Default/ProgressPrinter/ProgressPrinter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
141141
return;
142142
}
143143

144-
if ($this->source->ignoreSelfDeprecations() && $event->trigger()->isSelf()) {
144+
if ($this->source->ignoreSelfDeprecations() &&
145+
($event->trigger()->isTest() || $event->trigger()->isSelf())) {
145146
return;
146147
}
147148

@@ -171,7 +172,8 @@ public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): voi
171172
return;
172173
}
173174

174-
if ($this->source->ignoreSelfDeprecations() && $event->trigger()->isSelf()) {
175+
if ($this->source->ignoreSelfDeprecations() &&
176+
($event->trigger()->isTest() || $event->trigger()->isSelf())) {
175177
return;
176178
}
177179

src/TextUI/Output/Default/ResultPrinter.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -395,24 +395,26 @@ private function printIssueList(string $type, array $issues, bool $stackTrace =
395395
$body .= trim($issue->stackTrace()) . PHP_EOL . PHP_EOL;
396396
}
397397

398-
$body .= 'Triggered by:';
398+
if (!$issue->triggeredInTest()) {
399+
$body .= 'Triggered by:';
399400

400-
$triggeringTests = $issue->triggeringTests();
401+
$triggeringTests = $issue->triggeringTests();
401402

402-
ksort($triggeringTests);
403+
ksort($triggeringTests);
403404

404-
foreach ($triggeringTests as $triggeringTest) {
405-
$body .= PHP_EOL . PHP_EOL . '* ' . $triggeringTest['test']->id();
405+
foreach ($triggeringTests as $triggeringTest) {
406+
$body .= PHP_EOL . PHP_EOL . '* ' . $triggeringTest['test']->id();
406407

407-
if ($triggeringTest['count'] > 1) {
408-
$body .= sprintf(
409-
' (%d times)',
410-
$triggeringTest['count'],
411-
);
412-
}
408+
if ($triggeringTest['count'] > 1) {
409+
$body .= sprintf(
410+
' (%d times)',
411+
$triggeringTest['count'],
412+
);
413+
}
413414

414-
if ($triggeringTest['test']->isTestMethod()) {
415-
$body .= PHP_EOL . ' ' . $triggeringTest['test']->file() . ':' . $triggeringTest['test']->line();
415+
if ($triggeringTest['test']->isTestMethod()) {
416+
$body .= PHP_EOL . ' ' . $triggeringTest['test']->file() . ':' . $triggeringTest['test']->line();
417+
}
416418
}
417419
}
418420

tests/end-to-end/_files/baseline/generate-baseline-no-baseline-configured/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/end-to-end/_files/baseline/generate-baseline-suppressed-with-ignored-suppression/phpunit.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="../../../../../phpunit.xsd"
44
cacheResult="false"
5+
bootstrap="src/Source.php"
56
>
67
<testsuites>
78
<testsuite name="default">
@@ -15,7 +16,9 @@
1516
ignoreSuppressionOfNotices="true"
1617
ignoreSuppressionOfPhpNotices="true"
1718
ignoreSuppressionOfWarnings="true"
18-
ignoreSuppressionOfPhpWarnings="true"
19-
>
19+
ignoreSuppressionOfPhpWarnings="true">
20+
<include>
21+
<directory>src</directory>
22+
</include>
2023
</source>
2124
</phpunit>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Baseline;
11+
12+
use const E_USER_DEPRECATED;
13+
use const E_USER_NOTICE;
14+
use const E_USER_WARNING;
15+
use function trigger_error;
16+
use Serializable;
17+
18+
final class Source
19+
{
20+
public function triggerDeprecation(): void
21+
{
22+
$this->deprecation();
23+
}
24+
25+
public function triggerNotice(): void
26+
{
27+
$this->notice();
28+
}
29+
30+
public function triggerWarning(): void
31+
{
32+
$this->warning();
33+
}
34+
35+
public function triggerPhpDeprecation(): void
36+
{
37+
$this->phpDeprecation();
38+
}
39+
40+
public function triggerPhpNoticeAndWarning(): void
41+
{
42+
$this->phpNoticeAndWarning();
43+
}
44+
45+
private function deprecation(): void
46+
{
47+
@trigger_error('deprecation', E_USER_DEPRECATED);
48+
}
49+
50+
private function notice(): void
51+
{
52+
@trigger_error('notice', E_USER_NOTICE);
53+
}
54+
55+
private function warning(): void
56+
{
57+
@trigger_error('warning', E_USER_WARNING);
58+
}
59+
60+
private function phpDeprecation(): void
61+
{
62+
@$o = new class implements Serializable
63+
{
64+
public function serialize(): void
65+
{
66+
}
67+
68+
public function unserialize(string $data): void
69+
{
70+
}
71+
};
72+
}
73+
74+
private function phpNoticeAndWarning(): void
75+
{
76+
$o = new class
77+
{
78+
public static $a = 'b';
79+
};
80+
81+
@$o->a;
82+
}
83+
}

tests/end-to-end/_files/baseline/generate-baseline-suppressed-with-ignored-suppression/tests/Test.php

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,41 @@
99
*/
1010
namespace PHPUnit\TestFixture\Baseline;
1111

12-
use const E_USER_DEPRECATED;
13-
use const E_USER_NOTICE;
14-
use const E_USER_WARNING;
15-
use function trigger_error;
1612
use PHPUnit\Framework\TestCase;
17-
use Serializable;
1813

1914
final class Test extends TestCase
2015
{
2116
public function testDeprecation(): void
2217
{
23-
@trigger_error('deprecation', E_USER_DEPRECATED);
18+
(new Source)->triggerDeprecation();
2419

2520
$this->assertTrue(true);
2621
}
2722

2823
public function testNotice(): void
2924
{
30-
@trigger_error('notice', E_USER_NOTICE);
25+
(new Source)->triggerNotice();
3126

3227
$this->assertTrue(true);
3328
}
3429

3530
public function testWarning(): void
3631
{
37-
@trigger_error('warning', E_USER_WARNING);
32+
(new Source)->triggerWarning();
3833

3934
$this->assertTrue(true);
4035
}
4136

4237
public function testPhpDeprecation(): void
4338
{
44-
@$o = new class implements Serializable
45-
{
46-
public function serialize(): void
47-
{
48-
}
49-
50-
public function unserialize(string $data): void
51-
{
52-
}
53-
};
39+
(new Source)->triggerPhpDeprecation();
5440

5541
$this->assertTrue(true);
5642
}
5743

5844
public function testPhpNoticeAndWarning(): void
5945
{
60-
$o = new class
61-
{
62-
public static $a = 'b';
63-
};
64-
65-
@$o->a;
46+
(new Source)->triggerPhpNoticeAndWarning();
6647

6748
$this->assertTrue(true);
6849
}

tests/end-to-end/_files/baseline/generate-baseline-suppressed/phpunit.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="../../../../../phpunit.xsd"
44
cacheResult="false"
5+
bootstrap="src/Source.php"
56
>
67
<testsuites>
78
<testsuite name="default">
@@ -10,5 +11,8 @@
1011
</testsuites>
1112

1213
<source baseline="baseline.xml">
14+
<include>
15+
<directory>src</directory>
16+
</include>
1317
</source>
1418
</phpunit>

0 commit comments

Comments
 (0)