Skip to content

Commit

Permalink
Adds 'skip_initial_tests' and 'coverage' options support to infection…
Browse files Browse the repository at this point in the history
… task.
  • Loading branch information
jose-ba committed Nov 15, 2024
1 parent 1411718 commit 28b74bb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/tasks/infection.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ grumphp:
mutators: []
ignore_patterns: []
triggered_by: [php]
skip_initial_tests: false
coverage: ~
```
**threads**
Expand Down Expand Up @@ -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.
6 changes: 6 additions & 0 deletions src/Task/Infection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
26 changes: 26 additions & 0 deletions test/Unit/Task/InfectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function provideConfigurableOptions(): iterable
'mutators' => [],
'ignore_patterns' => [],
'triggered_by' => ['php'],
'skip_initial_tests' => false,
'coverage' => null
]
];
}
Expand Down Expand Up @@ -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'
]
];
}
}

0 comments on commit 28b74bb

Please sign in to comment.