php - 使用 Infection 进行突变测试时,phpdbg 达到内存限制
问题描述
尝试使用 phpdbg 运行感染测试时,我不断收到内存耗尽错误。我试过设置,-d memory_limit
但它似乎被忽略了。
下面是一些示例输出:
$ phpdbg -qrr -d memory_limit=1G vendor/bin/infection
You are running Infection with phpdbg enabled.
____ ____ __ _
/ _/___ / __/__ _____/ /_(_)___ ____
/ // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
_/ // / / / __/ __/ /__/ /_/ / /_/ / / / /
/___/_/ /_/_/ \___/\___/\__/_/\____/_/ /_/
Running initial test suite...
PHPUnit version: 7.5.11
4 [============================] 1 sec
[ERROR] Project tests must be in a passing state before running Infection.
Infection runs the test suite in a RANDOM order. Make sure your tests do not have hidden dependencies.
You can add these attributes to `phpunit.xml` to check it: <phpunit executionOrder="random"
resolveDependencies="true" ...
If you don't want to let Infection run tests in a random order, set the `executionOrder` to some value, for
example <phpunit executionOrder="default"
Check the executed command to identify the problem: '/usr/local/Cellar/php@7.2/7.2.18/bin/phpdbg' '-qrr'
'~/Project/vendor/phpunit/phpunit/phpunit' '--configuration'
'/var/folders/05/qbcbz9cn08jdty7r35dwkgdm0000gn/T/infection/phpunitConfiguration.initial.infection.xml'
PHPUnit reported an exit code of 255.
Refer to the PHPUnit's output below:
STDOUT:
PHPUnit 7.5.11 by Sebastian Bergmann and contributors.
Random seed: 1560152243
[PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65536 bytes) in
~/Project/vendor/sebastian/exporter/src/Exporter.php on line
219]
[PHP Stack trace:]
[PHP 1. {main}()
~/Project/vendor/phpunit/phpunit/phpunit:0]
使用我的infection.json.dist 文件:
{
"timeout": 10,
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "infection.log"
},
"mutators": {
"@default": true
}
}
解决方案
您可以预先收集覆盖范围,然后将其提供给 Infection。
vendor/bin/phpunit --coverage-xml=build/logs/coverage-xml \
--log-junit=build/logs/junit.xml
vendor/bin/infection --coverage=build/logs --show-mutations
由于您不会同时运行 Infection 和 PHPUnit,您可以完全避免内存限制问题。如果没有,运行任何具有更高内存限制的程序应该很容易:
php -d memory_limit=-1 vendor/bin/...
这样,您还可以在修复测试后重新运行 Infection 以查看您是否杀死了突变,而无需重新收集覆盖率数据。
推荐阅读
- android - 外部 SD 卡在移除时损坏
- python - python中CNN多类图像分类的边界框预测
- asp.net - 使用通过 React GUI 触发的实体框架向 DB 添加新条目时出现重复条目
- node.js - 如何使用角度从数据库中获取数据
- asp.net-mvc - 我正在验证用户的凭据,但此函数始终被评估为 true
- java - 如何使用 JCodec 对 Java 视频进行实时编码?
- dart - 如何使飞镖/渡槽永久运行
- java - @ComponentScan 的 excludeFilters 不起作用
- sql - 为什么左连接不给所有左表值和条件为假的其他表的空值?
- python - 仅在遍历 json 数据时获取字符串