-
-
Notifications
You must be signed in to change notification settings - Fork 5
Todo list TDD tutorial
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.
A simple rule is: do not write application code until there is a failing test ready for it.
The rhythm is usually:
- write a small failing test
- write the smallest amount of code that makes it pass
- 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.
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.
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.
- File-based routing
- Page views
- Page logic
- Dynamic URIs
- Headers and footers
- Custom HTML components
- Page partials
- Binding data to the DOM
- DOM manipulation
- Hello You tutorial
- Todo list tutorial
- Address book tutorial WIP
- Blueprints
- Application architecture
- Coding styleguide WIP
- PHP environment setup WIP
- Web servers WIP
- Background cron tasks
- Database setup WIP
- Client-side compilation WIP
- Testing WebEngine applications WIP
- Production checklist WIP
- Security WIP