Skip to content

Commit

Permalink
Properly report nested test suite errors during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
aik099 committed Mar 13, 2024
1 parent 51b0a78 commit f05f051
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tests/aik099/PHPUnit/Integration/EventDispatchingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


use ConsoleHelpers\PHPUnitCompat\Framework\TestResult;
use PHPUnit\Framework\TestFailure;
use tests\aik099\PHPUnit\AbstractTestCase;
use tests\aik099\PHPUnit\Fixture\SetupFixture;

Expand Down Expand Up @@ -58,7 +59,42 @@ public function testSetupEvent()
$suite = SetupFixture::suite('tests\\aik099\\PHPUnit\\Fixture\\SetupFixture');
$suite->run($result);

$this->assertTrue($result->wasSuccessful(), 'All sub-tests passed');
$error_msgs = array();

if ( $result->errorCount() > 0 ) {
foreach ( $result->errors() as $error ) {
$error_msgs[] = $this->prepareErrorMsg($error);
}
}

if ( $result->failureCount() > 0 ) {
foreach ( $result->failures() as $failure ) {
$error_msgs[] = $this->prepareErrorMsg($failure);
}
}

if ( $error_msgs ) {
$this->fail(
'The "SetupFixture" tests failed:' . \PHP_EOL . \PHP_EOL . implode(\PHP_EOL . ' * ', $error_msgs)
);
}

$this->assertTrue(true);
}

/**
* Prepares an error msg.
*
* @param TestFailure $test_failure Exception.
*
* @return string
*/
protected function prepareErrorMsg(TestFailure $test_failure)
{
$ret = $test_failure->toString() . \PHP_EOL;
$ret .= 'Trace:' . \PHP_EOL . $test_failure->thrownException()->getTraceAsString();

return $ret;
}

}

0 comments on commit f05f051

Please sign in to comment.