Friday, May 23, 2014

Behat Error: PHP Warning: array_combine():

When I attempted to run a Behat Feature with multiline arguments, I kept getting an error.  In the console, the Feature Description lines would print, but the following error would print 3 times thereafter.

PHP Warning: array_combine(): Both parameters should have an equal number of elements in /home/testadm/LbX/vendor/behat/gherkin/src/Behat/Gherkin/Node/TableNode.php on line 133

After hours of searching, I found that it was caused by my arguments and the PHP function array_combine().  This function requires all arrays to be combined to have the same number of elements.  I can't reproduce it now, but these are possible solutions:

  • The simple solution: make sure all your cells have values.
        | Good  | Data | Data |
        | Bad   |      |      | 
  • Don't put comments after a line in a multiline argument.
        | key   | value    |  # No comments after a cell 
  • Make sure your scenarios containing multiline arguments have a semicolon after them.
    Given you have a multiline argument:
        | Data | Value |
        | Data | Value |
    Then make sure you have a semicolon at the end of the line

I'll update this post when I figure out the true cause.

No comments: