infection
Infect files with test viruses
TLDR
Analyze code using the configuration file (or create one if it does not exist)
Use a specific number of threads
Specify a minimum Mutation Score Indicator (MSI)
Specify a minimum covered code MSI
Use a specific test framework (defaults to PHPUnit)
Only mutate lines of code that are covered by tests
Display the mutation code that has been applied
Specify the log verbosity
SYNOPSIS
infection [options] [arguments]
PARAMETERS
--threads
Specifies the number of parallel processes to use for mutation testing. Optimizes execution time for large projects.
--mutators
Allows specifying which mutators (types of code changes) should be applied. Can be a comma-separated list.
--show-mutations
Displays detailed diffs of all killed, escaped, and not covered mutants in the console output.
--coverage
Provides the path to an existing code coverage report (e.g., Clover XML) to optimize the mutation process by only mutating covered lines.
--min-msi
Sets the minimum acceptable Mutation Score Indicator (MSI) percentage. If the actual MSI falls below this, Infection will fail.
--dry-run
Performs a simulation without actually applying mutations or running tests. Useful for checking configuration.
--log-verbosity
Controls the level of detail in the log output (e.g., none, default, debug).
DESCRIPTION
The infection command refers to PHP's Infection, a sophisticated mutation testing framework for PHP codebases. While not a core Linux operating system utility, it is a command-line application designed to run on Linux (and other OSes) typically invoked via Composer's vendor/bin directory or a global installation.
Mutation testing aims to identify weaknesses and gaps in a project's test suite. Infection works by introducing small, targeted changes (mutations) into your source code and then running your existing unit tests. If the tests still pass after a mutation is introduced, it indicates that the test suite failed to 'kill' the mutant, thereby exposing a missing or insufficient test case. This process helps developers improve the robustness and effectiveness of their tests, leading to higher quality and more reliable code.
CAVEATS
The infection command is not a standard Linux system utility. It is an application written in PHP, requiring a PHP runtime and Composer dependency manager to be installed on the Linux system. Its primary use is in software development for improving code quality, not for system administration or security. Running it on large codebases can be resource-intensive and time-consuming.
CONFIGURATION FILE
Infection typically uses a configuration file named infection.json or infection.json.dist in the project's root directory. This JSON file allows developers to specify detailed settings, including paths to source code and test files, custom mutator settings, log outputs, and minimum MSI requirements.
MUTATION SCORE INDICATOR (MSI)
MSI is a key metric reported by Infection, representing the percentage of 'killed' mutants relative to the total number of detectable mutants. A higher MSI indicates a more robust and effective test suite, as it means more mutations (potential bugs) were caught by existing tests.
HISTORY
PHP's Infection framework was initially created by Hannes Van De Vreken and has evolved as an open-source project within the PHP community. It gained popularity as a vital tool for developers aiming to achieve higher quality test suites and improve software reliability by rigorously testing the effectiveness of their unit tests.
SEE ALSO
phpunit(1)