- Guide
- Playground
- GitHub
-
Ecosystem
Help
Resource Lists
Documentation
- Introduction
- Installation
- Usage
- Static Analysis Integration
- Command Line Options
- Mutators
- Custom Mutators
- Profiles
- Using with CI
- Mutation Badge, cloud HTML report
- How-to Guides
- Caveats
- Debugging Issues
- Infection Playground
- GitHub Sponsors ♥️
- Supported Test Frameworks
Miscellaneous
- Compare with competitors
Posts
- What's new in Infection 0.32.3
- What's new in Infection 0.26.0
- What's new in Infection 0.25.0
- What's new in Infection 0.24.0
- What's new in Infection 0.23.0
Static Analysis Integration
PHPStan integration: available in Infection 0.30.0+ Mago integration: available in Infection 0.32.7+
Static Analysis Integration helps improve mutation testing effectiveness by catching logical errors that tests might miss, such as:
- Type violations
- Dead code detection
- Unreachable code paths
If you come from a statically typed language with AoT compilers, you may be confused about the scope of this feature, but in the PHP ecosystem, producing runnable code that does not respect the type system is very easy, and mutation testing tools do this all the time.
Consider this example (credit: Roave/infection-static-analysis-plugin):
/** |
Given a test like:
function test_makes_a_list(): void |
A mutation testing framework will produce the following mutation, since the test does not verify the output precisely enough:
function makeAList(array $values): array |
Such mutant is escaped one because tests don’t detect this change. At the same time, this mutated code is valid PHP, but violates the @return list<T> type declaration. A static analysis tool can detect that the actual return value is no longer a list<T> but a map of array<int|string, T>, and kill this mutant — preventing you from having to write an unnecessary test.
Infection supports phpstan and mago as static analysis tools. To enable the integration, install the tool and set staticAnalysisTool in your config:
{ |
or pass it via CLI:
infection --static-analysis-tool=phpstan |
Note: This is an opt-in feature. Static analysis is only performed on mutants that escape the test suite, ensuring optimal performance.