- Command Line Options
- Using with CI
- Mutation Badge
- How-to Guides
- Compare with competitors
- What's new in Infection 0.12.0
- What's new in Infection 0.11.0
- What's new in Infection 0.10.0
- What's new in Infection 0.9.0
- What's new in Infection 0.8.0
The first time you run Infection for your project, it will ask you several questions to create a config file
infection.json.dist, with the following structure:
You can commit it to the VCS and, if necessary, override it locally by creating
infection.json which should be ignored (e.g. in
directories- array, contains all folders with source code you want to mutate. Can be
., but make sure to exclude
vendorin this case.
excludes- array, contains all folders or files you want to exclude within your source folders. You can use glob pattern (
*Bundle/**/*/Tests) for them as well as everything that accepts Symfony Finder’s notPath() method - path or regular expression. In order to skip all files containing
.interface.phpin the name, you would write it as
Infection automatically excludes
testsfolders if the source folder is
.(current dir). Make sure to not mutate your test suite.
excludeskey are relative to the
timeout- the allowed timeout configured for Infection. Make sure to set it to higher value than your tests are executed in seconds to avoid false-positives.
text- human readable text log file. Must see to understand what is going on during mutation process.
summary- summary log file, which will only tell display the amount of mutants per category, (Killed, Errored, Escaped, Timed Out & Not Covered)
debug- debug log file, which displays what mutations were found on what line, per category.
perMutator- a markdown file which will give a break-down of the effectiveness of each mutator.
tmpDir- Optional. It’s a folder where Infection creates its configs, caches and other stuff. It may be useful for people who doesn’t have access to the default system temporary folder and/or doesn’t have write permissions. Either absolute
var/cachepaths can be used.
phpUnit- optional key
configDir- custom directory path with
phpunit.xml.distfile. This is useful for example for old Symfony app, where
phpunit.xml.distis located at
customPath- custom path to PHPUnit executable. This is useful when you run tests by external shared phar file that is located outside project root.
mutators: optional key, it contains the settings for different mutations and profiles, read more about it here
testFramework: optional key, it sets the framework to use for testing. Defaults to
phpunit. This gets overridden by the
--test-frameworkcommand line argument.
bootstrap: optional key, use to specify a file to include as part of the startup to pre-configure the infection environment. Useful for adding custom autoloaders not included in composer.
initialTestsPhpOptions: optional key, specify additional php options for the initial test (IE: Enabling X-Debug).
--initial-tests-php-optionswill override this option.
testFrameworkOptions: optional key, specify additional options to pass to the test framework (IE: Enabling Verbose Mode).
--test-framework-optionswill override this option.
If you have a custom autoloader or bootstrap file for your application, you should tell Infection about it.
For example you have
then you have to add it to the
Thus, Infection will know how to autoload
NonPsr4CompliantFile class. Without adding it to the config, Infection will not be able to create Mutations because internally it uses
new \ReflectionClass() objects.
Ensure that your tests are all in a passing state (incomplete and skipped tests are allowed). Infection will quit if any of your tests are failing.
If you have installed Infection as a global composer package, just run it in your project’s root:
or if you cloned it to some folder:
# cd /path/to/project/root
In order to run Infection with Xdebug, you have several options:
In this case just run
Since Infection needs Xdebug only to generate code coverage in a separate process, it is possible to enable debugger just there.
Assuming Xdebug is disabled globally, run
./infection.phar --initial-tests-php-options="-d zend_extension=xdebug.so"
In order to run Infection with
phpdbg instead of Xdebug, you need to execute the following command:
phpdbg -qrr infection.phar
It is possible to run Infection without any debugger enabled. However, in this case you should provide already generated code coverage as an option
Read more what types of coverage Infection requires and how to do it.
@codeCoverageIgnore annotation on class and method level.
The following class will not be mutated, because it does not produce any code coverage.
In this example, method
generate() will be skipped from mutation logic, but
getDependencies() will be mutated as usual method.
To update your current phar, just run:
Note: Using a phar means that fixes may take longer to reach your version, but there’s more assurance of having a stable development version. The public key is downloaded only once. It is re-used by self-update to verify future phar releases.
While we recommend to use the most stable releases, you can update it to pre-release version if available
./infection.phar self-update --pre
It’s possible to check if there is a new version available:
./infection.phar self-update --check
If you experience any issues self-updating with unexpected
openssl or SSL errors, please ensure that you have enabled the
openssl extension. For example on Windows, you can do this by adding or uncommenting the following line in the
php.ini file for PHP on the command line (if different than the file for your http server):