From 28b74bb30b1594464009df9d49f082df3b4e4904 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 15 Nov 2024 07:45:28 +0100 Subject: [PATCH] Adds 'skip_initial_tests' and 'coverage' options support to infection task. --- doc/tasks/infection.md | 15 +++++++++++++++ src/Task/Infection.php | 6 ++++++ test/Unit/Task/InfectionTest.php | 26 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/doc/tasks/infection.md b/doc/tasks/infection.md index f11d9063..d09a89b3 100644 --- a/doc/tasks/infection.md +++ b/doc/tasks/infection.md @@ -28,6 +28,8 @@ grumphp: mutators: [] ignore_patterns: [] triggered_by: [php] + skip_initial_tests: false + coverage: ~ ``` **threads** @@ -112,3 +114,16 @@ With this option you can skip files like tests. Leave this option blank to run a This option will specify which file extensions will trigger the infection task. By default, infection will be triggered by altering a php file. You can overwrite this option to whatever file you want to use! + +**skip_initial_tests** + +*Default: false* + +Skip running the initial tests. If set to `true`, it is necessary to set `coverage` to the +path where `coverage-xml` and `log-junit` is written by `phpunit` task. + +**coverage** + +*Default: ~* + +Path where `coverage-xml` and `log-junit` is written by `phpunit` task. \ No newline at end of file diff --git a/src/Task/Infection.php b/src/Task/Infection.php index 65d83152..47ca3eca 100644 --- a/src/Task/Infection.php +++ b/src/Task/Infection.php @@ -34,6 +34,8 @@ public static function getConfigurableOptions(): ConfigOptionsResolver 'mutators' => [], 'ignore_patterns' => [], 'triggered_by' => ['php'], + 'skip_initial_tests' => false, + 'coverage' => null, ]); $resolver->addAllowedTypes('threads', ['null', 'int']); @@ -47,6 +49,8 @@ public static function getConfigurableOptions(): ConfigOptionsResolver $resolver->addAllowedTypes('mutators', ['array']); $resolver->addAllowedTypes('ignore_patterns', ['array']); $resolver->addAllowedTypes('triggered_by', ['array']); + $resolver->addAllowedTypes('skip_initial_tests', ['bool']); + $resolver->addAllowedTypes('coverage', ['null', 'string']); return ConfigOptionsResolver::fromOptionsResolver($resolver); } @@ -84,6 +88,8 @@ public function run(ContextInterface $context): TaskResultInterface $arguments->addOptionalArgument('--configuration=%s', $config['configuration']); $arguments->addOptionalArgument('--min-msi=%s', $config['min_msi']); $arguments->addOptionalArgument('--min-covered-msi=%s', $config['min_covered_msi']); + $arguments->addOptionalArgument('--coverage=%s', $config['coverage']); + $arguments->addOptionalArgument('--skip-initial-tests', $config['skip_initial_tests']); $arguments->addOptionalCommaSeparatedArgument('--mutators=%s', $config['mutators']); if ($context instanceof GitPreCommitContext) { diff --git a/test/Unit/Task/InfectionTest.php b/test/Unit/Task/InfectionTest.php index ea20b3ee..4f5c0071 100644 --- a/test/Unit/Task/InfectionTest.php +++ b/test/Unit/Task/InfectionTest.php @@ -36,6 +36,8 @@ public function provideConfigurableOptions(): iterable 'mutators' => [], 'ignore_patterns' => [], 'triggered_by' => ['php'], + 'skip_initial_tests' => false, + 'coverage' => null ] ]; } @@ -233,5 +235,29 @@ public function provideExternalTaskRuns(): iterable '--filter=hello.php,hello2.php' ] ]; + yield 'skip-initial-tests' => [ + [ + 'skip_initial_tests' => true, + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'infection', + [ + '--no-interaction', + '--ignore-msi-with-no-mutations', + '--skip-initial-tests' + ] + ]; + yield 'coverage' => [ + [ + 'coverage' => '/path/to/coverage', + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'infection', + [ + '--no-interaction', + '--ignore-msi-with-no-mutations', + '--coverage=/path/to/coverage' + ] + ]; } }