Skip to content

Commit

Permalink
Improve JUnit error formatter
Browse files Browse the repository at this point in the history
Resolves phpstan/phpstan#6772

If `AnalysisResult` has no errors, mark `<testsuite>` as having 1 test in order to be considered as having passed.
  • Loading branch information
mcaskill authored and ondrejmirtes committed Sep 14, 2022
1 parent 2c8d745 commit 29af264
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Command/ErrorFormatter/JunitErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ public function formatErrors(
Output $output,
): int
{
$totalFailuresCount = $analysisResult->getTotalErrorsCount();
$totalTestsCount = $analysisResult->hasErrors() ? $totalFailuresCount : 1;

$result = '<?xml version="1.0" encoding="UTF-8"?>';
$result .= sprintf(
'<testsuite failures="%d" name="phpstan" tests="%d" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd">',
$analysisResult->getTotalErrorsCount(),
$analysisResult->getTotalErrorsCount(),
$totalFailuresCount,
$totalTestsCount,
);

foreach ($analysisResult->getFileSpecificErrors() as $fileSpecificError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function dataFormatterOutputProvider(): Generator
0,
0,
'<?xml version="1.0" encoding="UTF-8"?>
<testsuite failures="0" name="phpstan" tests="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd">
<testsuite failures="0" name="phpstan" tests="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd">
<testcase name="phpstan"/>
</testsuite>
',
Expand Down

0 comments on commit 29af264

Please sign in to comment.