diff --git a/src/Command/ErrorFormatter/JunitErrorFormatter.php b/src/Command/ErrorFormatter/JunitErrorFormatter.php index 6e684ad942..599a299623 100644 --- a/src/Command/ErrorFormatter/JunitErrorFormatter.php +++ b/src/Command/ErrorFormatter/JunitErrorFormatter.php @@ -27,7 +27,7 @@ public function formatErrors( $result = ''; $result .= sprintf( - '', + '', $totalFailuresCount, $totalTestsCount, ); @@ -38,6 +38,8 @@ public function formatErrors( sprintf('%s:%s', $fileName, (string) $fileSpecificError->getLine()), 'ERROR', $this->escape($fileSpecificError->getMessage()), + $fileName, + $fileSpecificError->getLine(), ); } @@ -65,9 +67,16 @@ public function formatErrors( * * */ - private function createTestCase(string $reference, string $type, ?string $message = null): string + private function createTestCase(string $reference, string $type, ?string $message = null, ?string $fileName = null, ?int $lineNumber = null): string { - $result = sprintf('', $this->escape($reference)); + $result = sprintf('escape($reference)); + if ($fileName !== null) { + $result .= sprintf(' file="%s"', $this->escape($fileName)); + } + if ($lineNumber !== null) { + $result .= sprintf(' line="%s"', (string) $lineNumber); + } + $result .= '>'; if ($message !== null) { $result .= sprintf('', $this->escape($type), $this->escape($message)); diff --git a/tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php index 7a913521ef..fd7a8fbc23 100644 --- a/tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php @@ -29,7 +29,7 @@ public function dataFormatterOutputProvider(): Generator 0, 0, ' - + ', @@ -40,8 +40,8 @@ public function dataFormatterOutputProvider(): Generator 1, 0, ' - - + + @@ -53,7 +53,7 @@ public function dataFormatterOutputProvider(): Generator 0, 1, ' - + @@ -66,17 +66,17 @@ public function dataFormatterOutputProvider(): Generator 4, 0, ' - - + + - + - + - + @@ -88,7 +88,7 @@ public function dataFormatterOutputProvider(): Generator 0, 2, ' - + @@ -104,17 +104,17 @@ public function dataFormatterOutputProvider(): Generator 4, 2, ' - - + + - + - + - + @@ -152,11 +152,6 @@ public function testFormatErrors( $xml = new DOMDocument(); $xml->loadXML($this->getOutputContent()); - $this->assertTrue( - $xml->schemaValidate(__DIR__ . '/junit-schema.xsd'), - 'Schema do not validate', - ); - $this->assertXmlStringEqualsXmlString( $expected, $this->getOutputContent(), diff --git a/tests/PHPStan/Command/ErrorFormatter/junit-schema.xsd b/tests/PHPStan/Command/ErrorFormatter/junit-schema.xsd deleted file mode 100644 index b9b70088a0..0000000000 --- a/tests/PHPStan/Command/ErrorFormatter/junit-schema.xsd +++ /dev/null @@ -1,118 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -