Skip to content

fix: generate mutations of mutators requested outside the default sets - #48

Open
mechgw wants to merge 1 commit into
pestphp:5.xfrom
mechgw:fix/explicit-mutators-outside-default-sets
Open

mechgw wants to merge 1 commit into
pestphp:5.xfrom
mechgw:fix/explicit-mutators-outside-default-sets

Conversation

@mechgw

@mechgw mechgw commented Oct 16, 2026

Copy link
Copy Markdown

What:

  • Bug Fix
  • New Feature

Description:

A mutator that is not part of a default set never creates a mutation, even when it is requested explicitly. For example, pest --mutate --mutator=StringNotEmptyStringToEmpty (or ->mutator(Mutators::STRING_NOT_EMPTY_STRING_TO_EMPTY)) reports 0 Mutations for 0 Files created on code full of non-empty strings.

MutationGenerator::filterMutators() keeps only the requested mutators found in MutatorMap, and MutatorMap is built from the default sets. NotEmptyStringToEmpty is commented out in StringSet, so it is never in the map, and the requested mutator is silently dropped.

The fix. filterMutators() keeps each requested mutator whose nodesToHandle() contains a node type of the file. That is the same check the map performed, but it no longer depends on the default sets. The default sets are unchanged, so nothing changes for users who do not request such a mutator.

After this change MutatorMap is no longer used by the plugin. I left it in place because it is a public class; I am happy to remove it in this PR if you prefer.

Tests. it generates mutations of a mutator requested outside the default sets in tests/Unit/MutationGeneratorTest.php generates one mutation with NotEmptyStringToEmpty; without the fix it generates none.

CI. The workflows ran on a fork with the full matrix and fail-fast: false. COMPOSER_ROOT_VERSION=5.x-dev was set there only because Composer cannot guess the root version of a feature branch. The results were compared, job by job, with the same workflows on unmodified 5.x (d0c8711):

The set of failures is identical in every job:

  • the 3 Tests\Visual\* snapshots fail in the prefer-stable jobs, because current PHPUnit prints a deprecation warning for the cacheResult attribute of phpunit.xml;
  • PHPStan reports 2 errors, both in files this PR does not touch.

Everything else passes.

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 17:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@mechgw

mechgw commented Oct 16, 2026

Copy link
Copy Markdown
Author

For context: this is the first part of a fix for enum case values, which are never mutation-tested. The whole plan is described in pestphp/pest#1978.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants