Skip to content

Commit c959676

Browse files
committed
Updated Rector to commit 4d2efb4713e458c08470c4e02d64d17b91b6bd2d
rectorphp/rector-src@4d2efb4 JUnit output format (#6726)
1 parent fb37268 commit c959676

File tree

5 files changed

+95
-3
lines changed

5 files changed

+95
-3
lines changed

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'b5af1e4b4910d2fd5ea5eea31dbc0ea3fc209f9e';
22+
public const PACKAGE_VERSION = '4d2efb4713e458c08470c4e02d64d17b91b6bd2d';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-02-24 17:51:11';
27+
public const RELEASE_DATE = '2025-02-25 14:03:59';
2828
/**
2929
* @var int
3030
*/
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/**
4+
* JUnit specification:
5+
* - https://github.com/junit-team/junit5/blob/main/platform-tests/src/test/resources/jenkins-junit.xsda
6+
*/
7+
declare (strict_types=1);
8+
namespace Rector\ChangesReporting\Output;
9+
10+
use DOMDocument;
11+
use DOMElement;
12+
use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface;
13+
use Rector\ValueObject\Configuration;
14+
use Rector\ValueObject\ProcessResult;
15+
use RectorPrefix202502\Symfony\Component\Console\Style\SymfonyStyle;
16+
final class JUnitOutputFormatter implements OutputFormatterInterface
17+
{
18+
/**
19+
* @readonly
20+
*/
21+
private SymfonyStyle $symfonyStyle;
22+
public const NAME = 'junit';
23+
private const XML_ATTRIBUTE_FILE = 'file';
24+
private const XML_ATTRIBUTE_NAME = 'name';
25+
private const XML_ATTRIBUTE_TYPE = 'type';
26+
private const XML_ELEMENT_TESTSUITES = 'testsuites';
27+
private const XML_ELEMENT_TESTSUITE = 'testsuite';
28+
private const XML_ELEMENT_TESTCASE = 'testcase';
29+
private const XML_ELEMENT_ERROR = 'error';
30+
public function __construct(SymfonyStyle $symfonyStyle)
31+
{
32+
$this->symfonyStyle = $symfonyStyle;
33+
}
34+
public function getName() : string
35+
{
36+
return self::NAME;
37+
}
38+
public function report(ProcessResult $processResult, Configuration $configuration) : void
39+
{
40+
if (!\extension_loaded('dom')) {
41+
$this->symfonyStyle->warning('The "dom" extension is not loaded. The rector could not generate a response in the JUnit format');
42+
return;
43+
}
44+
$domDocument = new DOMDocument('1.0', 'UTF-8');
45+
$xmlTestSuite = $domDocument->createElement(self::XML_ELEMENT_TESTSUITE);
46+
$xmlTestSuite->setAttribute(self::XML_ATTRIBUTE_NAME, 'rector');
47+
$xmlTestSuites = $domDocument->createElement(self::XML_ELEMENT_TESTSUITES);
48+
$xmlTestSuites->appendChild($xmlTestSuite);
49+
$domDocument->appendChild($xmlTestSuites);
50+
$this->appendSystemErrors($processResult, $configuration, $domDocument, $xmlTestSuite);
51+
$this->appendFileDiffs($processResult, $configuration, $domDocument, $xmlTestSuite);
52+
echo $domDocument->saveXML() . \PHP_EOL;
53+
}
54+
private function appendSystemErrors(ProcessResult $processResult, Configuration $configuration, DOMDocument $domDocument, DOMElement $xmlTestSuite) : void
55+
{
56+
if (\count($processResult->getSystemErrors()) === 0) {
57+
return;
58+
}
59+
foreach ($processResult->getSystemErrors() as $error) {
60+
$filePath = $configuration->isReportingWithRealPath() ? $error->getAbsoluteFilePath() ?? '' : $error->getRelativeFilePath() ?? '';
61+
$xmlError = $domDocument->createElement(self::XML_ELEMENT_ERROR, $error->getMessage());
62+
$xmlError->setAttribute(self::XML_ATTRIBUTE_TYPE, 'Error');
63+
$xmlTestCase = $domDocument->createElement(self::XML_ELEMENT_TESTCASE);
64+
$xmlTestCase->setAttribute(self::XML_ATTRIBUTE_FILE, $filePath);
65+
$xmlTestCase->setAttribute(self::XML_ATTRIBUTE_NAME, $filePath . ':' . $error->getLine());
66+
$xmlTestCase->appendChild($xmlError);
67+
$xmlTestSuite->appendChild($xmlTestCase);
68+
}
69+
}
70+
private function appendFileDiffs(ProcessResult $processResult, Configuration $configuration, DOMDocument $domDocument, DOMElement $xmlTestSuite) : void
71+
{
72+
if (\count($processResult->getFileDiffs()) === 0) {
73+
return;
74+
}
75+
$fileDiffs = $processResult->getFileDiffs();
76+
\ksort($fileDiffs);
77+
foreach ($fileDiffs as $fileDiff) {
78+
$filePath = $configuration->isReportingWithRealPath() ? $fileDiff->getAbsoluteFilePath() ?? '' : $fileDiff->getRelativeFilePath() ?? '';
79+
$rectorClasses = \implode(' / ', $fileDiff->getRectorShortClasses());
80+
$xmlError = $domDocument->createElement(self::XML_ELEMENT_ERROR, $fileDiff->getDiff());
81+
$xmlError->setAttribute(self::XML_ATTRIBUTE_TYPE, $rectorClasses);
82+
$xmlTestCase = $domDocument->createElement(self::XML_ELEMENT_TESTCASE);
83+
$xmlTestCase->setAttribute(self::XML_ATTRIBUTE_FILE, $filePath);
84+
$xmlTestCase->setAttribute(self::XML_ATTRIBUTE_NAME, $filePath . ':' . $fileDiff->getFirstLineNumber());
85+
$xmlTestCase->appendChild($xmlError);
86+
$xmlTestSuite->appendChild($xmlTestCase);
87+
}
88+
}
89+
}

src/DependencyInjection/LazyContainerFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Rector\ChangesReporting\Output\GitHubOutputFormatter;
3939
use Rector\ChangesReporting\Output\GitlabOutputFormatter;
4040
use Rector\ChangesReporting\Output\JsonOutputFormatter;
41+
use Rector\ChangesReporting\Output\JUnitOutputFormatter;
4142
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper;
4243
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter\AliasClassNameImportSkipVoter;
4344
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter\ClassLikeNameClassNameImportSkipVoter;
@@ -222,7 +223,7 @@ final class LazyContainerFactory
222223
/**
223224
* @var array<class-string<OutputFormatterInterface>>
224225
*/
225-
private const OUTPUT_FORMATTER_CLASSES = [ConsoleOutputFormatter::class, JsonOutputFormatter::class, GitlabOutputFormatter::class, GitHubOutputFormatter::class];
226+
private const OUTPUT_FORMATTER_CLASSES = [ConsoleOutputFormatter::class, JsonOutputFormatter::class, GitlabOutputFormatter::class, JUnitOutputFormatter::class, GitHubOutputFormatter::class];
226227
/**
227228
* @var array<class-string<NodeTypeResolverInterface>>
228229
*/

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@
11001100
'Rector\\ChangesReporting\\Output\\ConsoleOutputFormatter' => $baseDir . '/src/ChangesReporting/Output/ConsoleOutputFormatter.php',
11011101
'Rector\\ChangesReporting\\Output\\GitHubOutputFormatter' => $baseDir . '/src/ChangesReporting/Output/GitHubOutputFormatter.php',
11021102
'Rector\\ChangesReporting\\Output\\GitlabOutputFormatter' => $baseDir . '/src/ChangesReporting/Output/GitlabOutputFormatter.php',
1103+
'Rector\\ChangesReporting\\Output\\JUnitOutputFormatter' => $baseDir . '/src/ChangesReporting/Output/JUnitOutputFormatter.php',
11031104
'Rector\\ChangesReporting\\Output\\JsonOutputFormatter' => $baseDir . '/src/ChangesReporting/Output/JsonOutputFormatter.php',
11041105
'Rector\\ChangesReporting\\ValueObjectFactory\\ErrorFactory' => $baseDir . '/src/ChangesReporting/ValueObjectFactory/ErrorFactory.php',
11051106
'Rector\\ChangesReporting\\ValueObjectFactory\\FileDiffFactory' => $baseDir . '/src/ChangesReporting/ValueObjectFactory/FileDiffFactory.php',

vendor/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,7 @@ class ComposerStaticInit57511360b381a600aff109823304b5c7
13191319
'Rector\\ChangesReporting\\Output\\ConsoleOutputFormatter' => __DIR__ . '/../..' . '/src/ChangesReporting/Output/ConsoleOutputFormatter.php',
13201320
'Rector\\ChangesReporting\\Output\\GitHubOutputFormatter' => __DIR__ . '/../..' . '/src/ChangesReporting/Output/GitHubOutputFormatter.php',
13211321
'Rector\\ChangesReporting\\Output\\GitlabOutputFormatter' => __DIR__ . '/../..' . '/src/ChangesReporting/Output/GitlabOutputFormatter.php',
1322+
'Rector\\ChangesReporting\\Output\\JUnitOutputFormatter' => __DIR__ . '/../..' . '/src/ChangesReporting/Output/JUnitOutputFormatter.php',
13221323
'Rector\\ChangesReporting\\Output\\JsonOutputFormatter' => __DIR__ . '/../..' . '/src/ChangesReporting/Output/JsonOutputFormatter.php',
13231324
'Rector\\ChangesReporting\\ValueObjectFactory\\ErrorFactory' => __DIR__ . '/../..' . '/src/ChangesReporting/ValueObjectFactory/ErrorFactory.php',
13241325
'Rector\\ChangesReporting\\ValueObjectFactory\\FileDiffFactory' => __DIR__ . '/../..' . '/src/ChangesReporting/ValueObjectFactory/FileDiffFactory.php',

0 commit comments

Comments
 (0)