如何使PHP警告失败PHPUnit测试用例?

时间:2015-02-27 14:37:59

标签: php jenkins phpunit automated-tests integration-testing

我正在使用Jenkins,Ant和PHPUnit 4.5.0运行PHP项目的持续集成。 Jenkins的xUnit插件将处理PHPUnit生成的XML日志。

某些重大错误(例如,引用未推送到VC​​S的文件)仅在PHPUnit中引发PHP警告,并且警告不包含在日志中。因此,即使需要修复,构建也会被标记为成功。

如何让PHP警告在构建时失败,例如通过为产生警告的测试引发异常?

2 个答案:

答案 0 :(得分:3)

确保将convert...ToExceptions选项设置为true。很遗憾options are not available in command-line,因此您必须创建phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    convertErrorsToExceptions   = "true"
    convertNoticesToExceptions  = "true"
    convertWarningsToExceptions = "true">
</phpunit>

答案 1 :(得分:0)

我们必须添加failOnWarning="true"才能将此类警告视为错误:

There was 1 warning:
1) The data provider specified for Tests\CreateSomethingTest::testCreateSomething is invalid.
FAILURES!
Tests: 841, Assertions: 2493, Failures: 1, Errors: 0.

所以我们的配置如下:

<phpunit 
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         stopOnFailure="false"
         failOnWarning="true">