phpstan/mutant-killer-infection-runner
Composer 安装命令:
composer require phpstan/mutant-killer-infection-runner
包简介
Static analysis on top of mutation testing - prevents escaped mutants from being invalid according to static analysis
README 文档
README
This plugin is designed to run static analysis on top of infection/infection
test runs in order to discover if escaped mutants
are valid mutations, or if they do not respect the type signature of your
program. If the mutation would result in a type error, it is "killed".
TL;DR:
- This will improve your mutation score, since mutations which result in type errors become killed.
- This is very hacky, and replaces
vendor/bin/infectionessentially. Please read theStabilitysection below first for details. - This is currently much slower than running infection by itself. There are ideas/suggestions to improve this in the future.
This plugin is a fork of excellent Roave/infection-static-analysis-plugin and uses PHPStan instead of Psalm.
Usage
The current design of this tool requires you to run vendor/bin/phpstan-mutant-killer-infection-runner
instead of running vendor/bin/infection:
composer require --dev phpstan/mutant-killer-infection-runner vendor/bin/phpstan-mutant-killer-infection-runner
Configuration
The phpstan-mutant-killer-infection-runner binary accepts all of infection flags and arguments, and an additional --phpstan-config argument.
Using --phpstan-config, you can specify the PHPStan configuration file to use when analysing the generated mutations:
vendor/bin/roave-infection-static-analysis-plugin --phpstan-config phpstan.neon
Background
If you come from a statically typed language with AoT compilers, you may be confused about the scope of this project, 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.
Take for example following snippet:
/** * @template T * @param array<T> $values * @return list<T> */ function makeAList(array $values): array { return array_values($values); }
Given a valid test as follows:
function test_makes_a_list(): void { $list = makeAList(['a' => 'b', 'c' => 'd']); assert(count($list) === 2); assert(in_array('b', $list, true)); assert(in_array('d', $list, true)); }
The mutation testing framework will produce following mutation, since we failed to verify the output in a more precise way:
/**
* @template T
* @param array<T> $values
* @return list<T>
*/
function makeAList(array $values): array
{
- return array_values($values);
+ return $values;
}
The code above is valid PHP, but not valid according to our type declarations.
While we can indeed write a test for this, such test would probably be
unnecessary, as existing type checkers can detect that our actual return value is
no longer a list<T>, but a map of array<int|string, T>, which is in conflict
with what we declared.
This plugin detects such mutations, and prevents them from making you write unnecessary tests, leveraging the full power of PHPStan.
Stability
Since infection/infection is not yet
designed to support plugins, this tool uses a very aggressive approach to bootstrap
itself, and relies on internal details of the underlying runner.
To prevent compatibility issues, it therefore always pins to a very specific version
of infection/infection, so please be patient when you wish to use the latest and
greatest version of infection/infection, as we may still be catching up to it.
Eventually, we will contribute patches to infection/infection so that there is a
proper way to design and use plugins, without the need for dirty hacks.
phpstan/mutant-killer-infection-runner 适用场景与选型建议
phpstan/mutant-killer-infection-runner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 535 次下载、GitHub Stars 达 13, 最近一次更新时间为 2025 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 phpstan/mutant-killer-infection-runner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phpstan/mutant-killer-infection-runner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 535
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-18