有没有办法让Behat不会因PHP Notice错误而失败? [英] Is there a way to have Behat NOT fail on PHP Notice errors?

查看:87
本文介绍了有没有办法让Behat不会因PHP Notice错误而失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,最好是定义所有变量并在评估之前检查数组索引.但是,我正在尝试对一些尚未通过这种方式编码的遗留代码之上开发的新功能进行一些测试.

I understand that it is a best practice to have all variables defined and to check for array indexes before evaluating. However, I'm trying to run some tests on new functionalities developed on top of some legacy code which has not been coded this way.

Behat失败并显示以下消息:

Behat fails with this message:

  Scenario: Add a new resource                         # features/accounting.feature:6
    Given I am user "admin"                            # FeatureContext::iAmUser()
      Notice: Undefined index: 13 in classloader.php line 126
    When I create a new resource                       # FeatureContext::iCreateANewResource()
    Then [...]

我最终将修复这些通知,但是我现在需要Behat忽略来自PHP的通知.有办法吗?

I will fix these notices eventually, but I need Behat to ignore notices from PHP for now. Is there a way to do that?

谢谢!

推荐答案

这将适用于Behatv2.x.对于v> 3.x,请参见下面的Alexander Haas答案.

This will work for v2.x of Behat. For v > 3.x see Alexander Haas answer below.

终于找到了!通过深入研究代码,我发现Behat可以更改错误报告级别.随便

Finally found it! By digging in the code, I found that Behat has a way to change the error reporting level. Just do

define('BEHAT_ERROR_REPORTING', E_ERROR | E_WARNING | E_PARSE);

文件中的

.它能解决问题!

in the FeatureContext.php file. It does the trick!

此后,我搜索了常量,并在更改日志:

Afterwards, I googled the constant and found this in the changelog:

  • 添加了BEHAT_ERROR_REPORTING常量以更改error_repoting级别

这篇关于有没有办法让Behat不会因PHP Notice错误而失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆