From 393a98bab1f0277fc266940fd3614f0f46f6e14b Mon Sep 17 00:00:00 2001 From: "agent:orchestrator" Date: Wed, 14 Oct 2026 20:14:23 +0200 Subject: [PATCH] fix: generate mutations of mutators requested outside the default sets The mutators applicable to a file were looked up in a map built from the default sets, so a mutator disabled in its set (NotEmptyStringToEmpty) never mutated anything, even when requested with --mutator. Co-Authored-By: Claude Opus 5.5 --- src/Support/MutationGenerator.php | 10 ++-------- tests/Unit/MutationGeneratorTest.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) 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); +});