当在一些失败并出现警告的测试中调用 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
file).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)