Custom Infection mutation testing mutators for PHPStan's codebase. These mutators target PHPStan-specific patterns (TrinaryLogic, type comparisons, type specifier contexts) that generic Infection mutators would not cover.
Used as a build dependency by PHPStan repositories (phpstan-src, phpstan-doctrine, phpstan-phpunit, phpstan-deprecation-rules, etc.).
Swaps ->yes() with !->no() and vice versa, including the inverse (!->yes() to ->no()). Tests that TrinaryLogic checks are precise and not interchangeable.
- $type->isBoolean()->yes();
+ !$type->isBoolean()->no();Inserts ->toBoolean() before ->isTrue()/->isFalse() calls. Tests that code distinguishes strict boolean type checks from loose boolean comparisons. Skips calls that already chain through ->toBoolean().
- $type->isFalse()->yes();
+ $type->toBoolean()->isFalse()->yes();Swaps the callee and argument of isSuperTypeOf() calls. Tests that the direction of type relationships matters. Supports variables, property fetches, method calls, static calls, and new expressions as both callee and argument.
- $a->isSuperTypeOf($b);
+ $b->isSuperTypeOf($a);Swaps isNonFalseyString() with isNonEmptyString() and vice versa. Tests that code correctly distinguishes between non-falsey strings (excludes "0") and non-empty strings (includes "0").
Note: This mutator is not included in the default config. Consuming repos must add it explicitly via
--mutator-class='PHPStan\Infection\NonFalseyNonEmptyStringMutator'.
- $type->isNonFalseyString()->yes();
+ $type->isNonEmptyString()->yes();Swaps true() with truthy() and false() with falsey() on TypeSpecifierContext (and vice versa). Tests that code correctly handles strict vs loose type specifier contexts.
- $context->false()
+ $context->falsey()- Check out
build-infectionas a subdirectory of the consuming repo - Install its Composer dependencies
- Generate an
infection.json5config:
php build-infection/bin/infection-config.php > infection.json5- Run Infection with the generated config
--source-directory='path/'-- add extra source directories--mutator-class='Fully\Qualified\Class'-- add extra mutator classes--timeout=N-- override the default timeout (30s)
Requires PHP ^8.2.
composer install
make check # lint, coding standard, tests, PHPStan
make tests # PHPUnit (unit + .phpt end-to-end tests)
make phpstan # static analysis (level 8)MIT