有没有办法让 Behat 不会因 PHP 通知错误而失败?
我知道最好的做法是定义所有变量并在评估之前检查数组索引。但是,我正在尝试对在一些尚未以这种方式编码的遗留代码之上开发的新功能运行一些测试。
Behat 失败并显示以下消息:
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 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 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 [...]
I will fix these notices eventually, but I need Behat to ignore notices from PHP for now. Is there a way to do that?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:这适用于 Behat v2.x。对于v> 3.x 请参阅下面 Alexander Haas 的回答。
终于找到了!通过深入研究代码,我发现 Behat 有一种方法可以更改错误报告级别。 执行即可
只需在
FeatureContext.php
文件中 。它确实有效!之后,我在 google 上搜索了该常量,并在 变更日志中找到了它
EDIT: This will work for v2.x of Behat. For v > 3.x see Alexander Haas answer below.
Finally found it! By digging in the code, I found that Behat has a way to change the error reporting level. Just do
in the
FeatureContext.php
file. It does the trick!Afterwards, I googled the constant and found this in the changelog:
对于 Behat 3,请参阅我的问题和答案:当出现 E_USER_DEPRECATED 级别错误时如何运行 Behat 测试
BEHAT_ERROR_REPORTING
被删除,取而代之的是配置值。For Behat 3 see my question and answer: How to run Behat tests when there are errors of level E_USER_DEPRECATED
BEHAT_ERROR_REPORTING
is dropped in favor of a configuration value.