From ca847405c512595a6f39f6ebfdde71ced4ce0492 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 31 Jul 2026 22:28:22 +0200 Subject: [PATCH] [ChangesReporting] Remove junit output format Rector is a refactoring tool, not a testing tool, so reporting its results as a JUnit test suite is a poor fit. The gitlab and github output formats already cover CI reporting. --- .../Output/JUnitOutputFormatter.php | 136 ------------------ .../LazyContainerFactory.php | 2 - 2 files changed, 138 deletions(-) delete mode 100644 src/ChangesReporting/Output/JUnitOutputFormatter.php diff --git a/src/ChangesReporting/Output/JUnitOutputFormatter.php b/src/ChangesReporting/Output/JUnitOutputFormatter.php deleted file mode 100644 index 2fbd7864967..00000000000 --- a/src/ChangesReporting/Output/JUnitOutputFormatter.php +++ /dev/null @@ -1,136 +0,0 @@ -symfonyStyle->warning( - 'The "dom" extension is not loaded. The rector could not generate a response in the JUnit format', - ); - - return; - } - - $domDocument = new DOMDocument('1.0', 'UTF-8'); - - $domElement = $domDocument->createElement(self::XML_ELEMENT_TESTSUITE); - $domElement->setAttribute(self::XML_ATTRIBUTE_NAME, 'rector'); - - $xmlTestSuites = $domDocument->createElement(self::XML_ELEMENT_TESTSUITES); - $xmlTestSuites->appendChild($domElement); - - $domDocument->appendChild($xmlTestSuites); - - $this->appendSystemErrors($processResult, $configuration, $domDocument, $domElement); - $this->appendFileDiffs($processResult, $configuration, $domDocument, $domElement); - - echo $domDocument->saveXML() . PHP_EOL; - } - - private function appendSystemErrors( - ProcessResult $processResult, - Configuration $configuration, - DOMDocument $domDocument, - DOMElement $domElement, - ): void { - if ($processResult->getSystemErrors() === []) { - return; - } - - foreach ($processResult->getSystemErrors() as $systemError) { - $filePath = $configuration->isReportingWithRealPath() - ? ($systemError->getAbsoluteFilePath() ?? '') - : ($systemError->getRelativeFilePath() ?? '') - ; - - $xmlError = $domDocument->createElement(self::XML_ELEMENT_ERROR); - $xmlError->setAttribute(self::XML_ATTRIBUTE_TYPE, 'Error'); - $xmlError->appendChild($domDocument->createTextNode($systemError->getMessage())); - - $xmlTestCase = $domDocument->createElement(self::XML_ELEMENT_TESTCASE); - $xmlTestCase->setAttribute(self::XML_ATTRIBUTE_FILE, $filePath); - $xmlTestCase->setAttribute(self::XML_ATTRIBUTE_NAME, $filePath . ':' . $systemError->getLine()); - $xmlTestCase->appendChild($xmlError); - - $domElement->appendChild($xmlTestCase); - } - } - - private function appendFileDiffs( - ProcessResult $processResult, - Configuration $configuration, - DOMDocument $domDocument, - DOMElement $domElement, - ): void { - if ($processResult->getFileDiffs() === []) { - return; - } - - $fileDiffs = $processResult->getFileDiffs(); - ksort($fileDiffs); - - foreach ($fileDiffs as $fileDiff) { - $filePath = $configuration->isReportingWithRealPath() - ? ($fileDiff->getAbsoluteFilePath() ?? '') - : ($fileDiff->getRelativeFilePath() ?? '') - ; - - $rectorClasses = implode(' / ', $fileDiff->getRectorShortClasses()); - - $xmlError = $domDocument->createElement(self::XML_ELEMENT_ERROR); - $xmlError->setAttribute(self::XML_ATTRIBUTE_TYPE, $rectorClasses); - $xmlError->appendChild($domDocument->createTextNode($fileDiff->getDiff())); - - $xmlTestCase = $domDocument->createElement(self::XML_ELEMENT_TESTCASE); - $xmlTestCase->setAttribute(self::XML_ATTRIBUTE_FILE, $filePath); - $xmlTestCase->setAttribute(self::XML_ATTRIBUTE_NAME, $filePath . ':' . $fileDiff->getFirstLineNumber()); - $xmlTestCase->appendChild($xmlError); - - $domElement->appendChild($xmlTestCase); - } - } -} diff --git a/src/DependencyInjection/LazyContainerFactory.php b/src/DependencyInjection/LazyContainerFactory.php index 70391988268..2c8c0c8760c 100644 --- a/src/DependencyInjection/LazyContainerFactory.php +++ b/src/DependencyInjection/LazyContainerFactory.php @@ -43,7 +43,6 @@ use Rector\ChangesReporting\Output\GitHubOutputFormatter; use Rector\ChangesReporting\Output\GitlabOutputFormatter; use Rector\ChangesReporting\Output\JsonOutputFormatter; -use Rector\ChangesReporting\Output\JUnitOutputFormatter; use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper; use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter\AliasClassNameImportSkipVoter; use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter\ClassLikeNameClassNameImportSkipVoter; @@ -340,7 +339,6 @@ final class LazyContainerFactory ConsoleOutputFormatter::class, JsonOutputFormatter::class, GitlabOutputFormatter::class, - JUnitOutputFormatter::class, GitHubOutputFormatter::class, ];