Infection is the mutation testing tool to consider for mature PHP projects.
Mutation testing intentionally changes code and checks whether the test suite fails. It is valuable, but slower than normal tests, so keep it manual or in a dedicated CI job.
Install Infection per project:
composer require --dev infection/infectionInitialize configuration:
vendor/bin/infection --initAdd a project script:
{
"scripts": {
"mutation": "infection --threads=max"
}
}Run it manually:
composer mutationStart with focused paths before running mutation testing across an entire legacy application:
{
"source": {
"directories": [
"src/Domain"
]
}
}Do not put mutation testing in the default local test command. Prefer:
- a scheduled CI job;
- a manual CI workflow;
- a release-hardening checklist;
- a focused run for critical domains.
Use mutation results to improve meaningful assertions. Avoid chasing 100 percent scores when the cost is brittle or low-value tests.
