My attempts at exercism.org
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 86 lines 2.8 kB view raw
1<?php 2 3declare(strict_types=1); 4 5use PHPUnit\Framework\TestCase; 6use PHPUnit\Framework\Attributes\TestDox; 7 8/** 9 * We use `assertEquals()` here for its loose type checking. We don't care if 10 * the student returns numeric strings or integers in this exercise. 11 * 12 * - Please use `assertSame()` whenever possible. Add a comment when it is not possible. 13 * - Do not use calls with named arguments. 14 * Use them only when the exercise requires named arguments (e.g. because the exercise is about named arguments). 15 * Named arguments are in the way of defining argument names the students want (e.g. in their native language). 16 * - Add `#[TestDox()]` with a useful test title, e.g. the task heading from `instructions.md`. 17 * The online editor shows that to students. 18 * - Add fail messages to assertions where helpful to tell students more than `#[TestDox()]` says. 19 */ 20class LasagnaTest extends TestCase 21{ 22 public static function setUpBeforeClass(): void 23 { 24 require_once 'Lasagna.php'; 25 } 26 27 /** 28 * @task_id 1 29 */ 30 #[TestDox('Returns cooking time in minutes as stated in the cook book')] 31 public function testExpectedCookTime(): void 32 { 33 $lasagna = new Lasagna(); 34 $this->assertEquals(40, $lasagna->expectedCookTime()); 35 } 36 37 /** 38 * @task_id 2 39 */ 40 #[TestDox('Returns how many minutes more the lasagna must be in the oven when it is 20 minutes in the oven already')] 41 public function testRemainingCookTime(): void 42 { 43 $lasagna = new Lasagna(); 44 $this->assertEquals(20, $lasagna->remainingCookTime(20)); 45 } 46 47 /** 48 * @task_id 2 49 */ 50 #[TestDox('Returns how many minutes more the lasagna must be in the oven when it is 30 minutes in the oven already')] 51 public function testAnotherRemainingCookTime(): void 52 { 53 $lasagna = new Lasagna(); 54 $this->assertEquals(10, $lasagna->remainingCookTime(30)); 55 } 56 57 /** 58 * @task_id 3 59 */ 60 #[TestDox('Returns how many minutes you spent preparing the lasagna with 7 layers')] 61 public function testTotalPreparationTime(): void 62 { 63 $lasagna = new Lasagna(); 64 $this->assertEquals(14, $lasagna->totalPreparationTime(7)); 65 } 66 67 /** 68 * @task_id 4 69 */ 70 #[TestDox('Returns the total minutes you have worked on the lasagna with 4 layers that is 13 minutes in the oven')] 71 public function testTotalElapsedTime(): void 72 { 73 $lasagna = new Lasagna(); 74 $this->assertEquals(21, $lasagna->totalElapsedTime(4, 13)); 75 } 76 77 /** 78 * @task_id 5 79 */ 80 #[TestDox('Returns the message indicating that the lasagna is ready to eat')] 81 public function testAlarm(): void 82 { 83 $lasagna = new Lasagna(); 84 $this->assertEquals("Ding!", $lasagna->alarm()); 85 } 86}