Skip to content

Commit 43cc09c

Browse files
Closes #5760
1 parent 3977933 commit 43cc09c

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

.psalm/baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@
614614
</PossiblyNullArgument>
615615
<RedundantCondition>
616616
<code><![CDATA[assert($test instanceof TestMethod)]]></code>
617+
<code><![CDATA[assert($test instanceof TestMethod)]]></code>
617618
</RedundantCondition>
618619
</file>
619620
<file src="src/Metadata/Api/CodeCoverage.php">

ChangeLog-10.5.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
1010
* [#5748](https://github.com/sebastianbergmann/phpunit/pull/5748): Improve performance of `NamePrettifier::prettifyTestMethodName()`
1111
* [#5750](https://github.com/sebastianbergmann/phpunit/pull/5750): Micro-optimize `NamePrettifier::prettifyTestMethodName()` once again
1212

13+
### Fixed
14+
15+
* [#5760](https://github.com/sebastianbergmann/phpunit/issues/5760): TestDox printer does not display details about exceptions raised in before-test methods
16+
1317
## [10.5.13] - 2024-03-12
1418

1519
### Changed

src/Logging/TestDox/TestResult/TestResultCollector.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ final class TestResultCollector
5454
private array $tests = [];
5555
private ?TestStatus $status = null;
5656
private ?Throwable $throwable = null;
57+
private bool $prepared = false;
5758

5859
/**
5960
* @throws EventFacadeIsSealedException
@@ -136,6 +137,7 @@ public function testPrepared(Prepared $event): void
136137

137138
$this->status = TestStatus::unknown();
138139
$this->throwable = null;
140+
$this->prepared = true;
139141
}
140142

141143
public function testErrored(Errored $event): void
@@ -146,6 +148,14 @@ public function testErrored(Errored $event): void
146148

147149
$this->status = TestStatus::error($event->throwable()->message());
148150
$this->throwable = $event->throwable();
151+
152+
if (!$this->prepared) {
153+
$test = $event->test();
154+
155+
assert($test instanceof TestMethod);
156+
157+
$this->process($test);
158+
}
149159
}
150160

151161
public function testFailed(Failed $event): void
@@ -290,18 +300,11 @@ public function testFinished(Finished $event): void
290300

291301
assert($test instanceof TestMethod);
292302

293-
if (!isset($this->tests[$test->testDox()->prettifiedClassName()])) {
294-
$this->tests[$test->testDox()->prettifiedClassName()] = [];
295-
}
296-
297-
$this->tests[$test->testDox()->prettifiedClassName()][] = new TestDoxTestMethod(
298-
$test,
299-
$this->status,
300-
$this->throwable,
301-
);
303+
$this->process($test);
302304

303305
$this->status = null;
304306
$this->throwable = null;
307+
$this->prepared = false;
305308
}
306309

307310
/**
@@ -340,4 +343,17 @@ private function updateTestStatus(TestStatus $status): void
340343

341344
$this->status = $status;
342345
}
346+
347+
private function process(TestMethod $test): void
348+
{
349+
if (!isset($this->tests[$test->testDox()->prettifiedClassName()])) {
350+
$this->tests[$test->testDox()->prettifiedClassName()] = [];
351+
}
352+
353+
$this->tests[$test->testDox()->prettifiedClassName()][] = new TestDoxTestMethod(
354+
$test,
355+
$this->status,
356+
$this->throwable,
357+
);
358+
}
343359
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
https://github.com/sebastianbergmann/phpunit/issues/5760
3-
--XFAIL--
4-
https://github.com/sebastianbergmann/phpunit/issues/5760
53
--FILE--
64
<?php declare(strict_types=1);
75
$_SERVER['argv'][] = '--do-not-cache-result';

0 commit comments

Comments
 (0)