From c03cf5396c28f43bdd82d031fe3bc18bfb6668e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne-Ga=C3=ABlle=20Kerros?= Date: Tue, 18 Feb 2025 20:19:26 +0100 Subject: [PATCH 1/8] F#78299 US#190650 T#207172 add the support of multi coverage file for the baseline command + raises an error when the custom coverage can be increased --- src/Command/BaselineCommand.php | 35 +++++++++++++++---- ... => DifferentCustomCoverageInspection.php} | 8 +++-- src/Lib/Metrics/MetricsAnalyzer.php | 4 +-- src/Model/Metric/Failure.php | 1 + src/Renderer/RendererHelper.php | 4 +++ ...DifferentCustomCoverageInspectionTest.php} | 30 +++++++++++----- 6 files changed, 63 insertions(+), 19 deletions(-) rename src/Lib/Metrics/Inspection/{BelowCustomCoverageInspection.php => DifferentCustomCoverageInspection.php} (60%) rename tests/Unit/Lib/Metrics/Inspection/{BelowCustomCoverageInspectionTest.php => DifferentCustomCoverageInspectionTest.php} (64%) diff --git a/src/Command/BaselineCommand.php b/src/Command/BaselineCommand.php index e91b6a7..4ef8b34 100644 --- a/src/Command/BaselineCommand.php +++ b/src/Command/BaselineCommand.php @@ -3,6 +3,7 @@ namespace DigitalRevolution\CodeCoverageInspection\Command; +use DigitalRevolution\CodeCoverageInspection\Lib\Config\ConfigFactory; use DigitalRevolution\CodeCoverageInspection\Lib\IO\DOMDocumentFactory; use DigitalRevolution\CodeCoverageInspection\Lib\IO\MetricsFactory; use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\MetricsAnalyzer; @@ -12,6 +13,7 @@ use RuntimeException; use SplFileInfo; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -21,11 +23,18 @@ */ class BaselineCommand extends Command { + public function __construct(string $name = null) + { + parent::__construct($name); + $this->configFactory = new ConfigFactory(); + $this->schemaPath = dirname(__DIR__, 2) . '/resources/phpfci.xsd'; + } + protected function configure(): void { $this->setName("baseline") ->setDescription("Generate phpfci.xml based on a given coverage.xml") - ->addArgument('coverage', InputOption::VALUE_REQUIRED, 'Path to phpunit\'s coverage.xml') + ->addArgument('coverage', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Path to phpunit\'s coverage.xml') ->addArgument('config', InputOption::VALUE_REQUIRED, 'Path to write the configuration file') ->addOption('threshold', '', InputOption::VALUE_REQUIRED, 'Minimum coverage threshold, defaults to 100', 100) ->addOption('baseDir', '', InputOption::VALUE_REQUIRED, 'Base directory from where to determine the relative config paths'); @@ -41,10 +50,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int $configArgument = reset($configArgument); } - $outputPath = new SplFileInfo((string)$configArgument); - $baseDir = $input->getOption('baseDir') ?? $outputPath->getPath(); - $threshold = $input->getOption('threshold'); - $coverageFilePath = FileUtil::getExistingFile($input->getArgument('coverage')); + $outputPath = new SplFileInfo((string)$configArgument); + $baseDir = $input->getOption('baseDir') ?? $outputPath->getPath(); + $threshold = $input->getOption('threshold'); + $coveragesFilepath = []; + $coverageArgument = $input->getArgument('coverage'); + if (is_array($coverageArgument) === false) { + $output->writeln('Coverage argument should be an array'); + return Command::FAILURE; + } + foreach ($coverageArgument as $coverageFilepath) { + $coveragesFilepath[] = FileUtil::getExistingFile($coverageFilepath); + } if (is_string($baseDir) === false) { $output->writeln("--baseDir argument is not valid. Expecting string argument"); @@ -59,8 +76,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int } // default to 100% coverage - $config = new InspectionConfig($baseDir, (int)$threshold, false); - $metrics = MetricsFactory::getFileMetrics(DOMDocumentFactory::getDOMDocument($coverageFilePath)); + $config = new InspectionConfig($baseDir, (int)$threshold, false); + $domDocuments = []; + foreach ($coveragesFilepath as $coverageFilepath) { + $domDocuments[] = DOMDocumentFactory::getDOMDocument($coverageFilepath); + } + $metrics = MetricsFactory::getFilesMetrics($domDocuments); // analyzer $failures = (new MetricsAnalyzer($metrics, $config))->analyze(); diff --git a/src/Lib/Metrics/Inspection/BelowCustomCoverageInspection.php b/src/Lib/Metrics/Inspection/DifferentCustomCoverageInspection.php similarity index 60% rename from src/Lib/Metrics/Inspection/BelowCustomCoverageInspection.php rename to src/Lib/Metrics/Inspection/DifferentCustomCoverageInspection.php index ecc5a6d..dfbab8c 100644 --- a/src/Lib/Metrics/Inspection/BelowCustomCoverageInspection.php +++ b/src/Lib/Metrics/Inspection/DifferentCustomCoverageInspection.php @@ -10,14 +10,18 @@ /** * File coverage is below custom coverage */ -class BelowCustomCoverageInspection extends AbstractInspection +class DifferentCustomCoverageInspection extends AbstractInspection { public function inspect(?PathInspectionConfig $fileConfig, FileMetric $metric): ?Failure { - if ($fileConfig !== null && $metric->getCoverage() < $fileConfig->getMinimumCoverage()) { + if ($fileConfig !== null && (int)floor($metric->getCoverage()) < $fileConfig->getMinimumCoverage()) { return new Failure($metric, $fileConfig->getMinimumCoverage(), Failure::CUSTOM_COVERAGE_TOO_LOW); } + if ($fileConfig !== null && (int)floor($metric->getCoverage()) > $fileConfig->getMinimumCoverage()) { + return new Failure($metric, $fileConfig->getMinimumCoverage(), Failure::CUSTOM_COVERAGE_TOO_HIGH); + } + return null; } } diff --git a/src/Lib/Metrics/MetricsAnalyzer.php b/src/Lib/Metrics/MetricsAnalyzer.php index 9c66c84..ff1f43c 100644 --- a/src/Lib/Metrics/MetricsAnalyzer.php +++ b/src/Lib/Metrics/MetricsAnalyzer.php @@ -4,7 +4,7 @@ namespace DigitalRevolution\CodeCoverageInspection\Lib\Metrics; use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\Inspection\AbstractInspection; -use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\Inspection\BelowCustomCoverageInspection; +use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\Inspection\DifferentCustomCoverageInspection; use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\Inspection\BelowGlobalCoverageInspection; use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\Inspection\CustomCoverageAboveGlobalInspection; use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\Inspection\UncoveredMethodsInspection; @@ -31,7 +31,7 @@ public function __construct(array $metrics, InspectionConfig $config) $this->config = $config; $this->inspections = [ - new BelowCustomCoverageInspection($config), + new DifferentCustomCoverageInspection($config), new BelowGlobalCoverageInspection($config), new UncoveredMethodsInspection($config), new CustomCoverageAboveGlobalInspection($config) diff --git a/src/Model/Metric/Failure.php b/src/Model/Metric/Failure.php index d4c8dfd..330a780 100644 --- a/src/Model/Metric/Failure.php +++ b/src/Model/Metric/Failure.php @@ -9,6 +9,7 @@ class Failure public const CUSTOM_COVERAGE_TOO_LOW = 2; public const UNNECESSARY_CUSTOM_COVERAGE = 3; public const MISSING_METHOD_COVERAGE = 4; + public const CUSTOM_COVERAGE_TOO_HIGH = 5; private FileMetric $metric; private int $minimumCoverage; diff --git a/src/Renderer/RendererHelper.php b/src/Renderer/RendererHelper.php index ab98795..0730ce3 100644 --- a/src/Renderer/RendererHelper.php +++ b/src/Renderer/RendererHelper.php @@ -19,6 +19,10 @@ public static function renderReason(InspectionConfig $config, Failure $failure): case Failure::CUSTOM_COVERAGE_TOO_LOW: $message = "Custom file coverage is configured at %s%%. Current coverage is at %s%%. Improve coverage for this class."; + return sprintf($message, (string)$failure->getMinimumCoverage(), (string)$failure->getMetric()->getCoverage()); + case Failure::CUSTOM_COVERAGE_TOO_HIGH: + $message = "Custom file coverage is configured at %s%%. Current coverage is at %s%%. Edit the phpfci baseline for this class."; + return sprintf($message, (string)$failure->getMinimumCoverage(), (string)$failure->getMetric()->getCoverage()); case Failure::MISSING_METHOD_COVERAGE: $message = "File coverage is above %s%%, but method(s) `%s` has/have no coverage at all."; diff --git a/tests/Unit/Lib/Metrics/Inspection/BelowCustomCoverageInspectionTest.php b/tests/Unit/Lib/Metrics/Inspection/DifferentCustomCoverageInspectionTest.php similarity index 64% rename from tests/Unit/Lib/Metrics/Inspection/BelowCustomCoverageInspectionTest.php rename to tests/Unit/Lib/Metrics/Inspection/DifferentCustomCoverageInspectionTest.php index b8a9636..71fe2db 100644 --- a/tests/Unit/Lib/Metrics/Inspection/BelowCustomCoverageInspectionTest.php +++ b/tests/Unit/Lib/Metrics/Inspection/DifferentCustomCoverageInspectionTest.php @@ -4,7 +4,7 @@ namespace DigitalRevolution\CodeCoverageInspection\Tests\Unit\Lib\Metrics\Inspection; use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\Inspection\AbstractInspection; -use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\Inspection\BelowCustomCoverageInspection; +use DigitalRevolution\CodeCoverageInspection\Lib\Metrics\Inspection\DifferentCustomCoverageInspection; use DigitalRevolution\CodeCoverageInspection\Model\Config\InspectionConfig; use DigitalRevolution\CodeCoverageInspection\Model\Config\PathInspectionConfig; use DigitalRevolution\CodeCoverageInspection\Model\Metric\Failure; @@ -12,16 +12,16 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[CoversClass(BelowCustomCoverageInspection::class)] +#[CoversClass(DifferentCustomCoverageInspection::class)] #[CoversClass(AbstractInspection::class)] -class BelowCustomCoverageInspectionTest extends TestCase +class DifferentCustomCoverageInspectionTest extends TestCase { - private BelowCustomCoverageInspection $inspection; + private DifferentCustomCoverageInspection $inspection; protected function setUp(): void { $config = new InspectionConfig('/tmp/', 80); - $this->inspection = new BelowCustomCoverageInspection($config); + $this->inspection = new DifferentCustomCoverageInspection($config); } public function testInspectNoCustomCoverageShouldPass(): void @@ -43,10 +43,24 @@ public function testInspectCoverageBelowCustomCoverageShouldFail(): void static::assertSame(40, $failure->getMinimumCoverage()); } - public function testInspectCoverageAboveCustomCoverageShouldPass(): void + /** + * Custom coverage 40% + */ + public function testInspectCoverageAboveCustomCoverageShouldFail(): void { - $fileConfig = new PathInspectionConfig(PathInspectionConfig::TYPE_FILE, '/tmp/b', 40); - $metric = new FileMetric('/tmp/a/', 0, 60, [], []); + $fileConfig = new PathInspectionConfig(PathInspectionConfig::TYPE_FILE, '/tmp/b', 20); + $metric = new FileMetric('/tmp/a/', 0, 40, [], []); + + $failure = $this->inspection->inspect($fileConfig, $metric); + static::assertNotNull($failure); + static::assertSame(Failure::CUSTOM_COVERAGE_TOO_HIGH, $failure->getReason()); + static::assertSame(20, $failure->getMinimumCoverage()); + } + + public function testInspectCoverageCustomCoverageShouldPass(): void + { + $fileConfig = new PathInspectionConfig(PathInspectionConfig::TYPE_FILE, '/tmp/b', 50); + $metric = new FileMetric('/tmp/a/', 0, 50.8, [], []); static::assertNull($this->inspection->inspect($fileConfig, $metric)); } From 1d0425893eafc7d844ae6358e56a593c45e2fb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne-Ga=C3=ABlle=20Kerros?= Date: Tue, 18 Feb 2025 20:19:56 +0100 Subject: [PATCH 2/8] F#78299 US#190650 T#207172 add the support of multi coverage file for the baseline command + raises an error when the custom coverage can be increased --- src/Command/BaselineCommand.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Command/BaselineCommand.php b/src/Command/BaselineCommand.php index 4ef8b34..6554df5 100644 --- a/src/Command/BaselineCommand.php +++ b/src/Command/BaselineCommand.php @@ -23,13 +23,6 @@ */ class BaselineCommand extends Command { - public function __construct(string $name = null) - { - parent::__construct($name); - $this->configFactory = new ConfigFactory(); - $this->schemaPath = dirname(__DIR__, 2) . '/resources/phpfci.xsd'; - } - protected function configure(): void { $this->setName("baseline") From ef03086e06576f6aa919bfa5e16ac2c4306524d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne-Ga=C3=ABlle=20Kerros?= Date: Tue, 18 Feb 2025 20:29:21 +0100 Subject: [PATCH 3/8] F#78299 US#190650 T#207172 add the support of multi coverage file for the baseline command + raises an error when the custom coverage can be increased --- .../Inspection/CustomCoverageAboveGlobalInspection.php | 3 +-- tests/Unit/Lib/Metrics/MetricsAnalyzerTest.php | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspection.php b/src/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspection.php index d8e4fb4..b0601e4 100644 --- a/src/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspection.php +++ b/src/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspection.php @@ -23,8 +23,7 @@ public function inspect(?PathInspectionConfig $fileConfig, FileMetric $metric): $globalCoverage = $this->config->getMinimumCoverage(); $customCoverage = $fileConfig->getMinimumCoverage(); - // custom coverage is lower than global coverage, and file is above global coverage - if ($customCoverage <= $globalCoverage && $metric->getCoverage() >= $globalCoverage) { + if ($customCoverage >= $globalCoverage || $metric->getCoverage() >= $globalCoverage) { return new Failure($metric, $fileConfig->getMinimumCoverage(), Failure::UNNECESSARY_CUSTOM_COVERAGE); } diff --git a/tests/Unit/Lib/Metrics/MetricsAnalyzerTest.php b/tests/Unit/Lib/Metrics/MetricsAnalyzerTest.php index a4f473a..4a63c4d 100644 --- a/tests/Unit/Lib/Metrics/MetricsAnalyzerTest.php +++ b/tests/Unit/Lib/Metrics/MetricsAnalyzerTest.php @@ -41,7 +41,7 @@ public function testAnalyzeFileWithCustomCoverageRuleShouldPass(): void { $metrics[] = new FileMetric('/a/b/c/test.php', 0, 45, [], []); $config = new InspectionConfig('/a/', 80, false); - $config->addPathInspection(new PathInspectionConfig(PathInspectionConfig::TYPE_FILE, 'b/c/test.php', 40)); + $config->addPathInspection(new PathInspectionConfig(PathInspectionConfig::TYPE_FILE, 'b/c/test.php', 45)); $analyzer = new MetricsAnalyzer($metrics, $config); $result = $analyzer->analyze(); @@ -66,12 +66,12 @@ public function testAnalyzeFileWithCustomCoverageAboveGlobalCoverageShouldFail() $metric = new FileMetric('/a/b/c/test.php', 0, 90, [], []); $metrics = [$metric]; $config = new InspectionConfig('/a/', 80, false); - $config->addPathInspection(new PathInspectionConfig(PathInspectionConfig::TYPE_FILE, 'b/c/test.php', 50)); + $config->addPathInspection(new PathInspectionConfig(PathInspectionConfig::TYPE_FILE, 'b/c/test.php', 90)); $analyzer = new MetricsAnalyzer($metrics, $config); $result = $analyzer->analyze(); static::assertCount(1, $result); - static::assertEquals([new Failure($metric, 50, Failure::UNNECESSARY_CUSTOM_COVERAGE)], $result); + static::assertEquals([new Failure($metric, 90, Failure::UNNECESSARY_CUSTOM_COVERAGE)], $result); } public function testAnalyzeFileWithUncoveredMethodsShouldFail(): void From c6a515d83ff73b96109eae05e5fbbb0f98c95aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne-Ga=C3=ABlle=20Kerros?= Date: Tue, 18 Feb 2025 20:32:05 +0100 Subject: [PATCH 4/8] F#78299 US#190650 T#207172 add the support of multi coverage file for the baseline command + raises an error when the custom coverage can be increased --- src/Command/BaselineCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Command/BaselineCommand.php b/src/Command/BaselineCommand.php index 6554df5..106b988 100644 --- a/src/Command/BaselineCommand.php +++ b/src/Command/BaselineCommand.php @@ -28,14 +28,14 @@ protected function configure(): void $this->setName("baseline") ->setDescription("Generate phpfci.xml based on a given coverage.xml") ->addArgument('coverage', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Path to phpunit\'s coverage.xml') - ->addArgument('config', InputOption::VALUE_REQUIRED, 'Path to write the configuration file') + ->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to write the configuration file') ->addOption('threshold', '', InputOption::VALUE_REQUIRED, 'Minimum coverage threshold, defaults to 100', 100) ->addOption('baseDir', '', InputOption::VALUE_REQUIRED, 'Base directory from where to determine the relative config paths'); } protected function execute(InputInterface $input, OutputInterface $output): int { - $configArgument = $input->getArgument('config'); + $configArgument = $input->getOption('config'); if (is_array($configArgument)) { if (count($configArgument) === 0) { throw new RuntimeException('Missing config argument'); From 268da1a5840cd5ad611eb2b8bc5a2dd579a7652d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne-Ga=C3=ABlle=20Kerros?= Date: Tue, 18 Feb 2025 20:47:33 +0100 Subject: [PATCH 5/8] F#78299 US#190650 T#207172 add the support of multi coverage file for the baseline command + raises an error when the custom coverage can be increased --- .../Inspection/CustomCoverageAboveGlobalInspection.php | 3 +-- src/Lib/Metrics/MetricsAnalyzer.php | 4 ++-- .../Command/InspectCommand/Data/checkstyle.xml | 5 ++++- .../Functional/Command/InspectCommand/Data/coverage.xml | 6 +++--- .../CustomCoverageAboveGlobalInspectionTest.php | 9 --------- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspection.php b/src/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspection.php index b0601e4..cb4131a 100644 --- a/src/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspection.php +++ b/src/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspection.php @@ -21,9 +21,8 @@ public function inspect(?PathInspectionConfig $fileConfig, FileMetric $metric): } $globalCoverage = $this->config->getMinimumCoverage(); - $customCoverage = $fileConfig->getMinimumCoverage(); - if ($customCoverage >= $globalCoverage || $metric->getCoverage() >= $globalCoverage) { + if ($metric->getCoverage() >= $globalCoverage) { return new Failure($metric, $fileConfig->getMinimumCoverage(), Failure::UNNECESSARY_CUSTOM_COVERAGE); } diff --git a/src/Lib/Metrics/MetricsAnalyzer.php b/src/Lib/Metrics/MetricsAnalyzer.php index ff1f43c..a735564 100644 --- a/src/Lib/Metrics/MetricsAnalyzer.php +++ b/src/Lib/Metrics/MetricsAnalyzer.php @@ -31,10 +31,10 @@ public function __construct(array $metrics, InspectionConfig $config) $this->config = $config; $this->inspections = [ + new CustomCoverageAboveGlobalInspection($config), new DifferentCustomCoverageInspection($config), new BelowGlobalCoverageInspection($config), - new UncoveredMethodsInspection($config), - new CustomCoverageAboveGlobalInspection($config) + new UncoveredMethodsInspection($config) ]; } diff --git a/tests/Functional/Command/InspectCommand/Data/checkstyle.xml b/tests/Functional/Command/InspectCommand/Data/checkstyle.xml index 4f74988..bab77fb 100644 --- a/tests/Functional/Command/InspectCommand/Data/checkstyle.xml +++ b/tests/Functional/Command/InspectCommand/Data/checkstyle.xml @@ -4,7 +4,10 @@ - + + + + diff --git a/tests/Functional/Command/InspectCommand/Data/coverage.xml b/tests/Functional/Command/InspectCommand/Data/coverage.xml index eed1668..1a3678e 100644 --- a/tests/Functional/Command/InspectCommand/Data/coverage.xml +++ b/tests/Functional/Command/InspectCommand/Data/coverage.xml @@ -62,13 +62,13 @@ conditionals="0" coveredconditionals="0" statements="10" - coveredstatements="8" + coveredstatements="6" elements="0" coveredelements="0"/> - + - + diff --git a/tests/Unit/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspectionTest.php b/tests/Unit/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspectionTest.php index 9a42102..bcf1ac8 100644 --- a/tests/Unit/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspectionTest.php +++ b/tests/Unit/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspectionTest.php @@ -47,13 +47,4 @@ public function testInspectCoverageAboveGlobalCoverageShouldFail(): void static::assertSame(Failure::UNNECESSARY_CUSTOM_COVERAGE, $failure->getReason()); static::assertSame(40, $failure->getMinimumCoverage()); } - - public function testInspectCoverageCustomCoverageAboveGlobalCoverageShouldPass(): void - { - // global is 80 - $fileConfig = new PathInspectionConfig(PathInspectionConfig::TYPE_FILE, '/tmp/b', 85); - $metric = new FileMetric('/tmp/b/', 0, 83, [], []); - - static::assertNull($this->inspection->inspect($fileConfig, $metric)); - } } From e21d5d3c0313a072db06ad246beb3a8f31568378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne-Ga=C3=ABlle=20Kerros?= Date: Tue, 18 Feb 2025 20:52:11 +0100 Subject: [PATCH 6/8] F#78299 US#190650 T#207172 add the support of multi coverage file for the baseline command + raises an error when the custom coverage can be increased --- src/Command/BaselineCommand.php | 2 +- .../BaselineCommand/BaselineCommandTest.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Command/BaselineCommand.php b/src/Command/BaselineCommand.php index 106b988..a43331b 100644 --- a/src/Command/BaselineCommand.php +++ b/src/Command/BaselineCommand.php @@ -28,7 +28,7 @@ protected function configure(): void $this->setName("baseline") ->setDescription("Generate phpfci.xml based on a given coverage.xml") ->addArgument('coverage', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Path to phpunit\'s coverage.xml') - ->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to write the configuration file') + ->addOption('config', '', InputOption::VALUE_REQUIRED, 'Path to write the configuration file') ->addOption('threshold', '', InputOption::VALUE_REQUIRED, 'Minimum coverage threshold, defaults to 100', 100) ->addOption('baseDir', '', InputOption::VALUE_REQUIRED, 'Base directory from where to determine the relative config paths'); } diff --git a/tests/Functional/Command/BaselineCommand/BaselineCommandTest.php b/tests/Functional/Command/BaselineCommand/BaselineCommandTest.php index f5f822f..ccb9789 100644 --- a/tests/Functional/Command/BaselineCommand/BaselineCommandTest.php +++ b/tests/Functional/Command/BaselineCommand/BaselineCommandTest.php @@ -20,12 +20,6 @@ class BaselineCommandTest extends TestCase /** @var vfsStreamDirectory */ private $fileSystem; - protected function setUp(): void - { - parent::setUp(); - $this->fileSystem = vfsStream::setup('output'); - } - /** * @throws Exception */ @@ -39,7 +33,7 @@ public function testBaselineCommand(): void // prepare command $command = new BaselineCommand(); - $input = new ArgvInput(['phpfci', '--baseDir', $baseDir, $coveragePath, $output]); + $input = new ArgvInput(['phpfci', $coveragePath, '--baseDir', $baseDir, '--config', $output]); $output = new BufferedOutput(); // run test case @@ -53,4 +47,10 @@ public function testBaselineCommand(): void static::assertSame($expected, $result); } + + protected function setUp(): void + { + parent::setUp(); + $this->fileSystem = vfsStream::setup('output'); + } } From fb1fcb66320667a2b537d54687bad280b324e3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne-Ga=C3=ABlle=20Kerros?= Date: Tue, 18 Feb 2025 20:54:52 +0100 Subject: [PATCH 7/8] F#78299 US#190650 T#207172 add the support of multi coverage file for the baseline command + raises an error when the custom coverage can be increased --- tests/Unit/Renderer/RendererHelperTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Unit/Renderer/RendererHelperTest.php b/tests/Unit/Renderer/RendererHelperTest.php index 39a007e..7f88059 100644 --- a/tests/Unit/Renderer/RendererHelperTest.php +++ b/tests/Unit/Renderer/RendererHelperTest.php @@ -40,6 +40,15 @@ public function testRenderReasonCustomCoverageTooLow(): void static::assertSame('Custom file coverage is configured at 30%. Current coverage is at 70%. Improve coverage for this class.', $message); } + public function testRenderReasonCustomCoverageTooHigh(): void + { + $metric = new FileMetric('foobar', 0, 50, [], []); + $failure = new Failure($metric, 70, Failure::CUSTOM_COVERAGE_TOO_HIGH, 5); + + $message = RendererHelper::renderReason($this->config, $failure); + static::assertSame('Custom file coverage is configured at 70%. Current coverage is at 50%. Edit the phpfci baseline for this class.', $message); + } + public function testRenderReasonMissingMethodCoverage(): void { $metric = new FileMetric('foobar', 0, 70, [new MethodMetric('coveredMethod', 100, 80), new MethodMetric('uncoveredMethod', 105, 0)], []); From a9bd9b193d4e3d311d9cbcf04f57f69724d19706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne-Ga=C3=ABlle=20Kerros?= Date: Tue, 18 Feb 2025 20:56:39 +0100 Subject: [PATCH 8/8] F#78299 US#190650 T#207172 add the support of multi coverage file for the baseline command + raises an error when the custom coverage can be increased --- tests/Unit/Renderer/RendererHelperTest.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/Unit/Renderer/RendererHelperTest.php b/tests/Unit/Renderer/RendererHelperTest.php index 7f88059..f3fad70 100644 --- a/tests/Unit/Renderer/RendererHelperTest.php +++ b/tests/Unit/Renderer/RendererHelperTest.php @@ -17,11 +17,6 @@ class RendererHelperTest extends TestCase { private InspectionConfig $config; - protected function setUp(): void - { - $this->config = new InspectionConfig('base-path', 80); - } - public function testRenderReasonGlobalCoverageTooLow(): void { $metric = new FileMetric('foobar', 0, 80, [], []); @@ -46,7 +41,10 @@ public function testRenderReasonCustomCoverageTooHigh(): void $failure = new Failure($metric, 70, Failure::CUSTOM_COVERAGE_TOO_HIGH, 5); $message = RendererHelper::renderReason($this->config, $failure); - static::assertSame('Custom file coverage is configured at 70%. Current coverage is at 50%. Edit the phpfci baseline for this class.', $message); + static::assertSame( + 'Custom file coverage is configured at 70%. Current coverage is at 50%. Edit the phpfci baseline for this class.', + $message + ); } public function testRenderReasonMissingMethodCoverage(): void @@ -79,4 +77,9 @@ public function testRenderReasonShouldThrowExceptionWhenInvalid(): void $this->expectException(RuntimeException::class); RendererHelper::renderReason($this->config, $failure); } + + protected function setUp(): void + { + $this->config = new InspectionConfig('base-path', 80); + } }