diff --git a/src/Framework/TestSuite.php b/src/Framework/TestSuite.php index 7ab4366f61e..d6ff0fec890 100644 --- a/src/Framework/TestSuite.php +++ b/src/Framework/TestSuite.php @@ -756,8 +756,9 @@ public function run(TestResult $result = null): TestResult } } } catch (Throwable $t) { - $error = new SyntheticError($t->getMessage(), 0, $t->getFile(), $t->getLine(), $t->getTrace()); - $test = new \Failure('tearDownAfterClass'); + $message = "Exception in {$this->name}::$afterClassMethod" . \PHP_EOL . $t->getMessage(); + $error = new SyntheticError($message, 0, $t->getFile(), $t->getLine(), $t->getTrace()); + $test = new \Failure($afterClassMethod); $result->startTest($test); $result->addFailure($test, $error, 0); diff --git a/tests/unit/Framework/TestSuiteTest.php b/tests/unit/Framework/TestSuiteTest.php index 71dd1349014..72d0d0afd32 100644 --- a/tests/unit/Framework/TestSuiteTest.php +++ b/tests/unit/Framework/TestSuiteTest.php @@ -228,6 +228,9 @@ public function testCreateTestForConstructorlessTestClass(): void TestSuite::createTest($reflection, 'TestForConstructorlessTestClass'); } + /** + * @testdox Handles exceptions in tearDownAfterClass() + */ public function testTearDownAfterClassInTestSuite(): void { $suite = new TestSuite(\ExceptionInTearDownAfterClassTest::class); @@ -238,6 +241,10 @@ public function testTearDownAfterClassInTestSuite(): void /** @var TestFailure $failure */ $failure = $this->result->failures()[0]; - $this->assertSame('throw Exception in tearDownAfterClass()', $failure->thrownException()->getMessage()); + $this->assertSame( + 'Exception in ExceptionInTearDownAfterClassTest::tearDownAfterClass' . \PHP_EOL . + 'throw Exception in tearDownAfterClass()', + $failure->thrownException()->getMessage() + ); } }