0Pricing
PHP Academy · Lesson

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/infection

The 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

  1. The Test-Driven Development Workflow
  2. Mocking and Stubbing with Mockery
  3. Integration and Functional Testing
  4. Mutation Testing with Infection
← Back to PHP Academy