Skip to content

Commit 092d742

Browse files
epdenoudensebastianbergmann
authored andcommitted
Do not throw needless fatals when logging non-standard TestCase
Not all project-specific implementations of TestCase implement support for information methods like e.g. getNumAssertions() or hasOutput() Rather than causing a scary fatal in the JUnit logger, we quietly skip these elements in the log.
1 parent ebcf10b commit 092d742

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Util/Log/JUnit.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,12 @@ public function startTest(Test $test): void
313313
*/
314314
public function endTest(Test $test, float $time): void
315315
{
316-
$numAssertions = $test->getNumAssertions();
316+
if (\method_exists($test, 'getNumAssertions')) {
317+
$numAssertions = $test->getNumAssertions();
318+
} else {
319+
$numAssertions = 0;
320+
}
321+
317322
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
318323

319324
$this->currentTestCase->setAttribute(
@@ -333,10 +338,16 @@ public function endTest(Test $test, float $time): void
333338
$this->testSuiteTests[$this->testSuiteLevel]++;
334339
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
335340

336-
if ($test->hasOutput()) {
341+
if (\method_exists($test, 'hasOutput') && \method_exists($test, 'getActualOutput')) {
342+
$testOutput = $test->hasOutput() ? $test->getActualOutput() : '';
343+
} else {
344+
$testOutput = '';
345+
}
346+
347+
if (!empty($testOutput)) {
337348
$systemOut = $this->document->createElement(
338349
'system-out',
339-
Xml::prepareString($test->getActualOutput())
350+
Xml::prepareString($testOutput)
340351
);
341352

342353
$this->currentTestCase->appendChild($systemOut);

0 commit comments

Comments
 (0)