Skip to content

Commit

Permalink
Do not throw needless fatals when logging non-standard TestCase
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
epdenouden authored and sebastianbergmann committed Dec 6, 2018
1 parent ebcf10b commit 092d742
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Util/Log/JUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ public function startTest(Test $test): void
*/
public function endTest(Test $test, float $time): void
{
$numAssertions = $test->getNumAssertions();
if (\method_exists($test, 'getNumAssertions')) {
$numAssertions = $test->getNumAssertions();
} else {
$numAssertions = 0;
}

$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;

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

if ($test->hasOutput()) {
if (\method_exists($test, 'hasOutput') && \method_exists($test, 'getActualOutput')) {
$testOutput = $test->hasOutput() ? $test->getActualOutput() : '';
} else {
$testOutput = '';
}

if (!empty($testOutput)) {
$systemOut = $this->document->createElement(
'system-out',
Xml::prepareString($test->getActualOutput())
Xml::prepareString($testOutput)
);

$this->currentTestCase->appendChild($systemOut);
Expand Down

0 comments on commit 092d742

Please sign in to comment.