From 850eddb38fcae843a890cd4df2caf6cddbf58e58 Mon Sep 17 00:00:00 2001 From: Sebastian Barbett Date: Thu, 19 Feb 2026 11:38:06 +0100 Subject: [PATCH 1/2] Fix regex to ignore classnames which are prefixed with a class to create mutations for --- src/Support/MutationGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/MutationGenerator.php b/src/Support/MutationGenerator.php index d712121..7fb47a4 100644 --- a/src/Support/MutationGenerator.php +++ b/src/Support/MutationGenerator.php @@ -154,7 +154,7 @@ private function doesNotContainClassToMutate(string $contents, array $classesToM $namespace = preg_quote(implode('\\', $parts)); $classOrNamespace = preg_quote($classOrNamespace); - if (preg_match("/namespace\\s+$namespace/", $contents) === 1 && preg_match("/(?:class|trait)\\s+$class.*/", $contents) === 1) { + if (preg_match("/namespace\\s+$namespace/", $contents) === 1 && preg_match("/(?:class|trait)\\s+$class\b.*/", $contents) === 1) { return false; } From ddd8ccc3f7a136956fd1980cc2786c24ea1aa620 Mon Sep 17 00:00:00 2001 From: Sebastian Barbett Date: Tue, 24 Mar 2026 09:26:08 +0100 Subject: [PATCH 2/2] Adjust unit tests to fixed behavior --- tests/Unit/MutationGeneratorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/MutationGeneratorTest.php b/tests/Unit/MutationGeneratorTest.php index 79c67ed..00163f9 100644 --- a/tests/Unit/MutationGeneratorTest.php +++ b/tests/Unit/MutationGeneratorTest.php @@ -96,7 +96,7 @@ classesToMutate: $classes, [['AgeHelper'], 2], [['SizeHelper'], 0], [[AgeHelper::class], 2], - [['Tests\\Fixtures\\Classes\\AgeHelp'], 2], + [['Tests\\Fixtures\\Classes\\AgeHelp'], 0], [['Invalid\\Namespace\\AgeHelper'], 0], [['Invalid\\Namespace\\AgeHelp'], 0], [['Invalid\\Namespace\\AgeHelper', AgeHelper::class], 2], @@ -118,7 +118,7 @@ classesToMutate: $classes, [[SizeHelper::class], 0], [[SizeHelperTrait::class, SizeHelper::class], 1], [['SizeHelperTrait'], 1], - [['Tests\\Fixtures\\Traits\\SizeHelperTrai'], 1], + [['Tests\\Fixtures\\Traits\\SizeHelperTrai'], 0], [['Invalid\\Namespace\\SizeHelperTrait'], 0], ]);