From dc7281e50005b5e01582a5f857765ecf99a347c6 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 18 Sep 2023 07:55:17 +0200 Subject: [PATCH] Emit Test\Failed (instead of Test\Errored) when an assertion fails in "after test" method --- src/Framework/TestCase.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index e08eed1d634..0e97269902b 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -744,6 +744,14 @@ final public function runBare(): void $this->invokeAfterClassHookMethods($hookMethods, $emitter); } } + } catch (AssertionError|AssertionFailedError $e) { + $this->status = TestStatus::failure($e->getMessage()); + + $emitter->testFailed( + $this->valueObjectForEvents(), + Event\Code\ThrowableBuilder::from($e), + Event\Code\ComparisonFailureBuilder::from($e), + ); } catch (Throwable $exceptionRaisedDuringTearDown) { if (!isset($e)) { $this->status = TestStatus::error($exceptionRaisedDuringTearDown->getMessage());