Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mutator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Custom Mutators: Implement MutatorInterface::mutate(mixed $value): iterable<mixed> to yield mutated variants. Mutations should be side-effect-free and deterministic.
  • Composing Workflows: Use MutatorChain to stack mutators — each mutator operates on the original value unless explicitly chained as stateful (though the package favors stateless mutation).
  • Pipeline Integration: Embed mutators into static analysis or testing pipelines: e.g., mutate expressions before running PHPUnit, or mutate node ASTs in your own PHPStan/Rector extensions.
  • Targeted Mutation: Since mutators accept mixed, use type guards (is_string, is_numeric, etc.) to apply domain-specific mutations only to relevant inputs.

Gotchas and Tips

  • Mutator Identity: Mutators must be pure — avoid dependencies on global state or randomness unless intended (e.g., via seeded RNG passed at runtime).
  • Iteration Overhead: Each mutate() call yields an iterable, so use yield from inside mutator implementations to avoid nested arrays or nested generators.
  • No Default Behavior: Unlike full frameworks (e.g., Infection core), this package does not parse code — you must integrate with AST or tokenizer separately and feed parsed values (e.g., AST node values) into mutators.
  • Extensibility: To extend test coverage, write unit tests for your mutator via yield assertions — test edge cases like null, empty arrays, or float precision overflow.
  • Performance: Mutators run sequentially per value — if composing many, benchmark deeply nested structures to ensure acceptable throughput.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport