From 43cc09c9dff5d8cb95c005ea9e66e975045ef82b Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 21 Mar 2024 08:07:49 +0100 Subject: [PATCH] Closes #5760 --- .psalm/baseline.xml | 1 + ChangeLog-10.5.md | 4 +++ .../TestResult/TestResultCollector.php | 34 ++++++++++++++----- tests/end-to-end/regression/5760.phpt | 2 -- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.psalm/baseline.xml b/.psalm/baseline.xml index a941c899ce9..4b21f579e73 100644 --- a/.psalm/baseline.xml +++ b/.psalm/baseline.xml @@ -614,6 +614,7 @@ + diff --git a/ChangeLog-10.5.md b/ChangeLog-10.5.md index 5a729287c08..efd08fafd72 100644 --- a/ChangeLog-10.5.md +++ b/ChangeLog-10.5.md @@ -10,6 +10,10 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi * [#5748](https://github.com/sebastianbergmann/phpunit/pull/5748): Improve performance of `NamePrettifier::prettifyTestMethodName()` * [#5750](https://github.com/sebastianbergmann/phpunit/pull/5750): Micro-optimize `NamePrettifier::prettifyTestMethodName()` once again +### Fixed + +* [#5760](https://github.com/sebastianbergmann/phpunit/issues/5760): TestDox printer does not display details about exceptions raised in before-test methods + ## [10.5.13] - 2024-03-12 ### Changed diff --git a/src/Logging/TestDox/TestResult/TestResultCollector.php b/src/Logging/TestDox/TestResult/TestResultCollector.php index 4417854d943..337a971210b 100644 --- a/src/Logging/TestDox/TestResult/TestResultCollector.php +++ b/src/Logging/TestDox/TestResult/TestResultCollector.php @@ -54,6 +54,7 @@ final class TestResultCollector private array $tests = []; private ?TestStatus $status = null; private ?Throwable $throwable = null; + private bool $prepared = false; /** * @throws EventFacadeIsSealedException @@ -136,6 +137,7 @@ public function testPrepared(Prepared $event): void $this->status = TestStatus::unknown(); $this->throwable = null; + $this->prepared = true; } public function testErrored(Errored $event): void @@ -146,6 +148,14 @@ public function testErrored(Errored $event): void $this->status = TestStatus::error($event->throwable()->message()); $this->throwable = $event->throwable(); + + if (!$this->prepared) { + $test = $event->test(); + + assert($test instanceof TestMethod); + + $this->process($test); + } } public function testFailed(Failed $event): void @@ -290,18 +300,11 @@ public function testFinished(Finished $event): void assert($test instanceof TestMethod); - if (!isset($this->tests[$test->testDox()->prettifiedClassName()])) { - $this->tests[$test->testDox()->prettifiedClassName()] = []; - } - - $this->tests[$test->testDox()->prettifiedClassName()][] = new TestDoxTestMethod( - $test, - $this->status, - $this->throwable, - ); + $this->process($test); $this->status = null; $this->throwable = null; + $this->prepared = false; } /** @@ -340,4 +343,17 @@ private function updateTestStatus(TestStatus $status): void $this->status = $status; } + + private function process(TestMethod $test): void + { + if (!isset($this->tests[$test->testDox()->prettifiedClassName()])) { + $this->tests[$test->testDox()->prettifiedClassName()] = []; + } + + $this->tests[$test->testDox()->prettifiedClassName()][] = new TestDoxTestMethod( + $test, + $this->status, + $this->throwable, + ); + } } diff --git a/tests/end-to-end/regression/5760.phpt b/tests/end-to-end/regression/5760.phpt index 351de080ae0..03cf2c61358 100644 --- a/tests/end-to-end/regression/5760.phpt +++ b/tests/end-to-end/regression/5760.phpt @@ -1,7 +1,5 @@ --TEST-- https://github.com/sebastianbergmann/phpunit/issues/5760 ---XFAIL-- -https://github.com/sebastianbergmann/phpunit/issues/5760 --FILE--