LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

infection

PHP mutation testing framework

TLDR

Run mutation testing
$ infection
copy
Run with all CPU cores
$ infection --threads=max
copy
Mutate specific files only
$ infection [src/Service/Mailer.php] [src/Entity/]
copy
Fail the build below a minimum score
$ infection --min-msi=[70] --min-covered-msi=[80]
copy
Mutate only lines changed in the current branch
$ infection --git-diff-lines --git-diff-base=[origin/main]
copy
Show all mutation diffs
$ infection --show-mutations=max
copy
Write an HTML report
$ infection --logger-html=[infection.html]
copy
Reuse existing coverage and skip the initial test run
$ infection --coverage=[build/coverage] --skip-initial-tests
copy

SYNOPSIS

infection [options] [paths...]

DESCRIPTION

infection is a PHP mutation testing framework. It makes small changes (mutants) to your source code and runs the test suite against each one.A killed mutant means tests caught the change; an escaped mutant indicates weak tests. Results are summarized as the Mutation Score Indicator (MSI). Configuration lives in infection.json5, created interactively on first run.

PARAMETERS

-j, --threads N|max

Number of parallel test processes; max uses all CPU cores.
--min-msi N
Minimum Mutation Score Indicator required; fail otherwise.
--min-covered-msi N
Minimum MSI for code covered by tests.
-s, --show-mutations N|max
Number of mutation diffs to show (default 20, 0 for none).
--mutators LIST
Comma-separated mutators or profiles to use.
--test-framework NAME
Test framework: phpunit, phpspec, codeception.
--test-framework-extra-args ARGS
Extra arguments for the test framework.
--git-diff-filter FILTER
Mutate only files matching a git diff filter, e.g. AM.
--git-diff-lines
Mutate only added or changed lines.
--git-diff-base BRANCH
Base branch for git diff options.
--coverage DIR
Use existing coverage reports.
--skip-initial-tests
Skip the initial test run (requires --coverage).
--only-covered
Mutate only code covered by tests.
--logger-text, --logger-html, --logger-github, --logger-gitlab FILE
Write a report in the given format.
--log-verbosity all|default|none
Detail level of file logs.
-c, --configuration FILE
Custom configuration file (default infection.json5).
--dry-run
Generate mutants without running tests.
--filter PATH
Deprecated since 0.34.0; pass paths as arguments instead.
--help
Display help information.

CAVEATS

PHP-only. Requires a coverage driver (Xdebug, PCOV or phpdbg) and PHPUnit, PhpSpec or Codeception. Resource intensive on large codebases. Tests that depend on each other or a shared database can produce false results with multiple threads.

HISTORY

Infection was created by Maks Rafalko and first released in 2017, bringing AST-based mutation testing to PHP.

SEE ALSO

phpunit(1), phpspec(1), pest(1), composer(1)

RESOURCES

Copied to clipboard
Kai