在某些因警告而失败的测试中调用 PHPunit 时,我得到:
$ phpunit -c phpunit.xml --group app
Warning - MongoCollection::insert(): expects parameter 1 to be an array or object, null given in ...
<more output>
OK, but incomplete or skipped tests!
Tests: 17, Assertions: 81, Incomplete: 1.
其中一个测试应该会失败,但实际上并没有; PHPunit 将其标记为“不完整”。
让我们检查最后的退出状态:
$ echo $?
0
我使用的配置是:
<phpunit
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
strict="true"
stopOnError="true"
stopOnFailure="true"
stopOnIncomplete="true"
stopOnSkipped="true"
colors="true"
bootstrap="bootstrap_phpunit.php"
>
知道如何在“不完整”测试的情况下强制 PHPunit 发出非零退出状态吗?
最佳答案
感谢 gontrollez,我开始研究错误处理程序并最终找到了解决方案:
set_error_handler(function ($severity, $message, $filepath, $line)
{
throw new Exception($severity." - ".$message." - ".$filepath." - ".$line);
});
此代码抛出异常,导致 PHPunit 将测试正确检测为 failed
而不是 incomplete
。它应该放在bootstrap_phpunit.php
中的某处(即在文件中,指定为bootstrap
文件)。
关于php - 如何使 PHPunit 在警告时返回非零退出状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24305936/