Skip to content

Commit 4ee8e31

Browse files
Closes #6583
1 parent ae1cf4f commit 4ee8e31

4 files changed

Lines changed: 67 additions & 1 deletion

File tree

ChangeLog-12.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 12.5 release series are documented in this fi
1010
* [#4975](https://github.com/sebastianbergmann/phpunit/issues/4975): `--filter` does not work when filter string starts with `#`
1111
* [#5354](https://github.com/sebastianbergmann/phpunit/issues/5354): JUnit XML logger does not handle `TestSuiteSkipped` event
1212
* [#6276](https://github.com/sebastianbergmann/phpunit/issues/6276): Exit with non-zero exit code when explicit test selection (`--filter`, `--group`, `--testsuite`) yields no tests
13+
* [#6583](https://github.com/sebastianbergmann/phpunit/issues/6583): Failing output expectation skips `tearDown()` and handler restoration, causing subsequent tests to be marked as risky
1314

1415
## [12.5.17] - 2026-04-08
1516

src/Framework/TestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,10 @@ final public function runBare(): void
599599
$this->stopOutputBuffering()) {
600600
$outputBufferingStopped = true;
601601

602-
$this->performAssertionsOnOutput();
602+
try {
603+
$this->performAssertionsOnOutput();
604+
} catch (ExpectationFailedException $e) {
605+
}
603606
}
604607

605608
try {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
GH-5842: Failing output expectation must not skip tearDown and handler restoration
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/5842/Issue5842Test.php';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
11+
--EXPECTF--
12+
PHPUnit %s by Sebastian Bergmann and contributors.
13+
14+
Runtime: %s
15+
16+
.F. 3 / 3 (100%)
17+
18+
Time: %s, Memory: %s
19+
20+
There was 1 failure:
21+
22+
1) PHPUnit\TestFixture\Issue5842Test::testFailingOutputExpectation
23+
Failed asserting that two strings are identical.
24+
--- Expected
25+
+++ Actual
26+
@@ @@
27+
-'expected output'
28+
+'actual output'
29+
30+
FAILURES!
31+
Tests: 3, Assertions: 3, Failures: 1.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
class Issue5842Test extends TestCase
15+
{
16+
public function testBeforeFailingOutputExpectation(): void
17+
{
18+
$this->assertTrue(true);
19+
}
20+
21+
public function testFailingOutputExpectation(): void
22+
{
23+
print 'actual output';
24+
$this->expectOutputString('expected output');
25+
}
26+
27+
public function testAfterFailingOutputExpectation(): void
28+
{
29+
$this->assertTrue(true);
30+
}
31+
}

0 commit comments

Comments
 (0)