How to do Behavior Driven Development (BDD) with Symfony
Second day of our Build CMS Application with Symfony articles suite.
Previous article day 01 - Symfony installation.
We’ll install :
In composer.json file add :
Enable Fixture Bundle in app/AppKernel.php
You now have a full BDD tool onboard, we’ll configure it.
Creating a test bundle
In order to have all our BDD tests at the same place, we create an empty bundle.
We choose “annotation” for config format and no route update.
Ensure that your bundle is enabled in app/AppKernel.php.
We then create folder to host our BDD tests in our BDD Bundle.
Create a behat.yml file at your site root.
Create your first feature test
In src/My/BDDBundle/Features/ create a file named 01-symfony-install.feature. More about features on behat.org.
This is supposed to give you a nice
Behat is unable to find steps (steps documentation on behat.org) and advise you to implement them.
But wait ! We have Mink onboard ! And Mink comes with predefined steps.
Open your src/My/BDDBundle/Features/Context/FeatureContext.php and make your class extend MinkContext.
To see the list of all predefined steps in Mink, just :
And now you get :
Oups ! We have an error ! We can’t see “I love Espelette pepper !”.
Ok, this is the normal way for testing : write tests, run test that fail, develop then run tests that succeed.
Edit src/Acme/DemoBundle/Resources/views/Welcome/index.html.twig and change
All the lights are now green !
Don’t forget to read behat doc and about Espelette pepper.
Next article will be on Sonata Admin Installation.
See you soon.