Search code examples
phpbddbehat

Find what step N is in Behat


I'm running a small suite of Behat tests, and getting an error in my Feature Context.

I can see that the error is triggered by trying to deserialise invalid json in my FeatureContext (json_decode()). However, I can't see the string it was trying to deserialise.

...................................................................... 70
...................................................................... 140
...................................................................... 210
...................................................................... 280
...................................................................... 350
...................................................................... 420
...................................................................... 490
...................................................................... 560
...................................................................... 630
...................................................................... 700
......................PHP Fatal error:  Cannot access property started with '\0' in tests/Behat/FeatureContext.php on line 512

I can see this is step #722. Is there an easy way to get the Feature, and line number from that?

I realise I can run this with pretty format on, and that will work in this case, but some of my other suites take over 2 hours to run. I was wondering if there was an easier way to do it.


Solution

  • There seem to be no way to know which Step failed if you haven't prepared your test suite for that. Steps are also "multiplied" but the Scenario outline cases, which makes it even harder to write any hacky Features parsing script to just count up all the steps as they might've been parsed by Behat.

    But for the future you can use "Before step" and "Before scenario" hooks to log step contents and scenario names. This way you should have all their names logged as a list.