diff --git a/build/target-repository/README.md b/build/target-repository/README.md
index d809cd6fca..ee25b39e2c 100644
--- a/build/target-repository/README.md
+++ b/build/target-repository/README.md
@@ -214,7 +214,6 @@ We currently provide formatters for:
- `console`: Human-oriented printing à la PHP CS Fixer.
- `json`: A custom JSON blob for arbitrary tooling.
-- `junit`: JUnit format to be used in different CI environments.
- `checkstyle`: Useful for Github Action Reports.
- `gitlab`: For Gitlab code quality reports or Code Climate tooling.
diff --git a/src/Console/Output/JUnitOutputFormatter.php b/src/Console/Output/JUnitOutputFormatter.php
deleted file mode 100644
index 5dd065ede4..0000000000
--- a/src/Console/Output/JUnitOutputFormatter.php
+++ /dev/null
@@ -1,104 +0,0 @@
-createXmlOutput($errorAndDiffResult, false);
- $this->easyCodingStandardStyle->writeln($xml);
-
- return $this->exitCodeResolver->resolve($errorAndDiffResult, $configuration);
- }
-
- public static function getName(): string
- {
- return 'junit';
- }
-
- public static function hasSupportForProgressBars(): bool
- {
- return false;
- }
-
- /**
- * @api
- */
- public function createXmlOutput(ErrorAndDiffResult $errorAndDiffResult, bool $absoluteFilePath = false): string
- {
- $result = '';
-
- $totalFailuresCount = $errorAndDiffResult->getErrorCount();
- $totalTestsCount = $errorAndDiffResult->getFileDiffsCount();
-
- $result .= sprintf(
- '',
- $totalFailuresCount,
- $totalTestsCount
- );
-
- foreach ($errorAndDiffResult->getErrors() as $codingStandardError) {
- $fileName = $absoluteFilePath ? $codingStandardError->getAbsoluteFilePath() : $codingStandardError->getRelativeFilePath();
- $result .= $this->createTestCase(
- sprintf('%s:%s', $fileName, $codingStandardError->getLine()),
- $codingStandardError->getMessage()
- );
- }
-
- foreach ($errorAndDiffResult->getSystemErrors() as $systemError) {
- if ($systemError instanceof SystemError) {
- $result .= $this->createTestCase($systemError->getFileWithLine(), $systemError->getMessage());
- }
- }
-
- foreach ($errorAndDiffResult->getFileDiffs() as $codingStandardError) {
- $fileName = $absoluteFilePath ? $codingStandardError->getAbsoluteFilePath() : $codingStandardError->getRelativeFilePath();
- $result .= $this->createTestCase($fileName ?? '', $codingStandardError->getDiff());
- }
-
- return $result . '';
- }
-
- /**
- * Format a single test case
- */
- private function createTestCase(string $reference, ?string $message = null): string
- {
- $result = sprintf('', $this->escape($reference));
- if ($message !== null) {
- $result .= sprintf('', 'ERROR', $this->escape($message));
- }
-
- return $result . '';
- }
-
- /**
- * Escapes values for using in XML
- */
- private function escape(string $string): string
- {
- return htmlspecialchars($string, ENT_XML1 | ENT_COMPAT, 'UTF-8');
- }
-}
diff --git a/src/Console/Output/OutputFormatterCollector.php b/src/Console/Output/OutputFormatterCollector.php
index 07f4e443f0..f58c627ee2 100644
--- a/src/Console/Output/OutputFormatterCollector.php
+++ b/src/Console/Output/OutputFormatterCollector.php
@@ -4,11 +4,21 @@
namespace Symplify\EasyCodingStandard\Console\Output;
+use Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyle;
use Symplify\EasyCodingStandard\Contract\Console\Output\OutputFormatterInterface;
use Symplify\EasyCodingStandard\Exception\Configuration\OutputFormatterNotFoundException;
final class OutputFormatterCollector
{
+ /**
+ * Formats dropped as ECS is a fixer, not a static analyzer; each maps to a still-supported fallback.
+ *
+ * @var array
+ */
+ private const array REMOVED_FORMATS = [
+ 'junit' => ConsoleOutputFormatter::NAME,
+ ];
+
/**
* @var array
*/
@@ -18,7 +28,8 @@ final class OutputFormatterCollector
* @param OutputFormatterInterface[] $outputFormatters
*/
public function __construct(
- array $outputFormatters
+ array $outputFormatters,
+ private readonly EasyCodingStandardStyle $easyCodingStandardStyle
) {
foreach ($outputFormatters as $outputFormatter) {
$this->outputFormatters[$outputFormatter->getName()] = $outputFormatter;
@@ -31,6 +42,17 @@ public function getByName(string $name): OutputFormatterInterface
return $this->outputFormatters[$name];
}
+ if (isset(self::REMOVED_FORMATS[$name])) {
+ $fallback = self::REMOVED_FORMATS[$name];
+ $this->easyCodingStandardStyle->warning(sprintf(
+ 'The "%s" output format was removed, as ECS is a fixer, not a static analyzer. Falling back to "%s".',
+ $name,
+ $fallback
+ ));
+
+ return $this->outputFormatters[$fallback];
+ }
+
$outputFormatterKeys = array_keys($this->outputFormatters);
$errorMessage = sprintf(
diff --git a/tests/Console/Output/Fixture/expected_junit_output.xml b/tests/Console/Output/Fixture/expected_junit_output.xml
deleted file mode 100644
index 1503329188..0000000000
--- a/tests/Console/Output/Fixture/expected_junit_output.xml
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/tests/Console/Output/JUnitOutputFormatterTest.php b/tests/Console/Output/JUnitOutputFormatterTest.php
deleted file mode 100644
index 204ea77fa1..0000000000
--- a/tests/Console/Output/JUnitOutputFormatterTest.php
+++ /dev/null
@@ -1,61 +0,0 @@
-jUnitOutputFormatter = $this->make(JUnitOutputFormatter::class);
- $this->colorConsoleDiffFormatter = $this->make(ColorConsoleDiffFormatter::class);
- }
-
- public function test(): void
- {
- $relativeFilePath = StaticRelativeFilePathHelper::resolveFromCwd(__DIR__ . '/Source/RandomFile.php');
-
- $fileDiffs = [];
-
- $diff = 'some diff';
- $fileDiffs[] = new FileDiff(
- $relativeFilePath,
- $diff,
- $this->colorConsoleDiffFormatter->format($diff),
- [LineLengthFixer::class]
- );
-
- $diff = 'some other diff';
- $fileDiffs[] = new FileDiff(
- $relativeFilePath,
- $diff,
- $this->colorConsoleDiffFormatter->format($diff),
- [LineLengthFixer::class]
- );
-
- $errorAndDiffResult = new ErrorAndDiffResult([], $fileDiffs, []);
-
- $jsonContent = $this->jUnitOutputFormatter->createXmlOutput($errorAndDiffResult);
- $this->assertStringMatchesFormatFile(
- __DIR__ . '/Fixture/expected_junit_output.xml',
- $jsonContent . PHP_EOL
- );
- }
-}
diff --git a/tests/Console/Output/OutputFormatterCollectorTest.php b/tests/Console/Output/OutputFormatterCollectorTest.php
index 246163718c..f89f946a49 100644
--- a/tests/Console/Output/OutputFormatterCollectorTest.php
+++ b/tests/Console/Output/OutputFormatterCollectorTest.php
@@ -8,7 +8,6 @@
use Symplify\EasyCodingStandard\Console\Output\ConsoleOutputFormatter;
use Symplify\EasyCodingStandard\Console\Output\GitlabOutputFormatter;
use Symplify\EasyCodingStandard\Console\Output\JsonOutputFormatter;
-use Symplify\EasyCodingStandard\Console\Output\JUnitOutputFormatter;
use Symplify\EasyCodingStandard\Console\Output\OutputFormatterCollector;
use Symplify\EasyCodingStandard\Testing\PHPUnit\AbstractTestCase;
@@ -33,10 +32,6 @@ public function test(): void
JsonOutputFormatter::class,
$this->outputFormatterCollector->getByName(JsonOutputFormatter::getName())
);
- $this->assertInstanceOf(
- JUnitOutputFormatter::class,
- $this->outputFormatterCollector->getByName(JUnitOutputFormatter::getName())
- );
$this->assertInstanceOf(
GitlabOutputFormatter::class,
$this->outputFormatterCollector->getByName(GitlabOutputFormatter::getName())
@@ -46,4 +41,12 @@ public function test(): void
$this->outputFormatterCollector->getByName(CheckstyleOutputFormatter::getName())
);
}
+
+ public function testRemovedJUnitFormatFallsBackToConsole(): void
+ {
+ $this->assertInstanceOf(
+ ConsoleOutputFormatter::class,
+ $this->outputFormatterCollector->getByName('junit')
+ );
+ }
}