Command Line Options
Besides general Symfony Console application command line options, Infection has its own ones.
--threads or -j
If you want to run tests for mutated code in parallel, set this to something > 1. It will dramatically speed up mutation process. Please note that if your tests somehow depends on each other or use database, this option can lead to failing tests which give many false-positives results.
By default or with --threads=auto, Infection selects the number of threads automatically and leaves some CPU capacity for other processes. The exact number is a heuristic and can change between versions.
To use all the available CPU cores but one (reserved for the main process), use --threads=max. This is a good choice for a dedicated machine or when the tests are IO-bound.
Both values respect CPU quota limits, such as docker run --cpus=2 or taskset -c 0,2.
--threads=auto is available in Infection 0.35.8+
In Infection 0.35.7, --threads=max used the same heuristic as --threads=auto. Between versions 0.33.2 and 0.35.6, Infection used --threads=max as the default.
For Infection versions below 0.26.15, you can detect the number of CPU cores depending on OS:
# on Linux
infection -j$(nproc)
# on OSX
infection -j$(sysctl -n hw.ncpu)Running Infection with more threads does not necessarily lead to better performance. Consider benchmarking several numbers to find one that works best for your particular case.
--test-framework
This is a name of the Test Framework to use. Currently, Infection supports PHPUnit, PhpSpec, Codeception and Testo.
If you are using infection/infection Composer package, PHPUnit is installed by default. Other test framework adapters will be automatically installed on demand.
PHAR distribution is bundled with all available adapters.
Feel free to request a new test framework to be supported out of the box in GitHub’s issues.
--test-framework-extra-args
Available in Infection 0.34.0+
This option allows passing additional options and arguments to the test framework. Example for PHPUnit:
infection --test-framework-extra-args="--verbose --filter=just/unit/tests"This will execute the PHPUnit as:
phpunit [...infection options] --verbose --filter=just/unit/testsor, another example with argument: this will narrow executed tests only for 1 file:
infection --test-framework-extra-args="tests/FooTest.php"This will execute the PHPUnit as:
phpunit [...infection options] tests/FooTest.phpPlease note that if you choose to use
--configuration,--filter, or--testsuiteforPHPUnit, these options will only be applied to the initial test run. Each mutation has a customphpunit.xmlfile generated for it which defines a single testsuite containing the tests which should be executed for that mutation. Applying--filteror--testsuitewould not make sense in this context as the tests have already been filtered down.
--test-framework-options (deprecated)
This option is deprecated since 0.34.0.
Use --test-framework-extra-args instead.
--coverage
Path to the existing coverage reports.
When you use Continuous Integration for your project, probably you are already generating code coverage metrics and run PHPUnit with Xdebug/phpdbg enabled. Then, you run Infection for mutation testing, which in its turn, generates Code Coverage again for internal needs. This dramatically increases the build time because running your tests with debugger twice requires too much time.
With this option it’s possible to reuse already generated coverage in Infection.
For PHPUnit and Codeception:
- Infection requires both the
xmlandjunitreports to work - If
build/coveragepath is provided, it should containcoverage-xmlfolder andjunit.xmlfilebuild/coverage/coverage-xml/*build/coverage/junit.xml
For PhpSpec:
- Infection requires the
xmlreport to work - If
build/coveragepath is provided, it should containphpspec-coverage-xmlfolder
Example:
# collect coverage
vendor/bin/phpunit --coverage-xml=build/coverage/coverage-xml --log-junit=build/coverage/junit.xml
# use coverage
infection --coverage=build/coverage--git-diff-filter
Selects source files by their Git change status. AM includes added and modified files; A includes only added files. This limits mutation testing to files changed on a feature branch or in a pull request.
The value is passed to Git’s --diff-filter option. The Git diff documentation describes all supported status letters and how to combine or exclude them.
For example, suppose you’re on a feature branch targeting main, origin/main has been fetched, and the installed infection command is available on PATH. From the project root:
infection --git-diff-filter=A --git-diff-base=origin/mainThis command selects source files added since the common ancestor of HEAD and origin/main. Existing files that were only modified are outside the selection. With --git-diff-filter=AM, both added and modified source files are included, and Infection can mutate eligible code anywhere in those files.
The --git-diff-base reference explains how Infection finds that common ancestor and chooses a default target when no base is supplied. The CI examples prepare the request’s source checkout and comparison history.
For mutation testing confined to changed lines within those files, --git-diff-lines provides a narrower selection.
infection config:list-sources --git-diff-filter=A --git-diff-base=origin/main lists the source files selected by the same filter without running mutation testing.
--git-diff-base
Sets the branch reference or commit SHA used with --git-diff-filter or --git-diff-lines.
Automatic CI base selection: available in Infection 0.35.11+
An explicit --git-diff-base takes precedence. Without it, Infection selects the base from the current CI environment:
| CI context | Automatically selected base |
|---|---|
| GitHub Actions, pull request | pull_request.base.sha from the event payload at GITHUB_EVENT_PATH, including the immediate target of a stacked PR |
| GitHub Actions, merge queue | merge_group.base_sha from the event payload at GITHUB_EVENT_PATH |
| GitLab CI, merge request | CI_MERGE_REQUEST_DIFF_BASE_SHA, including detached, merged results, and merge train pipelines |
When CI metadata does not provide a base, Infection resolves the local symbolic reference refs/remotes/origin/HEAD, which normally identifies origin’s default branch. If it cannot resolve that reference, it falls back to origin/master. A missing or unreadable GitHub event file, or invalid JSON, also causes Infection to use the repository default lookup.
--git-diff-base=origin/main identifies the target branch. Infection first finds its merge base with HEAD: their best common ancestor. It then compares the checked-out files with that ancestor. This selects changes made since your feature branch diverged. A direct git diff origin/main can also report differences caused by changes made only on main.
For example, suppose your feature branch diverged from main at commit B:
A---B---C---D origin/main
\
E---F HEAD (feature branch)The comparison starts at B, so it includes the feature branch’s changes in E and F. Changes made only on main in C and D are outside this comparison. Local edits to tracked files are also part of the checked-out files being compared.
The selected target commit and enough history to find the common ancestor must be available locally. In a shallow checkout, that history may be missing. If Git cannot find the ancestor, Infection compares directly against the selected target instead. In the example above, comparing directly against D could also select differences caused by C and D, outside your feature’s changes.
With origin/main fetched and the feature branch checked out, either file or line filtering can use that target explicitly:
infection --git-diff-filter=AM --git-diff-base=origin/main
infection --git-diff-lines --git-diff-base=origin/mainThese commands override automatic base selection. Automatic selection only chooses a comparison base; the job still needs to fetch its history and check out the intended source commit. The GitHub Actions and GitLab examples show how those steps fit together.
Infection’s Git commands expose each part of the selection without running tests:
# Print the default reference used when --git-diff-base is omitted.
infection git:default-base
# Resolve the merge base of the default reference and HEAD.
infection git:base-reference
# Inspect an explicit target and the changes relative to its merge base.
infection git:base-reference --base=origin/main
infection git:changed-files --base=origin/main
infection git:changed-lines --base=origin/maingit:default-base prints the selected default reference or SHA from CI metadata, the repository default branch, or the origin/master fallback; it does not verify that the commit exists locally. git:base-reference prints the merge-base SHA, or leaves the base reference unchanged if Git cannot find a merge base. To override automatic selection, the diagnostic option is --base, whereas the mutation-testing command uses --git-diff-base.
git:changed-files lists matching source paths; git:changed-lines lists their changed line ranges. Both respect the configured source directories. git branch --remotes lists the remote-tracking branches available locally, and infection list git lists Infection’s Git diagnostic commands.
--git-diff-lines
Limits mutation generation to added and modified lines of source code in added and modified files.
The default base and merge-base comparison are described under --git-diff-base. On GitHub Actions and GitLab CI, Infection uses the request’s base from CI metadata when available. To select another base, pass it explicitly, for example --git-diff-lines --git-diff-base=origin/main.
For example, if a feature changes one method in a large legacy file, this option selects code spanning the changed lines. --git-diff-filter=AM would instead include eligible code throughout the whole file. The narrower selection can reduce the number of mutants to evaluate while you work on tests for that change.
infection git:changed-lines --base=origin/main shows the source line ranges used for an explicit target. config:list-sources only lists files, so it doesn’t show which lines within those files are selected.
--map-source-class-to-test
Meant to be used together with
--git-diff-lines/--git-diff-filter/--filter
This option can dramatically decrease the time needed for “Initial Tests Run” stage.
If project has N tests files and we run Infection with, for example, infection --git-diff-lines and only 1 file Foo.php is updated/added in a Pull Request - it doesn’t make sense to run all the N tests to generate code coverage if we know that only 1 file of N covers the source code file - FooTest.php.
In practice, PHPUnit even has different methods that help define which test file covers which class:
requireCoverageMetadataconfiguration attribute#[CoversClass(...)]attribute
In the example above, Infection would run only FooTest.php to generate coverage for Foo.php.
Without this option, Infection will attempt to run all the project’s tests, as it doesn’t know which tests cover Foo.php.
Currently, --map-source-class-to-test supports the only one strategy of mapping source class to test file: by adding *Test postfix to a file name. If source class is named Foo, Infection will try to run FooTest.
Under the hood, it builds a regex for --filter option: --filter='FooTest|BarTest'.
--id
Available in Infection 0.30.0+
Run only one Mutant by its ID. Can be used multiple times. If source code is changed, this value can be invalidated. Pass all previous options with this one.
Example of usage: you completed a feature and wrote tests, then you run
infection --git-diff-linesto get all mutations for the new and changed lines. But if there are too many mutations, it can be more convenient to focus on just 1 mutant at a time.
Imagine you want to work on this Mutant:
11) src/SourceClass.php:9 [M] Minus [ID] 6fa7eadad5b9fd1a72e4d80c83a61cc3
@@ @@
{
- public function hello(): string
+ protected function hello(): string
{
return 'hello';
}
}So you copy 6fa7eadad5b9fd1a72e4d80c83a61cc3 value and run the same command as previously, just adding --id=6fa7eadad5b9fd1a72e4d80c83a61cc3:
infection --git-diff-lines --id=6fa7eadad5b9fd1a72e4d80c83a61cc3With this, Infection will only produce one mutant, and you can update your tests and re-run this command to check if it’s killed or still not.
Available in Infection 0.35.11+
The option can be repeated to run several Mutants in one go, e.g. to re-check all the Mutants you were working on:
infection --git-diff-lines --id=6fa7eadad5b9fd1a72e4d80c83a61cc3 --id=b2f1c9a0e4d34c57a8d1f3e6c7b90a12Infection will then only run the Mutants matching any of the given IDs.
--logger-github
Supposed to be used only with GitHub Actions. This logger prints GitHub Annotation warnings for escaped Mutants right in the Pull Request.
Use --logger-github=true to force-enable or --logger-github=false to force-disable it.
Note that the GitHub Actions environment is automatically detected and this switch isn’t actually necessary when executed there.

With the source checkout and comparison history prepared as in the GitHub Actions example, this command generates escaped-mutant annotations for added source files:
infection --logger-github=true --git-diff-filter=AWith --git-diff-lines in place of --git-diff-filter=A, mutation testing covers added and modified lines in both added and modified files. The logger reports escaped mutants from that selection.
Note: Infection automatically detects
GITHUB_WORKSPACEenvironment variable for report linking.
--logger-gitlab
This option is used to provide a path to the generated GitLab (Code Climate) Code Quality Report:
infection --logger-gitlab='gitlab-coverage.json'After Infection completes its job, the gitlab-coverage.json file will be generated. This file can than be included as a codequality report artifact.
Takes precedence over logger.gitlab setting inside infection.json5 file. If you want to always generate the GitLab Coverage report it’s better to configure it inside infection.json5, see here.
The GitLab CI example combines --git-diff-lines with a checkout of the MR’s own source commit. This limits mutation testing, and therefore the report, to that MR’s changes even when the pipeline was created for a merged result or merge train.
See this sample repository as an example of how to configure Code Quality with Infection
This is how it works on PR main page:

This is how it works on diff view:

Note that “See findings in merge request diff view” is not available on free tier
Note: Infection automatically detects
CI_PROJECT_DIRenvironment variable for report linking.
--logger-project-root-directory
While generating GitHub and GitLab reports, Infection need to replace some links to their correct path according to your
repository. To do so, it will auto-detect GITHUB_WORKSPACE GitHub environment variable, and CI_PROJECT_DIR GitLab
environment variable as project root directory.
If this auto-detection does not fit your needs (for instance, while using custom Docker image and custom project path in
GitLab CI), you can customize the path to replace using --logger-project-root-directory option:
infection --logger-project-root-directory='/custom/project/root/directory/path'Note: if
GITHUB_WORKSPACEandCI_PROJECT_DIRcannot be detected, and--logger-project-root-directoryoption is
not set, Infection will try to retrieve the project root directory usinggit rev-parse --show-toplevel.
--logger-html
This option is used to provide a path to the generated HTML Report:
infection --logger-html='mutation-report.html'After Infection completes its job, the mutation-report.html file will be generated with HTML report (example).
Takes precedence over logger.html setting inside infection.json5 file. If you want to always generate HTML report, it’s better to configure it inside infection.json5, see here.
If you want to store HTML report in the cloud (useful for OSS projects), see Stryker Dashboard integration
--logger-text
This option is used to provide a path to the generated text report:
infection --logger-text='mutation-report.log'After Infection completes its job, the mutation-report.log file will be generated with human-readable text report.
Takes precedence over logger.text setting inside infection.json5 file. If you want to always generate text report, it’s better to configure it inside infection.json5, see here.
The option supports
php://stdout,php://stderr, andphp://outputvalues.php://stdoutandphp://stderrcan be useful in CI environments, whilephp://outputcan be useful for same-process PHP wrappers that capture output with output buffering.
--logger-json
This option is used to provide a path to the generated JSON report:
Available in Infection 0.35.11
infection --logger-json='infection-log.json'After Infection completes its job, the infection-log.json file will be generated with machine-readable JSON containing all mutants, the original and mutated source code, and the test framework output. This can be programmatically analyzed, for example on CI. If you only need the general stats, see --logger-summary-json.
Since it takes precedence over logger.json setting inside infection.json5 file, tools built on top of Infection can use this option to get the full report without a custom infection.json5 file.
The option supports
php://stdout,php://stderr, andphp://outputvalues.php://stdoutandphp://stderrcan be useful in CI environments, whilephp://outputcan be useful for same-process PHP wrappers that capture output with output buffering.
--logger-summary-json
This option is used to provide a path to the generated summary JSON report:
infection --logger-summary-json='summary.json'After Infection completes its job, the summary.json file will be generated with machine-readable JSON containing only general stats (similar to json logger but without individual mutant details). This can be programmatically analyzed, for example on CI.
Takes precedence over logger.summaryJson setting inside infection.json5 file. If you want to always generate summary JSON report, it’s better to configure it inside infection.json5, see here.
The option supports
php://stdout,php://stderr, andphp://outputvalues.php://stdoutandphp://stderrcan be useful in CI environments, whilephp://outputcan be useful for same-process PHP wrappers that capture output with output buffering.
--skip-initial-tests
If you have already run the test suite to ensure it is passing, and you are providing coverage using --coverage then you can use this option to increase performance by not running the entire test suite again.
Note that it is extremely important that you ensure the test suite is passing when using this option, otherwise test failures would appear like caught mutations and those mutations may be reported incorrectly.
--only-covered
Run the mutation testing only for covered by tests files.
This option was removed in Infection 0.31.0, use
--with-uncoveredinstead
--only-covering-test-cases
Execute only those test cases that cover mutated line, not the whole test file with covering test cases. Can dramatically speed up Mutation Testing for slow test suites, like functional or integration.
For PHPUnit it uses --filter option under the hood. This option is not applicable for other test frameworks.
Read more about the problem and solution in this blog post
--with-uncovered
Available in Infection 0.31.0+
Allow mutation of code not covered by tests.
--show-mutations or -s
Limits how many colorized diffs of mutated files are shown to the console. 20 mutated diffs are shown by default.
infection --show-mutations=0 # don't show any diffs
infection --show-mutations=50 # will show 50 mutated diffs
infection --show-mutations=max # will show all mutated diffsPlease note that all mutations can be logged to files as well, if enabled. See
logsin usage section.
--configuration or -c
If you want to use custom configuration file path or name, use this option for it.
--min-msi
This is a minimum threshold of Mutation Score Indicator (MSI) in percentage. Can be used with CI server to automatically control tests quality.
Read more about using Infection in CI server
--min-covered-msi
This is a minimum threshold of Covered Code Mutation Score Indicator (MSI) in percentage. Can be used with CI server to automatically control tests quality.
--with-timeouts
Treats timed-out mutants as escaped instead of killed - this affects MSI calculation.
By default, timed-out mutants are counted as “killed” because the mutation was detected (the test didn’t pass). However, timeouts can hide real test gaps, especially on CI environments with weaker CPUs where mutations that would escape locally instead time out.
A timeout is not an unnatural outcome of the tests with mutation testing, but it leads to bad performance unless the timeout is very strict. As such, in some cases, you may want to add more tests than it is strictly necessary to fight against those timeouts.
# Get your real MSI with timeouts counted as escaped
infection --with-timeouts --min-msi=80
# Show timed-out mutations in output (alongside escaped ones)
infection --with-timeouts --show-mutationsUse this option when you want stricter MSI calculation that doesn’t hide potential test gaps behind timeouts.
This option can also be set in configuration file as
timeoutsAsEscaped
--max-timeouts
Fails the build if the number of timed-out mutants exceeds the specified threshold. This is a hard limit that does not affect MSI calculation.
# Fail if any timeouts occur (strict mode for PRs)
infection --git-diff-lines --max-timeouts=0
# Allow some timeouts but set a ceiling
infection --max-timeouts=10
# Combined: strict MSI + hard ceiling
infection --with-timeouts --max-timeouts=5 --min-msi=75Useful for preventing timeout accumulation over time. Especially valuable for PR workflows where you want zero new timeouts introduced.
This option can also be set in configuration file as
maxTimeouts
The --with-timeouts and --max-timeouts options are independent. One affects metric calculation, the other is a hard limit. They can be used separately or together.
--mutators
This is a comma separated option to specify a particular set of mutators or profiles that need to be executed. Example:
infection --mutators=PublicVisibility,Plus,Decrement,@numberSee here to find all mutator names.
--no-progress
This option has two effects:
- It disables intermediate buffering of mutations used to count them. This causes progress bars to not have a total number of mutations displayed, while also reducing memory usage and speeding up the entire process. It is beneficial during CI, and for larger projects.
- It disables dynamic progress bars output to reduce the amount of generated text output.
Disabling progress bars removes the following lines from output on Continuous Integration servers:
Processing source code files: 0/5678
Processing source code files: 1/5678
Processing source code files: 2/5678
Processing source code files: 3/5678
...
5k lines of text
...
Processing source code files: 5678/5678Progress bar display will be automatically disabled with or without this option when either CI or CONTINUOUS_INTEGRATION environment variables are set to "true".
For example, there is no need to enable this option manually on Travis CI just to hide progress bars.
--noop
Use noop mutators that do not change the AST.
All mutant processes run actual tests. It is expected that all Mutants are escaped, because the code is not changed.
For debugging purposes.
Read about debugging issues with
--noopoption here
If you want to see applied mutations but not run tests, use
--dry-runoption.
--dry-run
Run Mutation Testing with applied mutations but without actually running the tests for each Mutant.
All mutant processes returns 0 exit code. It is expected that all Mutants are escaped.
Can be useful for:
- print all mutations that will be applied - when combined with
--show-mutations=max - debugging purposes
--force-progress
Outputs progress bars and mutation count during progress even if a CI is detected.
This option also reverts optimizations made by --no-progress option, read here.
--static-analysis-tool
Enable static analysis integration to catch escaped mutants that are not killed by tests.
Supported static analysis tools: phpstan, mago.
infection --static-analysis-tool=phpstan
infection --static-analysis-tool=magoWhen enabled, Infection will:
- Run an initial static analysis check to ensure the tool passes and warm up caches
- Execute the static analysis tool for each mutant that escapes (is not killed by) the test suite
- Mark escaped mutants as “Killed by SA” if the static analysis tool detects errors
This feature helps improve mutation testing effectiveness by catching logical errors that tests might miss, such as:
- Type violations
- Dead code detection
- Unreachable code paths
Requirements for PHPStan:
- PHPStan must be installed at
vendor/bin/phpstan - A valid PHPStan configuration file should be present in your project
Requirements for Mago:
- Mago (>= 1.23.0) must be installed at
vendor/bin/mago - Install via Composer:
composer require --dev carthage-software/mago
Note: This is an opt-in feature. Static analysis is only performed on mutants that escape the test suite, ensuring optimal performance.
--static-analysis-tool-options
Specify additional options to pass to the static analysis tool (e.g. memory limit).
Example: --static-analysis-tool-options="--memory-limit=-1 --stop-on-error".
--formatter
This is a name of console output formatter. Possible values are: dot, progress. Default is dot formatter.
--dots-per-row
Number of dots per row in the dot progress formatter. Use "max" to fit the terminal width.
Accepted values: a positive integer (e.g. --dots-per-row=80) or the literal "max" (e.g. --dots-per-row=max). Default is 50. Only applies when the dot progress formatter is in use.
infection --dots-per-row=80
infection --dots-per-row=maxWith "max", the formatter fits as many dots as the terminal width allows after reserving room for the (current / total) suffix on the right, and never exceeds the total mutation count when it is known.
This option can also be set in configuration file as
dotsPerRow. The CLI flag takes precedence over the configuration file value.
--log-verbosity
The verbosity of the log file, all - this mode will add “Killed mutants” into log file and add additional information, default - normal mode will skip “Killed mutants” section in the log file, none - which will disable logging to files.
infection --log-verbosity=all--initial-tests-php-options
Run Initial Tests process with additional php options. For example with -d zend_extension=xdebug.so which will run Xdebug only for code coverage.
May be useful for cases when Xdebug is not enabled globally. Also it’s useful from performance point of view.
infection --initial-tests-php-options="-d zend_extension=xdebug.so"--ignore-msi-with-no-mutations
Ignore MSI violations when no mutations are generated. This will force Infection to return a zero exit code even when the required MSI is not reached.
--debug
Run Infection in a debug mode. With this option Infection will not erase tmpDir and this might be useful to run particular unit test with a mutated code for example.
Also, this option will add test framework’s output to log file so you can analyze by which test particular Mutant was killed, and additional information about executed command lines will be added.
--filter (deprecated)
Deprecated since Infection 0.34.0
Since Infection 0.34.0, positional arguments select source paths without this option. For example, when src/ is a configured source directory, these commands select one source file and then two source files:
infection src/Service/Mailer.php
infection src/Service/Mailer.php src/Entity/Foobar.phpThe deprecated option remains available for existing commands. It selects source files whose paths contain any of its comma-separated values:
| Existing option | Files selected |
|---|---|
--filter=src/Service/Mailer.php | Source files with src/Service/Mailer.php in their paths |
--filter=Mailer.php | Source files with Mailer.php in their paths, across configured source directories |
--filter=src/Service/ | Source files under a matching src/Service/ directory |
--filter=Mailer.php,Foobar.php | Source files matching either filename fragment |
Since Infection 0.35.12, Infection trims whitespace around each value, discards blank entries and removes duplicates. For an existing command containing --filter=' Mailer.php, , Foobar.php ', the spaces and blank entry no longer affect selection: it matches the same source files as --filter=Mailer.php,Foobar.php.
An entirely blank filter applies no file restriction and selects all configured sources, subject to their exclusions. The value 0 is retained: --filter=0 selects paths containing 0, such as src/Version0/Parser.php, rather than selecting all source files.
This option only filters file paths. Positional source symbol selectors can narrow mutation generation to a class or method within the selected files.
Source filtering leaves the initial test selection unchanged. Infection still runs the configured test suite unless test paths or test-framework options narrow it. For existing commands, infection config:list-sources --filter=Mailer.php lists the source files matching that filter.