Is there a way for Behat to NOT crash on PHP notification errors?

I understand that it is best to define all variables and check array indices before evaluating. However, I am trying to run some tests for new features developed on top of some legacy code that was not encoded in this way.

Without this message, it does not work:

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 eventually fix these notifications, but I need Behat to ignore notifications from PHP for now. Is there any way to do this?

Thanks!

+4
source share
2 answers

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

Finally found! Delving into the code, I found that Behat has a way to change the level of error reporting. Just do

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

in the FeatureContext.php file. This is a trick!

Then I googled the constant and found this in changelog :

  • Added constant BEHAT_ERROR_REPORTING to change the level of error
+15
source

For Behat 3, see my question and answer: How to run Behat tests when there are errors of the E_USER_DEPRECATED level

BEHAT_ERROR_REPORTING discarded in favor of the configuration value.

+5
source

Source: https://habr.com/ru/post/1395314/


All Articles