Skip to content

Commit

Permalink
Do not print "Triggered by" section for issues triggered in test code
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 26, 2024
1 parent 05c1687 commit f3d9714
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 188 deletions.
8 changes: 8 additions & 0 deletions src/Runner/TestResult/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
namespace PHPUnit\TestRunner\TestResult\Issues;

use function array_keys;
use function count;
use PHPUnit\Event\Code\Test;

/**
Expand Down Expand Up @@ -112,4 +114,10 @@ public function triggeringTests(): array
{
return $this->triggeringTests;
}

public function triggeredInTest(): bool
{
return count($this->triggeringTests) === 1 &&
$this->file === $this->triggeringTests[array_keys($this->triggeringTests)[0]]['test']->file();
}
}
30 changes: 17 additions & 13 deletions src/TextUI/Output/Default/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,24 +389,28 @@ private function printIssueList(string $type, array $issues): void
$issue->line(),
);

$body = trim($issue->description()) . PHP_EOL . PHP_EOL . 'Triggered by:';
$body = trim($issue->description()) . PHP_EOL . PHP_EOL;

$triggeringTests = $issue->triggeringTests();
if (!$issue->triggeredInTest()) {
$body .= 'Triggered by:';

ksort($triggeringTests);
$triggeringTests = $issue->triggeringTests();

foreach ($triggeringTests as $triggeringTest) {
$body .= PHP_EOL . PHP_EOL . '* ' . $triggeringTest['test']->id();
ksort($triggeringTests);

if ($triggeringTest['count'] > 1) {
$body .= sprintf(
' (%d times)',
$triggeringTest['count'],
);
}
foreach ($triggeringTests as $triggeringTest) {
$body .= PHP_EOL . PHP_EOL . '* ' . $triggeringTest['test']->id();

if ($triggeringTest['count'] > 1) {
$body .= sprintf(
' (%d times)',
$triggeringTest['count'],
);
}

if ($triggeringTest['test']->isTestMethod()) {
$body .= PHP_EOL . ' ' . $triggeringTest['test']->file() . ':' . $triggeringTest['test']->line();
if ($triggeringTest['test']->isTestMethod()) {
$body .= PHP_EOL . ' ' . $triggeringTest['test']->file() . ':' . $triggeringTest['test']->line();
}
}
}

Expand Down
5 changes: 0 additions & 5 deletions tests/end-to-end/cli/fail-on/fail-on-deprecation-output.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ message
1) %sDeprecationTest.php:%d
message

Triggered by:

* PHPUnit\TestFixture\TestRunnerStopping\DeprecationTest::testOne
%sDeprecationTest.php:%d

OK, but there were issues!
Tests: 3, Assertions: 3, Deprecations: 1, PHPUnit Deprecations: 1.
5 changes: 0 additions & 5 deletions tests/end-to-end/cli/fail-on/fail-on-notice-output.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,5 @@ Time: %s, Memory: %s
1) %sNoticeTest.php:%d
message

Triggered by:

* PHPUnit\TestFixture\TestRunnerStopping\NoticeTest::testOne
%sNoticeTest.php:%d

OK, but there were issues!
Tests: 2, Assertions: 2, Notices: 1.
5 changes: 0 additions & 5 deletions tests/end-to-end/cli/fail-on/fail-on-warning-output.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,5 @@ Time: %s, Memory: %s
1) %sWarningTest.php:%d
message

Triggered by:

* PHPUnit\TestFixture\TestRunnerStopping\WarningTest::testOne
%sWarningTest.php:%d

OK, but there were issues!
Tests: 2, Assertions: 2, Warnings: 1.
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,8 @@ Time: %s, Memory: %s
1) %sTest.php:25
deprecation triggered by method

Triggered by:

* PHPUnit\TestFixture\DeprecationTrigger\Test::testDeprecation
%sTest.php:23

2) %sTest.php:26
deprecation triggered by function

Triggered by:

* PHPUnit\TestFixture\DeprecationTrigger\Test::testDeprecation
%sTest.php:23

OK, but there were issues!
Tests: 1, Assertions: 1, Deprecations: 2.
10 changes: 0 additions & 10 deletions tests/end-to-end/deprecation-trigger/details.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,8 @@ Time: %s, Memory: %s
1) %sTest.php:25
deprecation triggered by method

Triggered by:

* PHPUnit\TestFixture\DeprecationTrigger\Test::testDeprecation
%sTest.php:23

2) %sTest.php:26
deprecation triggered by function

Triggered by:

* PHPUnit\TestFixture\DeprecationTrigger\Test::testDeprecation
%sTest.php:23

OK, but there were issues!
Tests: 1, Assertions: 1, Deprecations: 2.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,8 @@ Time: %s, Memory: %s
1) %sIgnoreDeprecationsTest.php:%d
message

Triggered by:

* PHPUnit\TestFixture\Event\IgnoreDeprecationsTest::testTwo
%sIgnoreDeprecationsTest.php:%d

2) %sIgnoreDeprecationsTest.php:%d
message

Triggered by:

* PHPUnit\TestFixture\Event\IgnoreDeprecationsTest::testTwoErrorGetLast
%sIgnoreDeprecationsTest.php:%d

OK, but there were issues!
Tests: 4, Assertions: 6, Deprecations: 2.
75 changes: 0 additions & 75 deletions tests/end-to-end/generic/outcome-and-issues.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -107,130 +107,55 @@ skipped message
1) %sOutcomesAndIssuesTest.php:%d
warning message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testSuccessWithWarning
%sOutcomesAndIssuesTest.php:%d

2) %sOutcomesAndIssuesTest.php:%d
warning message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testFailWithWarning
%sOutcomesAndIssuesTest.php:%d

3) %sOutcomesAndIssuesTest.php:%d
warning message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testErrorWithWarning
%sOutcomesAndIssuesTest.php:%d

4) %sOutcomesAndIssuesTest.php:%d
warning message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testIncompleteWithWarning
%sOutcomesAndIssuesTest.php:%d

5) %sOutcomesAndIssuesTest.php:%d
warning message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testSkippedWithWarning
%sOutcomesAndIssuesTest.php:%d

--

5 tests triggered 5 notices:

1) %sOutcomesAndIssuesTest.php:%d
notice message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testSuccessWithNotice
%sOutcomesAndIssuesTest.php:%d

2) %sOutcomesAndIssuesTest.php:%d
notice message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testFailWithNotice
%sOutcomesAndIssuesTest.php:%d

3) %sOutcomesAndIssuesTest.php:%d
notice message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testErrorWithNotice
%sOutcomesAndIssuesTest.php:%d

4) %sOutcomesAndIssuesTest.php:%d
notice message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testIncompleteWithNotice
%sOutcomesAndIssuesTest.php:%d

5) %sOutcomesAndIssuesTest.php:%d
notice message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testSkippedWithNotice
%sOutcomesAndIssuesTest.php:%d

--

5 tests triggered 5 deprecations:

1) %sOutcomesAndIssuesTest.php:%d
deprecation message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testSuccessWithDeprecation
%sOutcomesAndIssuesTest.php:%d

2) %sOutcomesAndIssuesTest.php:%d
deprecation message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testFailWithDeprecation
%sOutcomesAndIssuesTest.php:%d

3) %sOutcomesAndIssuesTest.php:%d
deprecation message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testErrorWithDeprecation
%sOutcomesAndIssuesTest.php:%d

4) %sOutcomesAndIssuesTest.php:%d
deprecation message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testIncompleteWithDeprecation
%sOutcomesAndIssuesTest.php:%d

5) %sOutcomesAndIssuesTest.php:%d
deprecation message

Triggered by:

* PHPUnit\TestFixture\OutcomesAndIssuesTest::testSkippedWithDeprecation
%sOutcomesAndIssuesTest.php:%d

ERRORS!
Tests: 17, Assertions: 7, Errors: 3, Failures: 3, Warnings: 5, Deprecations: 5, Notices: 5, Skipped: 3, Incomplete: 3, Risky: 1.
5 changes: 0 additions & 5 deletions tests/end-to-end/regression/5884.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,5 @@ Foo (PHPUnit\TestFixture\Issue5884\Foo)
1) %sFooTest.php:33
foo

Triggered by:

* PHPUnit\TestFixture\Issue5884\FooTest::testExpectUserDeprecationMessageNOTIgnoringDeprecations
%sFooTest.php:29

OK, but there were issues!
Tests: 6, Assertions: 7, Deprecations: 1.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,5 @@ Time: %s, Memory: %s
1) %sDeprecationInTestCodeTest.php:20
message

Triggered by:

* PHPUnit\TestFixture\SelfDirectIndirect\DeprecationInTestCodeTest::testOne
%sDeprecationInTestCodeTest.php:18

OK, but there were issues!
Tests: 1, Assertions: 1, Deprecations: 1.
15 changes: 0 additions & 15 deletions tests/end-to-end/testdox/outcome-and-issues-with-summary.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,19 @@ This test did not perform any assertions
1) %sOutcomeAndIssuesTest.php:48
message

Triggered by:

* PHPUnit\TestFixture\TestDox\OutcomeAndIssuesTest::testSuccessButWarning
%sOutcomeAndIssuesTest.php:44

--

1 test triggered 1 notice:

1) %sOutcomeAndIssuesTest.php:41
message

Triggered by:

* PHPUnit\TestFixture\TestDox\OutcomeAndIssuesTest::testSuccessButNotice
%sOutcomeAndIssuesTest.php:37

--

1 test triggered 1 deprecation:

1) %sOutcomeAndIssuesTest.php:34
message

Triggered by:

* PHPUnit\TestFixture\TestDox\OutcomeAndIssuesTest::testSuccessButDeprecation
%sOutcomeAndIssuesTest.php:30

ERRORS!
Tests: 9, Assertions: 5, Errors: 1, Failures: 1, Warnings: 1, Deprecations: 1, Notices: 1, Skipped: 1, Incomplete: 1, Risky: 1.
15 changes: 0 additions & 15 deletions tests/end-to-end/testdox/outcome-and-issues-without-summary.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,19 @@ This test did not perform any assertions
1) %sOutcomeAndIssuesTest.php:48
message

Triggered by:

* PHPUnit\TestFixture\TestDox\OutcomeAndIssuesTest::testSuccessButWarning
%sOutcomeAndIssuesTest.php:44

--

1 test triggered 1 notice:

1) %sOutcomeAndIssuesTest.php:41
message

Triggered by:

* PHPUnit\TestFixture\TestDox\OutcomeAndIssuesTest::testSuccessButNotice
%sOutcomeAndIssuesTest.php:37

--

1 test triggered 1 deprecation:

1) %sOutcomeAndIssuesTest.php:34
message

Triggered by:

* PHPUnit\TestFixture\TestDox\OutcomeAndIssuesTest::testSuccessButDeprecation
%sOutcomeAndIssuesTest.php:30

ERRORS!
Tests: 9, Assertions: 5, Errors: 1, Failures: 1, Warnings: 1, Deprecations: 1, Notices: 1, Skipped: 1, Incomplete: 1, Risky: 1.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,5 @@ Deprecation (PHPUnit\TestFixture\TestDox\Deprecation)
1) %sDeprecationTest.php:20
deprecation

Triggered by:

* PHPUnit\TestFixture\TestDox\DeprecationTest::testDeprecation
%sDeprecationTest.php:18

OK, but there were issues!
Tests: 1, Assertions: 1, Deprecations: 1.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,5 @@ Notice (PHPUnit\TestFixture\TestDox\Notice)
1) %sNoticeTest.php:20
notice

Triggered by:

* PHPUnit\TestFixture\TestDox\NoticeTest::testNotice
%sNoticeTest.php:18

OK, but there were issues!
Tests: 1, Assertions: 1, Notices: 1.
Loading

0 comments on commit f3d9714

Please sign in to comment.