Skip to content

Commit

Permalink
Merge pull request #411 from Fedcomp/issue-352-multiple-error-reports…
Browse files Browse the repository at this point in the history
…-with-system-out

Support multiple TestCase error reports with system out
  • Loading branch information
andreasschroth authored Nov 12, 2019
2 parents 306ce7a + c7f589a commit 44695ab
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 78 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
vendor
composer.lock
/test/fixtures/generated-tests
.phpunit.result.cache
90 changes: 13 additions & 77 deletions src/Logging/JUnit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,42 +91,6 @@ public function __construct(
$this->time = $time;
}

/**
* @param string $type
* @param string $text
*/
public function addFailure(string $type, string $text)
{
$this->addDefect('failures', $type, $text);
}

/**
* @param string $type
* @param string $text
*/
public function addError(string $type, string $text)
{
$this->addDefect('errors', $type, $text);
}

/**
* @param string $type
* @param string $text
*/
public function addWarning(string $type, string $text)
{
$this->addDefect('warnings', $type, $text);
}

/**
* @param string $type
* @param string $text
*/
public function addSkipped(string $type, string $text)
{
$this->addDefect('skipped', $type, $text);
}

/**
* Add a defect type (error or failure).
*
Expand All @@ -142,28 +106,6 @@ protected function addDefect(string $collName, string $type, string $text)
];
}

/**
* Add systemOut result on test (if has failed or have error).
*
* @param mixed $node
*
* @return mixed
*/
public static function addSystemOut(\SimpleXMLElement $node): \SimpleXMLElement
{
$sys = 'system-out';

if (!empty($node->failure)) {
$node->failure = (string) $node->failure . (string) $node->{$sys};
}

if (!empty($node->error)) {
$node->error = (string) $node->error . (string) $node->{$sys};
}

return $node;
}

/**
* Factory method that creates a TestCase object
* from a SimpleXMLElement.
Expand All @@ -183,26 +125,20 @@ public static function caseFromNode(\SimpleXMLElement $node): self
(string) $node['time']
);

$node = self::addSystemOut($node);
$failures = $node->xpath('failure');
$errors = $node->xpath('error');
$warnings = $node->xpath('warning');
$skipped = $node->xpath('skipped');

foreach ($failures as $fail) {
$case->addFailure((string) $fail['type'], (string) $fail);
}

foreach ($errors as $err) {
$case->addError((string) $err['type'], (string) $err);
}

foreach ($warnings as $warning) {
$case->addWarning((string) $warning['type'], (string) $warning);
}
$system_output = $node->{'system-out'};
$defect_groups = [
'failures' => (array) $node->xpath('failure'),
'errors' => (array) $node->xpath('error'),
'warnings' => (array) $node->xpath('warning'),
'skipped' => (array) $node->xpath('skipped'),
];

foreach ($skipped as $skip) {
$case->addSkipped((string) $skip['type'], (string) $skip);
foreach ($defect_groups as $group => $defects) {
foreach ($defects as $defect) {
$message = (string) $defect;
$message .= (string) $system_output;
$case->addDefect($group, (string) $defect['type'], $message);
}
}

return $case;
Expand Down
27 changes: 26 additions & 1 deletion test/Unit/Logging/JUnit/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class ReaderTest extends \ParaTest\Tests\TestBase
public function setUp(): void
{
$this->mixedPath = FIXTURES . DS . 'results' . DS . 'mixed-results.xml';
$single = FIXTURES . DS . 'results' . DS . 'single-wfailure.xml';
$this->mixed = new Reader($this->mixedPath);
$single = FIXTURES . DS . 'results' . DS . 'single-wfailure.xml';
$this->single = new Reader($single);
$empty = FIXTURES . DS . 'results' . DS . 'empty-test-suite.xml';
$this->empty = new Reader($empty);
$multi_errors = FIXTURES . DS . 'results' . DS . 'multiple-errors-with-system-out.xml';
$this->multi_errors = new Reader($multi_errors);
}

public function testInvalidPathThrowsException()
Expand Down Expand Up @@ -260,6 +262,29 @@ public function testSingleGetMessages()
);
}

/**
* https://github.com/paratestphp/paratest/issues/352
*/
public function testGetMultiErrorsMessages()
{
$errors = $this->multi_errors->getErrors();
$this->assertCount(2, $errors);
$this->assertEquals(
"Risky Test\n" .
"/project/vendor/phpunit/phpunit/src/TextUI/Command.php:200\n" .
"/project/vendor/phpunit/phpunit/src/TextUI/Command.php:159\n" .
"Custom error log on result test with multiple errors!",
$errors[0]
);
$this->assertEquals(
"Risky Test\n" .
"/project/vendor/phpunit/phpunit/src/TextUI/Command.php:200\n" .
"/project/vendor/phpunit/phpunit/src/TextUI/Command.php:159\n" .
"Custom error log on result test with multiple errors!",
$errors[1]
);
}

public function testMixedGetFeedback()
{
$totalCases = 7;
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/results/multiple-errors-with-system-out.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<testsuites>
<testsuite name="timeoutTest" file="/project/test/timeoutTest.php" tests="1" assertions="0" errors="2" warnings="0" failures="0" skipped="0" time="1.014721">
<testcase name="testTimeoutNotice" class="timeoutTest" classname="timeoutTest" file="/project/test/timeoutTest.php" line="8" assertions="0" time="1.014721">
<error type="PHPUnit\Framework\RiskyTestError">Risky Test
/project/vendor/phpunit/phpunit/src/TextUI/Command.php:200
/project/vendor/phpunit/phpunit/src/TextUI/Command.php:159
</error>
<error type="PHPUnit\Framework\RiskyTestError">Risky Test
/project/vendor/phpunit/phpunit/src/TextUI/Command.php:200
/project/vendor/phpunit/phpunit/src/TextUI/Command.php:159
</error>
<system-out>Custom error log on result test with multiple errors!</system-out>
</testcase>
</testsuite>
</testsuites>

0 comments on commit 44695ab

Please sign in to comment.