问题描述:

I've just moved from PHPUnit 3.7.28 to 5.1.4 in a Symfony 2.7 project, and I have errors when I launch tests, that I had not before.

Those errors are exceptions raised by phpunit on PHP warnings. I tried to stop them using convertWarningsToExceptions="false" in the configuration file phpunit.dist.xml (and also Errors and Notices, but this should not be necessary) :

<phpunit backupGlobals="false"

colors="true"

bootstrap="bootstrap.php.cache"

convertWarningsToExceptions="false"

convertNoticesToExceptions="false"

convertErrorsToExceptions="false"

>

But the errors are still here. Exemple of such an error in the PHPUnit output:

1) AppBundle\Tests\Controller\SecurityControllerTest

exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Warning: pg_query(): Query failed: ERREUR: erreur de syntaxe sur ou prs 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)

I found a workaround by making silent with @ the function calls throwing the warnings (here pg_query), but I am not satisfied with that solution.

Why is phpunit still converting warnings to exceptions with my config ?

网友答案:

convertWarningsToExceptions="true" converts php warnings to PHPUnit exceptions. convertWarningsToExceptions="false" disables this functionality. That's all.

You have a Symfony\Component\Debug\Exception\ContextErrorException explicitly thrown by some component of your system. It is not a php warning.

相关阅读:
Top