Data to test with

Exercise 2 of 6 in chapter 6 · 230 XP · 4 objectives checked by tests

Topics covered: Test databaseFixturesCrawler

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:

  1. in setUp(), save a category and a few dishes, with the BaseDeDonnees (database) trait, which is provided: recreerLaBase() (recreate the database), then enregistrer(...$objets) (save the objects);
  2. check that /menu?budget=5 only offers the affordable dishes, from cheapest to most expensive;
  3. 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?

Three mutants 🐛 are waiting for you. They are built to slip through data that is too well-behaved.