Skip to content

Commit 30c62b6

Browse files
Merge branch '10.5' into 11.5
2 parents 823240e + 15a2f3e commit 30c62b6

File tree

9 files changed

+122
-26
lines changed

9 files changed

+122
-26
lines changed

ChangeLog-11.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 11.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;
@@ -65,7 +66,7 @@ final class Collector
6566
private int $numberOfIssuesIgnoredByBaseline = 0;
6667

6768
/**
68-
* @var list<BeforeFirstTestMethodErrored|Errored>
69+
* @var list<AfterLastTestMethodErrored|BeforeFirstTestMethodErrored|Errored>
6970
*/
7071
private array $testErroredEvents = [];
7172

@@ -168,6 +169,7 @@ public function __construct(Facade $facade, IssueFilter $issueFilter)
168169
new TestPreparedSubscriber($this),
169170
new TestFinishedSubscriber($this),
170171
new BeforeTestClassMethodErroredSubscriber($this),
172+
new AfterTestClassMethodErroredSubscriber($this),
171173
new TestErroredSubscriber($this),
172174
new TestFailedSubscriber($this),
173175
new TestMarkedIncompleteSubscriber($this),
@@ -295,6 +297,11 @@ public function beforeTestClassMethodErrored(BeforeFirstTestMethodErrored $event
295297
$this->numberOfTestsRun++;
296298
}
297299

300+
public function afterTestClassMethodErrored(AfterLastTestMethodErrored $event): void
301+
{
302+
$this->testErroredEvents[] = $event;
303+
}
304+
298305
public function testErrored(Errored $event): void
299306
{
300307
$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 readonly 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: 22 additions & 21 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 @@
3637
private int $numberOfAssertions;
3738

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

@@ -131,25 +132,25 @@
131132
private int $numberOfIssuesIgnoredByBaseline;
132133

133134
/**
134-
* @param list<BeforeFirstTestMethodErrored|Errored> $testErroredEvents
135-
* @param list<Failed> $testFailedEvents
136-
* @param array<string,list<ConsideredRisky>> $testConsideredRiskyEvents
137-
* @param list<TestSuiteSkipped> $testSuiteSkippedEvents
138-
* @param list<TestSkipped> $testSkippedEvents
139-
* @param list<MarkedIncomplete> $testMarkedIncompleteEvents
140-
* @param array<string,list<PhpunitDeprecationTriggered>> $testTriggeredPhpunitDeprecationEvents
141-
* @param array<string,list<PhpunitErrorTriggered>> $testTriggeredPhpunitErrorEvents
142-
* @param array<string,list<PhpunitWarningTriggered>> $testTriggeredPhpunitWarningEvents
143-
* @param list<TestRunnerDeprecationTriggered> $testRunnerTriggeredDeprecationEvents
144-
* @param list<TestRunnerWarningTriggered> $testRunnerTriggeredWarningEvents
145-
* @param list<Issue> $errors
146-
* @param list<Issue> $deprecations
147-
* @param list<Issue> $notices
148-
* @param list<Issue> $warnings
149-
* @param list<Issue> $phpDeprecations
150-
* @param list<Issue> $phpNotices
151-
* @param list<Issue> $phpWarnings
152-
* @param non-negative-int $numberOfIssuesIgnoredByBaseline
135+
* @param list<AfterLastTestMethodErrored|BeforeFirstTestMethodErrored|Errored> $testErroredEvents
136+
* @param list<Failed> $testFailedEvents
137+
* @param array<string,list<ConsideredRisky>> $testConsideredRiskyEvents
138+
* @param list<TestSuiteSkipped> $testSuiteSkippedEvents
139+
* @param list<TestSkipped> $testSkippedEvents
140+
* @param list<MarkedIncomplete> $testMarkedIncompleteEvents
141+
* @param array<string,list<PhpunitDeprecationTriggered>> $testTriggeredPhpunitDeprecationEvents
142+
* @param array<string,list<PhpunitErrorTriggered>> $testTriggeredPhpunitErrorEvents
143+
* @param array<string,list<PhpunitWarningTriggered>> $testTriggeredPhpunitWarningEvents
144+
* @param list<TestRunnerDeprecationTriggered> $testRunnerTriggeredDeprecationEvents
145+
* @param list<TestRunnerWarningTriggered> $testRunnerTriggeredWarningEvents
146+
* @param list<Issue> $errors
147+
* @param list<Issue> $deprecations
148+
* @param list<Issue> $notices
149+
* @param list<Issue> $warnings
150+
* @param list<Issue> $phpDeprecations
151+
* @param list<Issue> $phpNotices
152+
* @param list<Issue> $phpWarnings
153+
* @param non-negative-int $numberOfIssuesIgnoredByBaseline
153154
*/
154155
public function __construct(int $numberOfTests, int $numberOfTestsRun, int $numberOfAssertions, array $testErroredEvents, array $testFailedEvents, array $testConsideredRiskyEvents, array $testSuiteSkippedEvents, array $testSkippedEvents, array $testMarkedIncompleteEvents, array $testTriggeredPhpunitDeprecationEvents, array $testTriggeredPhpunitErrorEvents, array $testTriggeredPhpunitWarningEvents, array $testRunnerTriggeredDeprecationEvents, array $testRunnerTriggeredWarningEvents, array $errors, array $deprecations, array $notices, array $warnings, array $phpDeprecations, array $phpNotices, array $phpWarnings, int $numberOfIssuesIgnoredByBaseline)
155156
{
@@ -188,7 +189,7 @@ public function numberOfAssertions(): int
188189
}
189190

190191
/**
191-
* @return list<BeforeFirstTestMethodErrored|Errored>
192+
* @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
@@ -30,4 +30,4 @@ After Last Test Method Finished:
3030
Test Suite Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest, 1 test)
3131
Test Runner Execution Finished
3232
Test Runner Finished
33-
PHPUnit Finished (Shell Exit Code: 0)
33+
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)