有没有办法让 Behat 不会因 PHP 通知错误而失败?

发布于 2025-01-03 00:44:04 字数 538 浏览 3 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

万劫不复 2025-01-10 00:44:04

编辑:这适用于 Behat v2.x。对于v> 3.x 请参阅下面 Alexander Haas 的回答。

终于找到了!通过深入研究代码,我发现 Behat 有一种方法可以更改错误报告级别。 执行即可

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

只需在 FeatureContext.php 文件中 。它确实有效!

之后,我在 google 上搜索了该常量,并在 变更日志中找到了它

  • :要更改的 BEHAT_ERROR_REPORTING 常量错误报告级别

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

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:

  • Added BEHAT_ERROR_REPORTING constant to change error_repoting level
探春 2025-01-10 00:44:04

对于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文