Skip to content

Latest commit

 

History

History
75 lines (52 loc) · 1.35 KB

File metadata and controls

75 lines (52 loc) · 1.35 KB

PHP Mutation Testing

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.

Installation

Install Infection per project:

composer require --dev infection/infection

Initialize configuration:

vendor/bin/infection --init

Composer script

Add a project script:

{
  "scripts": {
    "mutation": "infection --threads=max"
  }
}

Run it manually:

composer mutation

Infection mutation testing summary in a PHP project

Scope

Start with focused paths before running mutation testing across an entire legacy application:

{
  "source": {
    "directories": [
      "src/Domain"
    ]
  }
}

CI boundary

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.

Interpreting results

Use mutation results to improve meaningful assertions. Avoid chasing 100 percent scores when the cost is brittle or low-value tests.


← Docs index · Project README