What's new in Infection 0.18.0

Oct 17, 2020

Release: https://github.com/infection/infection/releases/tag/0.18.0

New features and enhancements

Exclude mutations matching the source code by Regular Expression

You may want to exclude mutations to the code that, if mutated, has little-to-no impact, or, alternatively, sometimes isn’t worth testing the result of - for example calls to a logging function.

If your codebase has lots of logging, this can generate many unwanted mutants and will greatly slow down the mutation test run.

Consider these examples:

- $this->logger->error($message, /* context */ ['user' => $user]);
+ $this->logger->error($message, []);
- Assert::numeric($string);

To avoid them, you can ignore mutations by regular expression, matching the source code:

{
"mutators": {
"global-ignoreSourceCodeByRegex": [
"\\$this->logger.*"
]
}
}

Or just per Mutator:

{
"mutators": {
"MethodRemoval": {
"ignoreSourceCodeByRegex": [
"Assert::.*"
]
}
}
}

global-ignoreSourceCodeByRegex allows to apply the ignoreSourceCodeByRegex setting to all mutators & profiles registered and works similar to global-ignore setting.

Read more about ignore and ignoreSourceCodeByRegex settings

Exact matching:

{
"mutators": {
"MethodRemoval": {
"ignoreSourceCodeByRegex": [
"Assert::numeric\\(\\$string\\);"
]
}
}
}

Ignore any mutants with particular method name, e.g.:

- public function methodCall() {
+ protected function methodCall() {
- $this->methodCall();

with the following config:

{
"mutators": {
"global-ignoreSourceCodeByRegex": [
".*methodCall.*"
]
}
}

Do not add any delimiters (like /) to the regular expression: we are adding and escaping them for you.

Allow fractional values for timeout

Allows fractional values for timeout. For example: half a second.

infection.json:

{
"timeout": 0.5
}

Partial PHPUnit 9.3 support

Infection is routinely tested with and using the most recent version of PHPUnit. The only caveat is the still missing support for the new schema. Therefore, to use Infection with recent versions of PHPUnit one should avoid upgrading the configurations, and list a path to the old schema in the configuration like so:

<phpunit
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/schema/9.2.xsd"
...>

Using old schema is enough to get Infection running with PHPUnit 9.3 and 9.4.

New Mutators

SharedCaseRemoval mutator

Code like this:

switch ($value) {
case 'a':
doSomething();
break;
case 'b':
case 'c':
default:
doSomethingElse();
break;
}

Creates the following mutants:

switch ($value) {
case 'a':
doSomething();
break;
- case 'b':
case 'c':
default:
doSomethingElse();
break;
}
switch ($value) {
case 'a':
doSomething();
break;
case 'b':
- case 'c':
default:
doSomethingElse();
break;
}
switch ($value) {
case 'a':
doSomething();
break;
case 'b':
case 'c':
- default:
doSomethingElse();
break;
}

This mutator removes only shared cases because there is no way to see they are missing tests by looking at the code coverage.


Enjoy!

Star