How to run Behat tests when there are errors of level E_USER_DEPRECATED

2.4k views Asked by At

I have a Symfony 2.7 Form Type which is causing some errors of level E_USER_DEPRECATED. This errors do not come from my own code but from vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php.

In dev mode using a web browser, I can access the page using said form just fine. The WDT does show me some DEPRECATED messages but the form does work, the page is returned with status 200.

Using Behat 3 (with Behat\Symfony2Extension\Driver\KernelDriver and Behat\Mink\Driver\BrowserKitDriver), the request for the same URL returns a status 500 server error. The stack trace in the response shows that the DEPRECATED errors are causing a exception.

My Behat configuration is as plain as described in http://docs.behat.org/en/v3.0/cookbooks/1.symfony2_integration.html

When I do define('BEHAT_ERROR_REPORTING', 0); on top of my FeatureContext.php file as suggested by https://stackoverflow.com/a/9217606/2342504 there is no change in behaviour.

After some code scanning, I guess that the constant BEHAT_ERROR_REPORTING is removed in Behat 3 and the RuntimeCallHandler::errorReportingLevel is used instead.

Yet I currently have no idea how to configure or set RuntimeCallHandler::errorReportingLevel.

1

There are 1 answers

1
Alexander Haas On BEST ANSWER

So I got it. This file gave me the required hint: https://github.com/Behat/Behat/blob/master/features/error_reporting.feature#L100-L101

To get the required integer, I used php -r "echo E_ALL & ~E_USER_DEPRECATED;" which yielded 16383. So I put this into my behat.yml:

    calls:
        error_reporting: 16383

After that Behat finally did not break, but it did show ugly exception-traces. So I put back the call to error_reporting in FeatureContext.php, right before the class definition:

error_reporting(error_reporting() & ~E_USER_DEPRECATED);

Now Behat ignores all errors of level E_USER_DEPRECATED and I guess I will keep it that way until I start using Symfony 3.