PHPUnit:convertWarningsToExceptions="false" 似乎没有效果

PHPUnit : convertWarningsToExceptions="false" seems to have no effect

我刚刚在 Symfony 2.7 项目中从 PHPUnit 3.7.28 移动到 5.1.4,并且在启动测试时出现错误,这是我以前没有遇到过的。

这些错误是 phpunit 在 PHP 警告时引发的异常。我试图在配置文件 phpunit.dist.xml 中使用 convertWarningsToExceptions="false" 来阻止它们(还有错误和通知,但这不是必需的):

<phpunit backupGlobals="false"
     colors="true"
     bootstrap="bootstrap.php.cache"
     convertWarningsToExceptions="false"
     convertNoticesToExceptions="false"
     convertErrorsToExceptions="false"
>

但错误仍然存​​在。 PHP单元输出中的此类错误示例:

1) AppBundle\Tests\Controller\SecurityControllerTest
exception 'Symfony\Component\Debug\Exception\ContextErrorException' with  message 'Warning: pg_query(): Query failed: ERREUR:  erreur de syntaxe sur ou près de « NOT »
LINE 4: CREATE SCHEMA IF NOT EXISTS website;
                     ^' in /.../AppBundle/Tests/Controller/SecurityControllerTest.php:18
Stack trace:
#0 [internal function]: Symfony\Component\Debug\ErrorHandler->handleError(2, 'pg_query(): Que...', '/var/DATA/jenki...', 18, Array)

我找到了一个变通方法,通过使用 @ 使抛出警告的函数调用保持静默(此处 pg_query),但我对该解决方案不满意。

为什么 phpunit 仍然将我的配置中的警告转换为异常?

convertWarningsToExceptions="true" 将 php 警告转换为 PHPUnit 异常。 convertWarningsToExceptions="false" 禁用此功能。就这样。

您有一个 Symfony\Component\Debug\Exception\ContextErrorException 由系统的某些组件明确抛出。这不是 php 警告。