Skip to content

Commit

Permalink
Closes #5760
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 21, 2024
1 parent 3977933 commit 43cc09c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@
</PossiblyNullArgument>
<RedundantCondition>
<code><![CDATA[assert($test instanceof TestMethod)]]></code>
<code><![CDATA[assert($test instanceof TestMethod)]]></code>
</RedundantCondition>
</file>
<file src="src/Metadata/Api/CodeCoverage.php">
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog-10.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 25 additions & 9 deletions src/Logging/TestDox/TestResult/TestResultCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class TestResultCollector
private array $tests = [];
private ?TestStatus $status = null;
private ?Throwable $throwable = null;
private bool $prepared = false;

/**
* @throws EventFacadeIsSealedException
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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,
);
}
}
2 changes: 0 additions & 2 deletions tests/end-to-end/regression/5760.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5760
--XFAIL--
https://github.com/sebastianbergmann/phpunit/issues/5760
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
Expand Down

0 comments on commit 43cc09c

Please sign in to comment.