如果存在级别E_USER_DEPRECATED错误,如何运行Behat测试

时间:2015-06-25 12:40:53

标签: php symfony behat

我有一个Symfony 2.7表单类型导致一些级别E_USER_DEPRECATED的错误。此错误不是来自我自己的代码,而是来自vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

在使用网络浏览器的dev模式下,我可以使用所述表单访问该页面。 WDT确实向我显示了一些DEPRECATED消息,但表单确实有效,页面返回状态为200.

使用Behat 3(Behat\Symfony2Extension\Driver\KernelDriverBehat\Mink\Driver\BrowserKitDriver),对同一URL的请求将返回状态500服务器错误。响应中的堆栈跟踪显示DEPRECATED错误导致异常。

My Behat配置与http://docs.behat.org/en/v3.0/cookbooks/1.symfony2_integration.html

中描述的一样简单

当我按照https://stackoverflow.com/a/9217606/2342504的建议在我的define('BEHAT_ERROR_REPORTING', 0);文件上FeatureContext.php时,行为没有变化。

经过一些代码扫描后,我猜在Behat 3中删除了常量BEHAT_ERROR_REPORTING,而是使用了RuntimeCallHandler::errorReportingLevel

但我目前不知道如何配置或设置RuntimeCallHandler::errorReportingLevel

1 个答案:

答案 0 :(得分:3)

所以我明白了。这个文件给了我必要的提示:https://github.com/Behat/Behat/blob/master/features/error_reporting.feature#L100-L101

要获得所需的整数,我使用了php -r "echo E_ALL & ~E_USER_DEPRECATED;",它产生了16383。所以我把它放到behat.yml

    calls:
        error_reporting: 16383
之后,Behat终于没有破解,但确实显示出丑陋的异常痕迹。所以我在error_reporting中将FeatureContext.php的调用放回到类定义之前:

error_reporting(error_reporting() & ~E_USER_DEPRECATED);

现在Behat忽略了级别E_USER_DEPRECATED的所有错误,我想我会保持这种方式,直到我开始使用Symfony 3。