Skip to content

Todo list TDD tutorial

Greg Bowler edited this page May 11, 2026 · 2 revisions

This tutorial revisits the todo list tutorial, but approaches it from test-first development. The implementation details are largely the same, so the focus here is on the order of work rather than on introducing different features.

Getting started with TDD

A simple rule is: do not write application code until there is a failing test ready for it.

The rhythm is usually:

  1. write a small failing test
  2. write the smallest amount of code that makes it pass
  3. repeat

That process tends to keep the design small and makes it much harder for behaviour to appear in the application without being covered by a test.

First steps

The first tests should prove useful behaviour, not language features. There is usually no value in testing that a class can simply be constructed.

A more useful sequence is:

  • the to-do list is empty by default
  • requesting an item by ID returns null
  • creating an item stores it in the list
  • retrieving an item returns the expected data
  • editing an item updates the stored result
  • toggling complete status changes the right value
  • deleting an item removes it cleanly

By the end, the same feature set exists as in the original tutorial, but the behaviour is now proved step by step.

Behavioural tests

Once the application classes are covered by PHPUnit, browser-level behaviour can be exercised with Behat so the page interactions are tested as well.

That gives us both kinds of confidence: the business behaviour works, and the user can actually drive it through the browser.


Move on to the next tutorial: address book tutorial.

Clone this wiki locally