有没有办法让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 此后,我搜索了常量,并在更改日志href ="https://github.com/Behat/Behat/blob/5df81971f7796f0ad5c577c608a4ccad12d03b5e/CHANGES.md" >: Afterwards, I googled the constant and found this in the changelog:FeatureContext.php
file. It does the trick!