Skip to content

Commit 15a2f3e

Browse files
Closes #6094
1 parent 75849d2 commit 15a2f3e

File tree

9 files changed

+104
-8
lines changed

9 files changed

+104
-8
lines changed

ChangeLog-10.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
1010

1111
### Fixed
1212

13+
* [#6094](https://github.com/sebastianbergmann/phpunit/issues/6094): Errors in after-last-test methods are not reported
1314
* [#6095](https://github.com/sebastianbergmann/phpunit/issues/6095): Expectation is not counted correctly when a doubled method is called more often than is expected
1415
* [#6098](https://github.com/sebastianbergmann/phpunit/issues/6098): No `system-out` element in JUnit XML logfile
1516

src/Runner/TestResult/Collector.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPUnit\Event\Code\TestMethod;
1717
use PHPUnit\Event\EventFacadeIsSealedException;
1818
use PHPUnit\Event\Facade;
19+
use PHPUnit\Event\Test\AfterLastTestMethodErrored;
1920
use PHPUnit\Event\Test\BeforeFirstTestMethodErrored;
2021
use PHPUnit\Event\Test\ConsideredRisky;
2122
use PHPUnit\Event\Test\DeprecationTriggered;
@@ -66,7 +67,7 @@ final class Collector
6667
private int $numberOfIssuesIgnoredByBaseline = 0;
6768

6869
/**
69-
* @psalm-var list<BeforeFirstTestMethodErrored|Errored>
70+
* @psalm-var list<AfterLastTestMethodErrored|BeforeFirstTestMethodErrored|Errored>
7071
*/
7172
private array $testErroredEvents = [];
7273

@@ -169,6 +170,7 @@ public function __construct(Facade $facade, Source $source)
169170
new TestPreparedSubscriber($this),
170171
new TestFinishedSubscriber($this),
171172
new BeforeTestClassMethodErroredSubscriber($this),
173+
new AfterTestClassMethodErroredSubscriber($this),
172174
new TestErroredSubscriber($this),
173175
new TestFailedSubscriber($this),
174176
new TestMarkedIncompleteSubscriber($this),
@@ -296,6 +298,11 @@ public function beforeTestClassMethodErrored(BeforeFirstTestMethodErrored $event
296298
$this->numberOfTestsRun++;
297299
}
298300

301+
public function afterTestClassMethodErrored(AfterLastTestMethodErrored $event): void
302+
{
303+
$this->testErroredEvents[] = $event;
304+
}
305+
299306
public function testErrored(Errored $event): void
300307
{
301308
$this->testErroredEvents[] = $event;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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\TestRunner\TestResult;
11+
12+
use PHPUnit\Event\Test\AfterLastTestMethodErrored;
13+
use PHPUnit\Event\Test\AfterLastTestMethodErroredSubscriber;
14+
15+
/**
16+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
17+
*
18+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
19+
*/
20+
final class AfterTestClassMethodErroredSubscriber extends Subscriber implements AfterLastTestMethodErroredSubscriber
21+
{
22+
public function notify(AfterLastTestMethodErrored $event): void
23+
{
24+
$this->collector()->afterTestClassMethodErrored($event);
25+
}
26+
}

src/Runner/TestResult/TestResult.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PHPUnit\TestRunner\TestResult;
1111

1212
use function count;
13+
use PHPUnit\Event\Test\AfterLastTestMethodErrored;
1314
use PHPUnit\Event\Test\BeforeFirstTestMethodErrored;
1415
use PHPUnit\Event\Test\ConsideredRisky;
1516
use PHPUnit\Event\Test\Errored;
@@ -36,7 +37,7 @@ final class TestResult
3637
private readonly int $numberOfAssertions;
3738

3839
/**
39-
* @psalm-var list<BeforeFirstTestMethodErrored|Errored>
40+
* @psalm-var list<AfterLastTestMethodErrored|BeforeFirstTestMethodErrored|Errored>
4041
*/
4142
private readonly array $testErroredEvents;
4243

@@ -131,7 +132,7 @@ final class TestResult
131132
private readonly int $numberOfIssuesIgnoredByBaseline;
132133

133134
/**
134-
* @psalm-param list<BeforeFirstTestMethodErrored|Errored> $testErroredEvents
135+
* @psalm-param list<AfterLastTestMethodErrored|BeforeFirstTestMethodErrored|Errored> $testErroredEvents
135136
* @psalm-param list<Failed> $testFailedEvents
136137
* @psalm-param array<string,list<ConsideredRisky>> $testConsideredRiskyEvents
137138
* @psalm-param list<TestSuiteSkipped> $testSuiteSkippedEvents
@@ -188,7 +189,7 @@ public function numberOfAssertions(): int
188189
}
189190

190191
/**
191-
* @psalm-return list<BeforeFirstTestMethodErrored|Errored>
192+
* @psalm-return list<AfterLastTestMethodErrored|BeforeFirstTestMethodErrored|Errored>
192193
*/
193194
public function testErroredEvents(): array
194195
{

src/TextUI/Output/Default/ResultPrinter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use function trim;
2727
use PHPUnit\Event\Code\Test;
2828
use PHPUnit\Event\Code\TestMethod;
29+
use PHPUnit\Event\Test\AfterLastTestMethodErrored;
2930
use PHPUnit\Event\Test\BeforeFirstTestMethodErrored;
3031
use PHPUnit\Event\Test\ConsideredRisky;
3132
use PHPUnit\Event\Test\DeprecationTriggered;
@@ -239,7 +240,7 @@ private function printTestsWithErrors(TestResult $result): void
239240
$elements = [];
240241

241242
foreach ($result->testErroredEvents() as $event) {
242-
if ($event instanceof BeforeFirstTestMethodErrored) {
243+
if ($event instanceof AfterLastTestMethodErrored || $event instanceof BeforeFirstTestMethodErrored) {
243244
$title = $event->testClassName();
244245
} else {
245246
$title = $this->name($event->test());

tests/end-to-end/event/exception-in-teardown-after-class.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ After Last Test Method Finished:
3131
Test Suite Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest, 1 test)
3232
Test Runner Execution Finished
3333
Test Runner Finished
34-
PHPUnit Finished (Shell Exit Code: 0)
34+
PHPUnit Finished (Shell Exit Code: 2)

tests/end-to-end/logging/teamcity-directory.phpt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Runtime: %s
7070
##teamcity[testSuiteFinished name='CLI Arguments' flowId='%d']
7171
Time: %s, Memory: %s
7272

73-
There were 5 errors:
73+
There were 6 errors:
7474

7575
1) PHPUnit\TestFixture\Basic\SetUpBeforeClassTest
7676
Exception: forcing an Exception in setUpBeforeClass()
@@ -97,6 +97,11 @@ RuntimeException: error with custom message
9797

9898
%s%eStatusTest.php:%d
9999

100+
6) PHPUnit\TestFixture\Basic\TearDownAfterClassTest
101+
Exception: forcing an Exception in tearDownAfterClass()
102+
103+
%s%eTearDownAfterClassTest.php:%d
104+
100105
--
101106

102107
There were 2 failures:
@@ -127,4 +132,4 @@ This test did not perform any assertions
127132
%s%eStatusTest.php:%d
128133

129134
ERRORS!
130-
Tests: 18, Assertions: 6, Errors: 5, Failures: 2, Skipped: 3, Incomplete: 2, Risky: 2.
135+
Tests: 18, Assertions: 6, Errors: 6, Failures: 2, Skipped: 3, Incomplete: 2, Risky: 2.

tests/end-to-end/regression/6094.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6094
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/6094/Issue6094Test.php';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
11+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
12+
--EXPECTF--
13+
PHPUnit %s by Sebastian Bergmann and contributors.
14+
15+
Runtime: %s
16+
17+
. 1 / 1 (100%)
18+
19+
Time: %s, Memory: %s
20+
21+
There was 1 error:
22+
23+
1) PHPUnit\TestFixture\Issue6094\Issue6094Test
24+
Exception: message
25+
26+
%sIssue6094Test.php:19
27+
28+
ERRORS!
29+
Tests: 1, Assertions: 1, Errors: 1.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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\Issue6094;
11+
12+
use Exception;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class Issue6094Test extends TestCase
16+
{
17+
public static function tearDownAfterClass(): void
18+
{
19+
throw new Exception('message');
20+
}
21+
22+
public function testOne(): void
23+
{
24+
$this->assertTrue(true);
25+
}
26+
}

0 commit comments

Comments
 (0)