如何 运行 出现级别 E_USER_DEPRECATED 错误时进行 Behat 测试

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

我有一个 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 returns 状态 500 服务器错误。响应中的堆栈跟踪显示 DEPRECATED 错误导致了异常。

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

中描述的一样简单

当我按照 的建议在我的 FeatureContext.php 文件上执行 define('BEHAT_ERROR_REPORTING', 0); 时,行为没有变化。

经过一些代码扫描,我猜想常量 BEHAT_ERROR_REPORTING 在 Behat 3 中被删除了,取而代之的是 RuntimeCallHandler::errorReportingLevel

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

所以我明白了。这个文件给了我所需的提示: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 终于没有崩溃,但它确实显示了丑陋的异常痕迹。所以我在 FeatureContext.php 中放回对 error_reporting 的调用,就在 class 定义之前:

error_reporting(error_reporting() & ~E_USER_DEPRECATED);

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