You probably already know from the latest post that Sylius is awesome eCommerce framework.
If you don’t, read this and you will 🙂
What the Behat?
What makes it so special? Many factors. One of them is the development workflow. Sylius uses BDD way of creating new lines of code which is great once you realize that communication between business and development is not something you may call easy.
One of the best things about BDD is that instead of focusing how a code should work like you do in TDD, you are concerning more on what this code should do for you. Sometimes it was a little bit tricky to explain to a potential customer why writing tests is so important and why should he pay some extra money for something which from the business point of view does nothing. Even though the benefits of having the app fully tested for tech people are obvious but, believe me, or not – it’s not the case for the non-tech guy.
On the other hand, BDD can save you much time in big and complicated projects where a developer has to figure out the customer’s needs. Deep understanding of the specific business process is not something developer should care about. Predicting the value of code he creates and potential limits ARE NOT his responsibilities. Writing feature stories makes development rapid while by the time you don’t understand or you don’t feel comfortable with the customer specification, you don’t have to ask your project manager to ask the client “What was on your mind?”. Having one straightforward feature description syntax helps not only with keeping the developer’s responsibilities ordered but also often eliminates potential concept issues before they are implemented. I have mentioned only a few reasons why Behat probably something that should appear in any business project, but you can read the quick intro of Behat documentation for some more information which I advise you to do.
Ok, but you probably know that there are many types of tests. Behat you can write functional tests which test the behavior of your software as a whole. But what about the implementation itself? Should Behat be enough?
The answer is no,
Behat is not enough
Let’s face the truth – low budget projects have mostly low tests coverage. When the customer decides to pay for tests he will probably understand that proper architecture is something you can call at least really important. Considering a well designed, object oriented and maintainable code, you may find Behat will not be enough. That’s where PHPSpec comes into play.
In nutshell, PHPSpec helps you to describe the behavior of simple, decoupled class. This, however, helps you writing isolated domain model. And hey, reading the documentation of this tools will not take you more than drinking three cups of coffee, I promise. It’s that simple.
Personally, I love it because of the way it is stupid. Here are some ideas I share with Marcelo Duarte, the author of this blog post I encourage you to read.
In next parts of this article I will implement a simple Book resource with one of Sylius components named ResourceBundle. You can treat it as a basic intro into the BDD in Sylius as well as how to implement some new platform functionality like new admin tab which simply does something awesome. I will try to make it as simple as it’s possible and especially for you, my friend, I am sharing this tutorial code on this GitHub repository.
One thing before we start – by the time I am writing this tutorial, Sylius most stable version is beta-2. This is the one we will be using in next three parts of this article. We will also work with FriendsOfBehat components which makes working with Behat way much easier in Symfony applications with Sylius on top. Those components come by default for the dev version of Sylius platform, but in case you would like to start using Behat in your existing Symfony app which is not a Sylius platform, you can use these FOB extensions in a similar way.
If you want to use ResourceBundle without the whole Sylius platform in your Symfony app,
you can check the official Sylius ResourceBundle documentation which will help you a lot.