diff --git a/src/Support/MutationGenerator.php b/src/Support/MutationGenerator.php index cebc859..b80a451 100644 --- a/src/Support/MutationGenerator.php +++ b/src/Support/MutationGenerator.php @@ -200,13 +200,7 @@ public function enterNode(Node $node): ?Node $nodeTypes = array_unique($nodeTypes); - $mutatorsToUse = []; - foreach ($nodeTypes as $nodeType) { - foreach (MutatorMap::get()[$nodeType] ?? [] as $mutator) { - $mutatorsToUse[] = $mutator; - } - } - - return array_intersect($mutators, $mutatorsToUse); + // a mutator may be requested explicitly although it is not part of any default set + return array_filter($mutators, fn (string $mutator): bool => array_intersect($mutator::nodesToHandle(), $nodeTypes) !== []); } } diff --git a/tests/Unit/MutationGeneratorTest.php b/tests/Unit/MutationGeneratorTest.php index 79c67ed..87ed9fc 100644 --- a/tests/Unit/MutationGeneratorTest.php +++ b/tests/Unit/MutationGeneratorTest.php @@ -5,6 +5,7 @@ use Pest\Mutate\Mutators\ControlStructures\IfNegated; use Pest\Mutate\Mutators\Equality\GreaterOrEqualToGreater; use Pest\Mutate\Mutators\Equality\SmallerToSmallerOrEqual; +use Pest\Mutate\Mutators\String\NotEmptyStringToEmpty; use Pest\Mutate\Support\MutationGenerator; use Pest\Mutate\Support\PhpParserFactory; use Symfony\Component\Finder\SplFileInfo; @@ -286,3 +287,19 @@ function test() { expect($mutations) ->toBeEmpty(); }); + +it('generates mutations of a mutator requested outside the default sets', function (): void { + $mutations = ($this->generate)(<<<'PHP' + toHaveCount(1) + ->and($mutations[0]->mutator)->toBe(NotEmptyStringToEmpty::class); +});