diff --git a/src/Logging/TestDox/PlainTextRenderer.php b/src/Logging/TestDox/PlainTextRenderer.php index 45d0c81df0d..82b6d4b238b 100644 --- a/src/Logging/TestDox/PlainTextRenderer.php +++ b/src/Logging/TestDox/PlainTextRenderer.php @@ -9,7 +9,14 @@ */ namespace PHPUnit\Logging\TestDox; +use function array_map; +use function implode; +use function is_int; +use function preg_split; use function sprintf; +use PHPUnit\Event\Code\TestMethod; +use PHPUnit\Event\TestData\NoDataSetFromDataProviderException; +use PHPUnit\Framework\TestStatus\TestStatus; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit @@ -26,12 +33,8 @@ public function render(array $tests): string foreach ($tests as $prettifiedClassName => $_tests) { $buffer .= $prettifiedClassName . "\n"; - foreach ($this->reduce($_tests) as $prettifiedMethodName => $outcome) { - $buffer .= sprintf( - ' [%s] %s' . "\n", - $outcome, - $prettifiedMethodName, - ); + foreach ($_tests as $test) { + $buffer .= $this->renderTestResult($test); } $buffer .= "\n"; @@ -41,28 +44,88 @@ public function render(array $tests): string } /** - * @psalm-return array + * @throws NoDataSetFromDataProviderException */ - private function reduce(TestResultCollection $tests): array + private function renderTestResult(TestResult $testResult): string { - $result = []; + $method = $testResult->test(); - foreach ($tests as $test) { - $prettifiedMethodName = $test->test()->testDox()->prettifiedMethodName(); + $status = $testResult->status(); - if (!isset($result[$prettifiedMethodName])) { - $result[$prettifiedMethodName] = $test->status()->isSuccess() ? 'x' : ' '; + return sprintf( + '%s%s', + $this->renderTestResultHeader($method, $status), + $this->renderTestResultBody($method, $status), + ); + } - continue; - } + /** + * @throws NoDataSetFromDataProviderException + */ + private function renderTestResultHeader(TestMethod $method, TestStatus $status): string + { + $testStatus = $status->isSuccess() ? 'x' : ' '; - if ($test->status()->isSuccess()) { - continue; - } + $prettifiedMethodName = $method->testDox()->prettifiedMethodName(); - $result[$prettifiedMethodName] = ' '; + $testData = $method->testData(); + + if ($testData->hasDataFromDataProvider()) { + $dataSetNameOrInt = $testData->dataFromDataProvider()->dataSetName(); + + $dataSetName = sprintf( + ' with data set %s', + is_int($dataSetNameOrInt) ? '#' . $dataSetNameOrInt : '"' . $dataSetNameOrInt . '"', + ); } - return $result; + return sprintf( + ' [%s] %s%s%s', + $testStatus, + $prettifiedMethodName, + $dataSetName ?? '', + "\n", + ); + } + + private function renderTestResultBody(TestMethod $method, TestStatus $status): string + { + if ($status->isSuccess()) { + return ''; + } + + return sprintf( + "%s\n%s\n%s\n%s\n", + $this->prefixLines($this->prefixFor('start'), ''), + $this->prefixLines($this->prefixFor('message'), $status->message()), + $this->prefixLines($this->prefixFor('default'), sprintf("\n%s:%d", $method->file(), $method->line())), + $this->prefixLines($this->prefixFor('last'), ''), + ); + } + + private function prefixLines(string $prefix, string $message): string + { + return implode( + "\n", + array_map( + static fn (string $line) => ' ' . $prefix . ($line ? ' ' . $line : ''), + preg_split('/\r\n|\r|\n/', $message), + ), + ); + } + + /** + * @psalm-param 'default'|'start'|'message'|'diff'|'trace'|'last' $type + */ + private function prefixFor(string $type): string + { + return match ($type) { + 'default' => '│', + 'start' => '┐', + 'message' => '├', + 'diff' => '┊', + 'trace' => '╵', + 'last' => '┴', + }; } } diff --git a/src/Logging/TestDox/TestMethod/Subscriber/BeforeTestClassMethodErroredSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/BeforeTestClassMethodErroredSubscriber.php new file mode 100644 index 00000000000..9c359f4df32 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/BeforeTestClassMethodErroredSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\BeforeFirstTestMethodErrored; +use PHPUnit\Event\Test\BeforeFirstTestMethodErroredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class BeforeTestClassMethodErroredSubscriber extends Subscriber implements BeforeFirstTestMethodErroredSubscriber +{ + public function notify(BeforeFirstTestMethodErrored $event): void + { + $this->collector()->beforeTestClassMethodErrored($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/ExecutionStartedSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/ExecutionStartedSubscriber.php new file mode 100644 index 00000000000..93c15c282b7 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/ExecutionStartedSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\TestRunner\ExecutionStarted; +use PHPUnit\Event\TestRunner\ExecutionStartedSubscriber as TestRunnerExecutionStartedSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class ExecutionStartedSubscriber extends Subscriber implements TestRunnerExecutionStartedSubscriber +{ + public function notify(ExecutionStarted $event): void + { + $this->collector()->executionStarted($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestRunnerTriggeredDeprecationSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestRunnerTriggeredDeprecationSubscriber.php new file mode 100644 index 00000000000..24c7a775edf --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestRunnerTriggeredDeprecationSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\TestRunner\DeprecationTriggered; +use PHPUnit\Event\TestRunner\DeprecationTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestRunnerTriggeredDeprecationSubscriber extends Subscriber implements DeprecationTriggeredSubscriber +{ + public function notify(DeprecationTriggered $event): void + { + $this->collector()->testRunnerTriggeredDeprecation($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestRunnerTriggeredWarningSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestRunnerTriggeredWarningSubscriber.php new file mode 100644 index 00000000000..3c8172c7dbf --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestRunnerTriggeredWarningSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\TestRunner\WarningTriggered; +use PHPUnit\Event\TestRunner\WarningTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestRunnerTriggeredWarningSubscriber extends Subscriber implements WarningTriggeredSubscriber +{ + public function notify(WarningTriggered $event): void + { + $this->collector()->testRunnerTriggeredWarning($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestSuiteFinishedSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestSuiteFinishedSubscriber.php new file mode 100644 index 00000000000..f703c5bc63f --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestSuiteFinishedSubscriber.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\TestData\NoDataSetFromDataProviderException; +use PHPUnit\Event\TestSuite\Finished; +use PHPUnit\Event\TestSuite\FinishedSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestSuiteFinishedSubscriber extends Subscriber implements FinishedSubscriber +{ + /** + * @throws NoDataSetFromDataProviderException + */ + public function notify(Finished $event): void + { + $this->collector()->testSuiteFinished($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestSuiteSkippedSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestSuiteSkippedSubscriber.php new file mode 100644 index 00000000000..a4846972b4b --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestSuiteSkippedSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\TestSuite\Skipped; +use PHPUnit\Event\TestSuite\SkippedSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestSuiteSkippedSubscriber extends Subscriber implements SkippedSubscriber +{ + public function notify(Skipped $event): void + { + $this->collector()->testSuiteSkipped($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestSuiteStartedSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestSuiteStartedSubscriber.php new file mode 100644 index 00000000000..3e22b86d5c5 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestSuiteStartedSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\TestSuite\Started; +use PHPUnit\Event\TestSuite\StartedSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestSuiteStartedSubscriber extends Subscriber implements StartedSubscriber +{ + public function notify(Started $event): void + { + $this->collector()->testSuiteStarted($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredDeprecationSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredDeprecationSubscriber.php new file mode 100644 index 00000000000..43cde139b71 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredDeprecationSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\DeprecationTriggered; +use PHPUnit\Event\Test\DeprecationTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredDeprecationSubscriber extends Subscriber implements DeprecationTriggeredSubscriber +{ + public function notify(DeprecationTriggered $event): void + { + $this->collector()->testTriggeredDeprecation($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredErrorSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredErrorSubscriber.php new file mode 100644 index 00000000000..a6ba1d634ea --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredErrorSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\ErrorTriggered; +use PHPUnit\Event\Test\ErrorTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredErrorSubscriber extends Subscriber implements ErrorTriggeredSubscriber +{ + public function notify(ErrorTriggered $event): void + { + $this->collector()->testTriggeredError($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredNoticeSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredNoticeSubscriber.php new file mode 100644 index 00000000000..0346b3bc928 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredNoticeSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\NoticeTriggered; +use PHPUnit\Event\Test\NoticeTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredNoticeSubscriber extends Subscriber implements NoticeTriggeredSubscriber +{ + public function notify(NoticeTriggered $event): void + { + $this->collector()->testTriggeredNotice($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpDeprecationSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpDeprecationSubscriber.php new file mode 100644 index 00000000000..6b99e1b65f5 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpDeprecationSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\PhpDeprecationTriggered; +use PHPUnit\Event\Test\PhpDeprecationTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredPhpDeprecationSubscriber extends Subscriber implements PhpDeprecationTriggeredSubscriber +{ + public function notify(PhpDeprecationTriggered $event): void + { + $this->collector()->testTriggeredPhpDeprecation($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpNoticeSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpNoticeSubscriber.php new file mode 100644 index 00000000000..31c19f9d4b6 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpNoticeSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\PhpNoticeTriggered; +use PHPUnit\Event\Test\PhpNoticeTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredPhpNoticeSubscriber extends Subscriber implements PhpNoticeTriggeredSubscriber +{ + public function notify(PhpNoticeTriggered $event): void + { + $this->collector()->testTriggeredPhpNotice($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpWarningSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpWarningSubscriber.php new file mode 100644 index 00000000000..f479bd5f938 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpWarningSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\PhpWarningTriggered; +use PHPUnit\Event\Test\PhpWarningTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredPhpWarningSubscriber extends Subscriber implements PhpWarningTriggeredSubscriber +{ + public function notify(PhpWarningTriggered $event): void + { + $this->collector()->testTriggeredPhpWarning($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpunitDeprecationSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpunitDeprecationSubscriber.php new file mode 100644 index 00000000000..d6615b2c7e5 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpunitDeprecationSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\PhpunitDeprecationTriggered; +use PHPUnit\Event\Test\PhpunitDeprecationTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredPhpunitDeprecationSubscriber extends Subscriber implements PhpunitDeprecationTriggeredSubscriber +{ + public function notify(PhpunitDeprecationTriggered $event): void + { + $this->collector()->testTriggeredPhpunitDeprecation($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpunitErrorSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpunitErrorSubscriber.php new file mode 100644 index 00000000000..85020c54206 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpunitErrorSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\PhpunitErrorTriggered; +use PHPUnit\Event\Test\PhpunitErrorTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredPhpunitErrorSubscriber extends Subscriber implements PhpunitErrorTriggeredSubscriber +{ + public function notify(PhpunitErrorTriggered $event): void + { + $this->collector()->testTriggeredPhpunitError($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpunitWarningSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpunitWarningSubscriber.php new file mode 100644 index 00000000000..28294e8f89a --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredPhpunitWarningSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\PhpunitWarningTriggered; +use PHPUnit\Event\Test\PhpunitWarningTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredPhpunitWarningSubscriber extends Subscriber implements PhpunitWarningTriggeredSubscriber +{ + public function notify(PhpunitWarningTriggered $event): void + { + $this->collector()->testTriggeredPhpunitWarning($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredWarningSubscriber.php b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredWarningSubscriber.php new file mode 100644 index 00000000000..600ceb07264 --- /dev/null +++ b/src/Logging/TestDox/TestMethod/Subscriber/TestTriggeredWarningSubscriber.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Logging\TestDox; + +use PHPUnit\Event\Test\WarningTriggered; +use PHPUnit\Event\Test\WarningTriggeredSubscriber; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestTriggeredWarningSubscriber extends Subscriber implements WarningTriggeredSubscriber +{ + public function notify(WarningTriggered $event): void + { + $this->collector()->testTriggeredWarning($event); + } +} diff --git a/src/Logging/TestDox/TestMethod/TestResultCollector.php b/src/Logging/TestDox/TestMethod/TestResultCollector.php index cba5ef21509..de1dafd83de 100644 --- a/src/Logging/TestDox/TestMethod/TestResultCollector.php +++ b/src/Logging/TestDox/TestMethod/TestResultCollector.php @@ -9,6 +9,7 @@ */ namespace PHPUnit\Logging\TestDox; +use function array_key_exists; use function array_keys; use function array_merge; use function assert; @@ -18,12 +19,16 @@ use function usort; use PHPUnit\Event\Code\TestMethod; use PHPUnit\Event\Code\Throwable; +use PHPUnit\Event\Event; use PHPUnit\Event\EventFacadeIsSealedException; use PHPUnit\Event\Facade; use PHPUnit\Event\InvalidArgumentException; use PHPUnit\Event\Telemetry\HRTime; +use PHPUnit\Event\Test\BeforeFirstTestMethodErrored; use PHPUnit\Event\Test\ConsideredRisky; +use PHPUnit\Event\Test\DeprecationTriggered; use PHPUnit\Event\Test\Errored; +use PHPUnit\Event\Test\ErrorTriggered; use PHPUnit\Event\Test\Failed; use PHPUnit\Event\Test\Finished; use PHPUnit\Event\Test\MarkedIncomplete; @@ -31,12 +36,26 @@ use PHPUnit\Event\Test\MockObjectForAbstractClassCreated; use PHPUnit\Event\Test\MockObjectForTraitCreated; use PHPUnit\Event\Test\MockObjectFromWsdlCreated; +use PHPUnit\Event\Test\NoticeTriggered; use PHPUnit\Event\Test\PartialMockObjectCreated; use PHPUnit\Event\Test\Passed; +use PHPUnit\Event\Test\PhpDeprecationTriggered; +use PHPUnit\Event\Test\PhpNoticeTriggered; +use PHPUnit\Event\Test\PhpunitDeprecationTriggered; +use PHPUnit\Event\Test\PhpunitErrorTriggered; +use PHPUnit\Event\Test\PhpunitWarningTriggered; +use PHPUnit\Event\Test\PhpWarningTriggered; use PHPUnit\Event\Test\Prepared; use PHPUnit\Event\Test\Skipped; use PHPUnit\Event\Test\TestProxyCreated; use PHPUnit\Event\Test\TestStubCreated; +use PHPUnit\Event\Test\WarningTriggered; +use PHPUnit\Event\TestRunner\DeprecationTriggered as TestRunnerDeprecationTriggered; +use PHPUnit\Event\TestRunner\ExecutionStarted as TestRunnerExecutionStarted; +use PHPUnit\Event\TestRunner\WarningTriggered as TestRunnerWarningTriggered; +use PHPUnit\Event\TestSuite\Finished as TestSuiteFinished; +use PHPUnit\Event\TestSuite\Skipped as TestSuiteSkipped; +use PHPUnit\Event\TestSuite\Started as TestSuiteStarted; use PHPUnit\Event\UnknownSubscriberTypeException; use PHPUnit\Framework\TestStatus\TestStatus; use PHPUnit\Logging\TestDox\TestResult as TestDoxTestMethod; @@ -70,6 +89,47 @@ public function __construct(Facade $facade) $this->registerSubscribers($facade); } + public function __invoke(Event $event): void + { + /** @var ?TestStatus $status */ + $status = $this->getStatus($event); + + if (!$status instanceof TestStatus) { + return; + } + + /** + * @var ?HRTime $time + * + * @psalm-suppress UnsupportedPropertyReferenceUsage + */ + $time = &$this->time; + + if (!$time instanceof HRTime) { + $time = $event->telemetryInfo()->time(); + } + + /** + * @var TestStatus $currentStatus + * + * @psalm-suppress UnsupportedPropertyReferenceUsage + */ + $currentStatus = &$this->status; + + if (!$currentStatus instanceof TestStatus) { + + $currentStatus = $status; + + return; + } + + if ($currentStatus->isMoreImportantThan($status)) { + return; + } + + $currentStatus = $status; + } + /** * @psalm-return array */ @@ -140,10 +200,9 @@ public function testPrepared(Prepared $event): void return; } - $this->time = $event->telemetryInfo()->time(); - $this->status = TestStatus::unknown(); $this->throwable = null; $this->testDoubles = []; + $this($event); } public function testErrored(Errored $event): void @@ -152,8 +211,9 @@ public function testErrored(Errored $event): void return; } - $this->status = TestStatus::error($event->throwable()->message()); $this->throwable = $event->throwable(); + + $this($event); } public function testFailed(Failed $event): void @@ -162,8 +222,9 @@ public function testFailed(Failed $event): void return; } - $this->status = TestStatus::failure($event->throwable()->message()); $this->throwable = $event->throwable(); + + $this($event); } public function testPassed(Passed $event): void @@ -172,23 +233,24 @@ public function testPassed(Passed $event): void return; } - $this->status = TestStatus::success(); + $this($event); } public function testSkipped(Skipped $event): void { - $this->status = TestStatus::skipped($event->message()); + $this($event); } public function testMarkedIncomplete(MarkedIncomplete $event): void { - $this->status = TestStatus::incomplete($event->throwable()->message()); $this->throwable = $event->throwable(); + + $this($event); } public function testConsideredRisky(ConsideredRisky $event): void { - $this->status = TestStatus::risky($event->message()); + $this($event); } public function testCreatedTestDouble(MockObjectCreated|MockObjectForAbstractClassCreated|MockObjectForTraitCreated|MockObjectFromWsdlCreated|PartialMockObjectCreated|TestProxyCreated|TestStubCreated $event): void @@ -221,11 +283,13 @@ public function testFinished(Finished $event): void assert($test instanceof TestMethod); - if (!isset($this->tests[$test->testDox()->prettifiedClassName()])) { - $this->tests[$test->testDox()->prettifiedClassName()] = []; + $prettifiedClassName = $test->testDox()->prettifiedClassName(); + + if (!array_key_exists($prettifiedClassName, $this->tests)) { + $this->tests[$prettifiedClassName] = []; } - $this->tests[$test->testDox()->prettifiedClassName()][] = new TestDoxTestMethod( + $this->tests[$prettifiedClassName][] = new TestDoxTestMethod( $test, $event->telemetryInfo()->time()->duration($this->time), $this->status, @@ -239,6 +303,117 @@ public function testFinished(Finished $event): void $this->testDoubles = []; } + public function testTriggeredWarning(WarningTriggered $event): void + { + $this($event); + } + + public function testTriggeredNotice(NoticeTriggered $event): void + { + $this($event); + } + + public function testTriggeredError(ErrorTriggered $event): void + { + $this($event); + } + + public function testTriggeredDeprecation(DeprecationTriggered $event): void + { + $this($event); + } + + public function testRunnerTriggeredDeprecation(TestRunnerDeprecationTriggered $event): void + { + $this($event); + } + + public function executionStarted(TestRunnerExecutionStarted $event): void + { + $this($event); + } + + public function beforeTestClassMethodErrored(BeforeFirstTestMethodErrored $event): void + { + $this($event); + } + + public function testRunnerTriggeredWarning(TestRunnerWarningTriggered $event): void + { + $this($event); + } + + public function testSuiteFinished(TestSuiteFinished $event): void + { + $this($event); + } + + public function testSuiteSkipped(TestSuiteSkipped $event): void + { + $this($event); + } + + public function testSuiteStarted(TestSuiteStarted $event): void + { + $this($event); + } + + public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): void + { + $this($event); + } + + public function testTriggeredPhpNotice(PhpNoticeTriggered $event): void + { + $this($event); + } + + public function testTriggeredPhpWarning(PhpWarningTriggered $event): void + { + $this($event); + } + + public function testTriggeredPhpunitWarning(PhpunitWarningTriggered $event): void + { + $this($event); + } + + public function testTriggeredPhpunitError(PhpunitErrorTriggered $event): void + { + $this($event); + } + + public function testTriggeredPhpunitDeprecation(PhpunitDeprecationTriggered $event): void + { + $this($event); + } + + private function getStatus(Event $event): ?TestStatus + { + /** @var ConsideredRisky|DeprecationTriggered|Errored|ErrorTriggered|Failed|Finished|MarkedIncomplete|NoticeTriggered|Passed|PhpDeprecationTriggered|PhpNoticeTriggered|PhpunitDeprecationTriggered|PhpunitErrorTriggered|PhpunitWarningTriggered|PhpWarningTriggered|Prepared|Skipped|TestRunnerDeprecationTriggered|TestRunnerExecutionStarted|TestSuiteFinished|TestSuiteStarted|WarningTriggered $event */ + return match (true) { + $event instanceof ConsideredRisky => TestStatus::risky($event->message()), + $event instanceof DeprecationTriggered, + $event instanceof PhpDeprecationTriggered, + $event instanceof PhpunitDeprecationTriggered , + $event instanceof TestRunnerDeprecationTriggered => TestStatus::deprecation($event->message()), + $event instanceof Errored => TestStatus::error($event->throwable()->message()), + $event instanceof ErrorTriggered, + $event instanceof PhpunitErrorTriggered => TestStatus::error($event->message()), + $event instanceof Failed => TestStatus::failure($event->throwable()->message()), + $event instanceof MarkedIncomplete => TestStatus::incomplete($event->throwable()->message()), + $event instanceof NoticeTriggered, + $event instanceof PhpNoticeTriggered => TestStatus::notice($event->message()), + $event instanceof Passed => TestStatus::success(), + $event instanceof WarningTriggered, + $event instanceof PhpunitWarningTriggered, + $event instanceof PhpWarningTriggered => TestStatus::warning($event->message()), + $event instanceof Prepared => TestStatus::unknown(), + $event instanceof Skipped => TestStatus::skipped($event->message()), + default => null, + }; + } + /** * @throws EventFacadeIsSealedException * @throws UnknownSubscriberTypeException @@ -246,6 +421,8 @@ public function testFinished(Finished $event): void private function registerSubscribers(Facade $facade): void { $facade->registerSubscribers( + new BeforeTestClassMethodErroredSubscriber($this), + new ExecutionStartedSubscriber($this), new TestConsideredRiskySubscriber($this), new TestCreatedMockObjectForAbstractClassSubscriber($this), new TestCreatedMockObjectForTraitSubscriber($this), @@ -260,7 +437,22 @@ private function registerSubscribers(Facade $facade): void new TestMarkedIncompleteSubscriber($this), new TestPassedSubscriber($this), new TestPreparedSubscriber($this), + new TestRunnerTriggeredDeprecationSubscriber($this), + new TestRunnerTriggeredWarningSubscriber($this), new TestSkippedSubscriber($this), + new TestSuiteFinishedSubscriber($this), + new TestSuiteSkippedSubscriber($this), + new TestSuiteStartedSubscriber($this), + new TestTriggeredDeprecationSubscriber($this), + new TestTriggeredErrorSubscriber($this), + new TestTriggeredNoticeSubscriber($this), + new TestTriggeredPhpDeprecationSubscriber($this), + new TestTriggeredPhpNoticeSubscriber($this), + new TestTriggeredPhpunitDeprecationSubscriber($this), + new TestTriggeredPhpunitErrorSubscriber($this), + new TestTriggeredPhpunitWarningSubscriber($this), + new TestTriggeredPhpWarningSubscriber($this), + new TestTriggeredWarningSubscriber($this), ); } } diff --git a/tests/end-to-end/logging/testdox-print-deprecation.phpt b/tests/end-to-end/logging/testdox-print-deprecation.phpt index 753a390b031..a03199cb1da 100644 --- a/tests/end-to-end/logging/testdox-print-deprecation.phpt +++ b/tests/end-to-end/logging/testdox-print-deprecation.phpt @@ -18,5 +18,10 @@ require realpath($parentDirectory . '/../bootstrap.php'); (new PHPUnit\TextUI\Application)->run($_SERVER['argv']); --EXPECTF-- Deprecation (PHPUnit\TestFixture\TestRunnerStopping\Deprecation) - [x] One + [ ] One + ┐ + ├ message + │ + │ %s:%d + ┴ [x] Two diff --git a/tests/end-to-end/logging/testdox-print-error.phpt b/tests/end-to-end/logging/testdox-print-error.phpt index d70369c5ee4..9b0ca74078e 100644 --- a/tests/end-to-end/logging/testdox-print-error.phpt +++ b/tests/end-to-end/logging/testdox-print-error.phpt @@ -19,4 +19,9 @@ require realpath($parentDirectory . '/../bootstrap.php'); --EXPECTF-- Error (PHPUnit\TestFixture\TestRunnerStopping\Error) [ ] One + ┐ + ├ message + │ + │ %s:%d + ┴ [x] Two diff --git a/tests/end-to-end/logging/testdox-print-failure.phpt b/tests/end-to-end/logging/testdox-print-failure.phpt index 23abef31899..a8f22bc52f8 100644 --- a/tests/end-to-end/logging/testdox-print-failure.phpt +++ b/tests/end-to-end/logging/testdox-print-failure.phpt @@ -18,4 +18,9 @@ require realpath($parentDirectory . '/../bootstrap.php'); --EXPECTF-- Failure (PHPUnit\TestFixture\TestRunnerStopping\Failure) [ ] One + ┐ + ├ Failed asserting that false is true. + │ + │ %s:%d + ┴ [x] Two diff --git a/tests/end-to-end/logging/testdox-print-incomplete.phpt b/tests/end-to-end/logging/testdox-print-incomplete.phpt index e5527ed16cd..9e1a336cff0 100644 --- a/tests/end-to-end/logging/testdox-print-incomplete.phpt +++ b/tests/end-to-end/logging/testdox-print-incomplete.phpt @@ -19,4 +19,9 @@ require realpath($parentDirectory . '/../bootstrap.php'); --EXPECTF-- Incomplete (PHPUnit\TestFixture\TestRunnerStopping\Incomplete) [ ] One + ┐ + ├ message + │ + │ %s:%d + ┴ [x] Two diff --git a/tests/end-to-end/logging/testdox-print-notice.phpt b/tests/end-to-end/logging/testdox-print-notice.phpt index 2127090d854..5756d78d63b 100644 --- a/tests/end-to-end/logging/testdox-print-notice.phpt +++ b/tests/end-to-end/logging/testdox-print-notice.phpt @@ -18,5 +18,10 @@ require realpath($parentDirectory . '/../bootstrap.php'); (new PHPUnit\TextUI\Application)->run($_SERVER['argv']); --EXPECTF-- Notice (PHPUnit\TestFixture\TestRunnerStopping\Notice) - [x] One + [ ] One + ┐ + ├ message + │ + │ %s:%d + ┴ [x] Two diff --git a/tests/end-to-end/logging/testdox-print-risky.phpt b/tests/end-to-end/logging/testdox-print-risky.phpt index e0d3021db2a..32593814afc 100644 --- a/tests/end-to-end/logging/testdox-print-risky.phpt +++ b/tests/end-to-end/logging/testdox-print-risky.phpt @@ -18,4 +18,9 @@ require realpath($parentDirectory . '/../bootstrap.php'); --EXPECTF-- Risky (PHPUnit\TestFixture\TestRunnerStopping\Risky) [ ] One + ┐ + ├ This test did not perform any assertions + │ + │ %s:%d + ┴ [x] Two diff --git a/tests/end-to-end/logging/testdox-print-skipped.phpt b/tests/end-to-end/logging/testdox-print-skipped.phpt index d53074bfe1b..9be2584c599 100644 --- a/tests/end-to-end/logging/testdox-print-skipped.phpt +++ b/tests/end-to-end/logging/testdox-print-skipped.phpt @@ -19,4 +19,9 @@ require realpath($parentDirectory . '/../bootstrap.php'); --EXPECTF-- Skipped (PHPUnit\TestFixture\TestRunnerStopping\Skipped) [ ] One + ┐ + ├ message + │ + │ %s:%d + ┴ [x] Two diff --git a/tests/end-to-end/logging/testdox-print-warning.phpt b/tests/end-to-end/logging/testdox-print-warning.phpt index 2c6db08148b..9eedc9825af 100644 --- a/tests/end-to-end/logging/testdox-print-warning.phpt +++ b/tests/end-to-end/logging/testdox-print-warning.phpt @@ -18,5 +18,10 @@ require realpath($parentDirectory . '/../bootstrap.php'); (new PHPUnit\TextUI\Application)->run($_SERVER['argv']); --EXPECTF-- Warning (PHPUnit\TestFixture\TestRunnerStopping\Warning) - [x] One + [ ] One + ┐ + ├ message + │ + │ %s:%d + ┴ [x] Two diff --git a/tests/end-to-end/logging/testdox-text.phpt b/tests/end-to-end/logging/testdox-text.phpt index 105276ce13c..85ca7f243d3 100644 --- a/tests/end-to-end/logging/testdox-text.phpt +++ b/tests/end-to-end/logging/testdox-text.phpt @@ -22,3 +22,4 @@ unlink($output); Bank Account (PHPUnit\TestFixture\BankAccount) [x] Balance is initially zero [x] Balance cannot become negative + [x] Balance cannot become negative diff --git a/tests/end-to-end/regression/5172.phpt b/tests/end-to-end/regression/5172.phpt index 9ef0b1be364..cb4e5078c58 100644 --- a/tests/end-to-end/regression/5172.phpt +++ b/tests/end-to-end/regression/5172.phpt @@ -20,7 +20,7 @@ Configuration: %s Time: %s, Memory: %s Issue5172 (PHPUnit\TestFixture\Issue5172) - ✔ One + ? One There was 1 PHPUnit test runner deprecation: