Behavior Driven Development with CakePHP, Django, Drupal, and Symfony

Cocomore

In a workshop we did at FUxCon 2013, the grand meetup of Frankfurt users' groups, we presented a comparison of four web frameworks, CakePHP 2, Django 1.5, Drupal 7, and Symfony 2. Our goal was to compare the different approaches in the four frameworks and to introduce Behavior Driven Development at the same time. Drupal stands out as the one system that requires the least custom code to implement our example behavior.

We based our comparison on a simple portfolio website, consisting of a start page with marketing text and a project list below it. From the start page, more pages with project lists can be reached, using a paginator at the bottom of the page. Each project entry shows title, teaser text, and a small picture. Project detail pages with a big photo, list of topics, title, and description can be reached by clicking on the teaser titles or pictures. The descriptions are entered via multiple editors, using Markdown. Pictures are automatically scaled to 200x200px on list pages and 380x380px on project detail pages. Nothing special really. Here is a product canvas for this site:

Product canvas of a portfolio site

 

For our comparison, this portfolio page should be created in all four frameworks. We captured the behavior of the site formally, using the Domain Specific Language (DSL), Gherkin. Behavior definitions in Gherkin are nothing but user stories, well-known from Agile software development, which, in an Agile project, are typically maintained by the product owner. This role is often filled by non-technical people. So the Gherkin language constructs strive to read like natural language.

User stories captured in Gherkin are called features. Features are made concrete by means of scenarios. Scenarios, in turn, are made executable by step definitions, which are nothing more than functional tests we know from classic test-driven development (TDD). The fact that scenarios are written in Gherkin first, and thus are readable by non-technicians, makes Behavior Driven Development (BDD) special. This closes the gap between requirements definition and software development.

BDD, the approach of formally defining behavior for a software project, which can then be validated, has been developed since 2003 by Dan North. It was inspired by test-driven development, which was still in its infancy at that time. Dan North first developed a Java-based tool for his methods, but since then, the Ruby-based Cucumber has become quite popular. These tools also first implemented Gherkin.

Behat is the corresponding tool for the PHP world. We used Behat to define our behaviors and tests. All four implementations already fulfill the behavior as described above. However, they are different in a few minor aspects, thus, we have not yet totally reached our goal.

All four implementations are extensively documented with their aspects installation, configuration, modeling, business logic, appearance, user accounts and permissions, topic lists, picture upload and scaling, edit forms, text formatting, and test data generation. They are licensed under the General Public License (GPL) and are available as repositories on Github and for free download as virtual appliances. The behavior definitions, scenarios, and step definitions are available on Github for free as well. Point of entry for this project is the web site cocomore.github.io/fuxcon2013. We look forward to your comments, suggestions, pull requests, and alternative implementations in other frameworks.

About Cocomore

As an agency for marketing, IT and experience design, Cocomore develops communication, e-commerce and CRM solutions (Customer Relationship Management) with a total of 180 employees at its locations in Frankfurt am Main, Cologne, Geneva (Switzerland) and Seville (Spain). Cocomore's customers include Merck, Nestlé, Procter & Gamble, Rabobank, Syngenta, Tele Columbus and the European Broadcasting Union. Cocomore has realized projects in more than 30 countries.