infection/mutator
Mutation testing tool for PHP: generates code mutations and runs your PHPUnit tests to measure how well they catch bugs. Helps improve test quality and identify weak assertions, with configurable mutators, thresholds, and reporting for CI pipelines.
Start by installing the package via Composer:
composer require infection/mutator
The core abstractions are MutatorInterface (for defining custom mutations) and MutatorChain (for composing multiple mutators). Your first use case is likely to generate test-targeted mutations — for example, to verify your test suite’s ability to catch common code changes.
Look at src/Mutator/ in the repository for built-in mutator implementations (e.g., Arithmetic, Logical, Comparison). These serve as reference examples for defining your own.
MutatorInterface::mutate(mixed $value): iterable<mixed> to yield mutated variants. Mutations should be side-effect-free and deterministic.MutatorChain to stack mutators — each mutator operates on the original value unless explicitly chained as stateful (though the package favors stateless mutation).mixed, use type guards (is_string, is_numeric, etc.) to apply domain-specific mutations only to relevant inputs.mutate() call yields an iterable, so use yield from inside mutator implementations to avoid nested arrays or nested generators.yield assertions — test edge cases like null, empty arrays, or float precision overflow.How can I help you explore Laravel packages today?