Gorm's second project: the menu for a budget (/menu?budget=5). Broke adventurers count on it: no way it should offer them a stew at 12 gold pieces.
This page reads the database. But during the tests, the database starts from scratch: no menu, no dishes. It's up to the test to prepare its own data. These are called fixtures.
Your mission
In tests/Taverne/BudgetTest.php:
- in
setUp(), save a category and a few dishes, with theBaseDeDonnees(database) trait, which is provided:recreerLaBase()(recreate the database), thenenregistrer(...$objets)(save the objects); - check that
/menu?budget=5only offers the affordable dishes, from cheapest to most expensive; - check the message when nothing fits the budget.
Choosing your data is choosing what you test
A test only sees what its data shows it. For each rule, ask yourself: which piece of data would make my test fail if the rule were broken?
- “5 gp or less”: a dish at exactly 5 gp, the edge case;
- “from cheapest to most expensive”: dishes saved out of order. Otherwise, the database returns them in insertion order, and a forgotten sort goes unnoticed;
- “only the affordable ones”: at least one dish that is too expensive.
Three mutants 🐛 are waiting for you. They are built to slip through data that is too well-behaved.