Gorm has done the math. Since the website opened, Pippin has “improved” the tavern four times, and four times everything broke. Each time, they only found out because a customer complained.
“Never again!” From now on, automated tests stand guard: with every change, they check that the tavern still works.
Your mission
Write the tests for the reservation page, in tests/Taverne/ReservationTest.php:
- the
/reservationpage is displayed, with its form and “Table for 2 adventurers” by default; - a valid reservation (Gimli, 3 adventurers) redirects to
/reservation, then displays “Table booked for Gimli (3 adventurers)!”; - a reservation for 13 adventurers is refused (422), with an error message.
Nothing to change in the application: this time, you only write the tests.
How your tests are graded
Your tests must first pass on the tavern as it is. Then we secretly slip bugs into the application: these are the mutants 🐛. A good test fails when the application is broken. Each mutant your tests detect completes an objective. A mutant that goes unnoticed is a missing test.
The list of detected and surviving mutants appears at the end of the “PHPUnit output”.
The toolbox
$client = static::createClient(); // a simulated browser $client->request('GET', '/reservation'); $client->submitForm('Book', ['nom' => 'Gimli', 'personnes' => 3]); $client->followRedirect(); $this->assertResponseIsSuccessful(); // 2xx $this->assertResponseStatusCodeSame(422); $this->assertResponseRedirects('/reservation'); $this->assertSelectorExists('form.reservation'); $this->assertSelectorTextContains('.flash', 'Table booked');
The form fields keep their French names: nom (name) and personnes (number of adventurers).