Bee hat for Behat

Behat 3 Tables and TableNode Examples

Behaviour Driven Development (BDD) with Behat 3 is a thing of beauty. When combined with PHPSpec you get something I am hugely excited about.

However, there are many ways in which BDD can be daunting not just for the new-comer, but for a new project in general.

Once you have a feature or two written up, copy / pasting and doing a little editing can yield quick results but writing the code that lives in the underlying Feature Context can be a little harder. For me, this was most evident when dealing with Scenarios that contained tabular data.

I made myself a little Behat TableNode cheat sheet to help – at a glance, and whilst in my IDE (PHPStorm btw) – figure out just what might be in my TableNode objects for the specific methods available on that class.

This is an example of the scenario I was working with:

Behat 3 TableNode var_dump

And a dump of the resulting TableNode:




Hopefully this is as useful a reference to you as it has become for me. Being able to quickly ‘guess’ what is going to be in my TableNode objects and where has helped save me a good deal of time already.


Published by

Code Review

Code Review

CodeReviewVideos is a video training site helping software developers learn Symfony faster and easier.

2 thoughts on “Behat 3 Tables and TableNode Examples”

  1. Hi,
    Is there a way of passing array from a feature file to the context file. Say I had to pass an array (e.g array(1,2,3);), how can I achieve that? Any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.