diff --git a/ChangeLog-11.5.md b/ChangeLog-11.5.md index 043c25e621..56d934acb2 100644 --- a/ChangeLog-11.5.md +++ b/ChangeLog-11.5.md @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi ### Fixed * [#6103](https://github.com/sebastianbergmann/phpunit/issues/6103): Output from test run in separate process is printed twice +* [#6109](https://github.com/sebastianbergmann/phpunit/issues/6109): Skipping a test in a before-class method crashes JUnit XML logger ## [11.5.3] - 2025-01-13 diff --git a/src/Logging/JUnit/JunitXmlLogger.php b/src/Logging/JUnit/JunitXmlLogger.php index 8ba3a57c6b..5a5884f498 100644 --- a/src/Logging/JUnit/JunitXmlLogger.php +++ b/src/Logging/JUnit/JunitXmlLogger.php @@ -88,6 +88,7 @@ final class JunitXmlLogger private ?HRTime $time = null; private bool $prepared = false; private bool $preparationFailed = false; + private ?string $unexpectedOutput = null; /** * @throws EventFacadeIsSealedException @@ -197,14 +198,7 @@ public function testPrepared(): void public function testPrintedUnexpectedOutput(PrintedUnexpectedOutput $event): void { - assert($this->currentTestCase !== null); - - $systemOut = $this->document->createElement( - 'system-out', - Xml::prepareString($event->output()), - ); - - $this->currentTestCase->appendChild($systemOut); + $this->unexpectedOutput = $event->output(); } /** @@ -277,6 +271,15 @@ private function handleFinish(Info $telemetryInfo, int $numberOfAssertionsPerfor sprintf('%F', $time), ); + if ($this->unexpectedOutput !== null) { + $systemOut = $this->document->createElement( + 'system-out', + Xml::prepareString($this->unexpectedOutput), + ); + + $this->currentTestCase->appendChild($systemOut); + } + $this->testSuites[$this->testSuiteLevel]->appendChild( $this->currentTestCase, ); @@ -284,9 +287,10 @@ private function handleFinish(Info $telemetryInfo, int $numberOfAssertionsPerfor $this->testSuiteTests[$this->testSuiteLevel]++; $this->testSuiteTimes[$this->testSuiteLevel] += $time; - $this->currentTestCase = null; - $this->time = null; - $this->prepared = false; + $this->currentTestCase = null; + $this->time = null; + $this->prepared = false; + $this->unexpectedOutput = null; } /** diff --git a/tests/end-to-end/regression/6109.phpt b/tests/end-to-end/regression/6109.phpt new file mode 100644 index 0000000000..090d73c970 --- /dev/null +++ b/tests/end-to-end/regression/6109.phpt @@ -0,0 +1,23 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit/issues/6109 +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- + + + + + + + + diff --git a/tests/end-to-end/regression/6109/Issue6109Test.php b/tests/end-to-end/regression/6109/Issue6109Test.php new file mode 100644 index 0000000000..131ab6bdb2 --- /dev/null +++ b/tests/end-to-end/regression/6109/Issue6109Test.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture\Issue6109; + +use PHPUnit\Framework\TestCase; + +final class Issue6109Test extends TestCase +{ + protected function setUp(): void + { + print '*'; + + $this->markTestSkipped('message'); + } + + public function testOne(): void + { + $this->assertTrue(true); + } +}