Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to have Behat NOT fail on PHP Notice errors?

Tags:

php

behat

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 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!

like image 586
JuanXarg Avatar asked Dec 01 '22 06:12

JuanXarg


1 Answers

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
like image 68
JuanXarg Avatar answered Dec 06 '22 03:12

JuanXarg