Mutation Testing with Infection
Measure how good your tests really are.
Coverage Lies
100% line coverage feels reassuring, but it only proves your tests executed the code — not that they would catch a bug in it. A test can run a line and assert nothing meaningful. Mutation testing measures the real thing: would your tests fail if the code were subtly broken? Infection is the standard PHP tool for this.
composer require --dev infection/infectionThe Core Idea: Mutants
Infection takes your covered code and introduces tiny faults — mutants. It flips > to >=, + to -, && to ||, removes a return, etc. Then it re-runs your tests against each mutant:
- If a test fails → the mutant is killed (good — your tests caught the fault).
- If all tests pass → the mutant survived (bad — a real bug here would go unnoticed).
All lessons in this course
- The Test-Driven Development Workflow
- Mocking and Stubbing with Mockery
- Integration and Functional Testing
- Mutation Testing with Infection