From 9c44e574e74cf28b51769a13f4c99ce82796ff26 Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Thu, 23 Jul 2026 14:39:07 +0200 Subject: [PATCH 1/6] configlet create --practice-exercise save-the-cow --- config.json | 8 ++++ .../save-the-cow/.docs/instructions.md | 7 ++++ .../save-the-cow/.docs/introduction.md | 4 ++ .../practice/save-the-cow/.meta/config.json | 15 +++++++ .../practice/save-the-cow/.meta/example.php | 0 .../practice/save-the-cow/.meta/tests.toml | 40 +++++++++++++++++++ .../practice/save-the-cow/SaveTheCow.php | 0 .../practice/save-the-cow/SaveTheCowTest.php | 0 8 files changed, 74 insertions(+) create mode 100644 exercises/practice/save-the-cow/.docs/instructions.md create mode 100644 exercises/practice/save-the-cow/.docs/introduction.md create mode 100644 exercises/practice/save-the-cow/.meta/config.json create mode 100644 exercises/practice/save-the-cow/.meta/example.php create mode 100644 exercises/practice/save-the-cow/.meta/tests.toml create mode 100644 exercises/practice/save-the-cow/SaveTheCow.php create mode 100644 exercises/practice/save-the-cow/SaveTheCowTest.php diff --git a/config.json b/config.json index 78d58addd..035719763 100644 --- a/config.json +++ b/config.json @@ -1386,6 +1386,14 @@ "practices": [], "prerequisites": [], "difficulty": 7 + }, + { + "slug": "save-the-cow", + "name": "Save the Cow", + "uuid": "ec60632c-c682-4f72-87a7-8601c960165b", + "practices": [], + "prerequisites": [], + "difficulty": 1 } ], "foregone": [ diff --git a/exercises/practice/save-the-cow/.docs/instructions.md b/exercises/practice/save-the-cow/.docs/instructions.md new file mode 100644 index 000000000..1ec98a43a --- /dev/null +++ b/exercises/practice/save-the-cow/.docs/instructions.md @@ -0,0 +1,7 @@ +# Instructions + +Implement the logic for a word-guessing game. + +A player tries to solve a secret word by guessing individual letters. +They win if they reveal all the letters in the secret word. +They lose if they make ten incorrect guesses before revealing the word. diff --git a/exercises/practice/save-the-cow/.docs/introduction.md b/exercises/practice/save-the-cow/.docs/introduction.md new file mode 100644 index 000000000..c87a7fa92 --- /dev/null +++ b/exercises/practice/save-the-cow/.docs/introduction.md @@ -0,0 +1,4 @@ +# Introduction + +Bessie the cow has wandered onto an alien spaceship. +Guess the secret door code to bring her home before the ship blasts off. diff --git a/exercises/practice/save-the-cow/.meta/config.json b/exercises/practice/save-the-cow/.meta/config.json new file mode 100644 index 000000000..251a749a1 --- /dev/null +++ b/exercises/practice/save-the-cow/.meta/config.json @@ -0,0 +1,15 @@ +{ + "authors": [], + "files": { + "solution": [ + "SaveTheCow.php" + ], + "test": [ + "SaveTheCowTest.php" + ], + "example": [ + ".meta/example.php" + ] + }, + "blurb": "Implement a word-guessing game." +} diff --git a/exercises/practice/save-the-cow/.meta/example.php b/exercises/practice/save-the-cow/.meta/example.php new file mode 100644 index 000000000..e69de29bb diff --git a/exercises/practice/save-the-cow/.meta/tests.toml b/exercises/practice/save-the-cow/.meta/tests.toml new file mode 100644 index 000000000..eca72c42c --- /dev/null +++ b/exercises/practice/save-the-cow/.meta/tests.toml @@ -0,0 +1,40 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[71d340f9-fc29-4826-872e-ad7d0b83dd98] +description = "Initially 9 failures are allowed and no letters are guessed" + +[76759c24-8f1a-4fc8-9ffd-d6a1ff0cf03b] +description = "After 10 failures the game is over" + +[d6f2e202-7857-46fb-b709-43a7f3f3b2de] +description = "Losing with several correct guesses" + +[71bc0cda-2032-4637-80c8-fc8771124c08] +description = "Feeding a correct letter removes underscores" + +[5b568a1c-867d-418f-97a8-7b6f8a7ca0a2] +description = "Feeding a correct letter twice counts as a failure" + +[3d40f15b-0271-4c5d-b1a4-3e1f66ff221f] +description = "Guessing a repeated letter reveals all instances" + +[11a86435-e401-4250-a26e-3b0d8c4049ad] +description = "Getting all the letters right makes for a win" + +[b3d81876-84ee-45bb-b531-baa1b05b4709] +description = "Winning on the last guess is still a win" + +[cf204398-5e9f-402f-8bff-42cb7cbbbda9] +description = "Guessing after a lose is error" + +[c2ec5b3d-4923-4a0e-a485-6aa6e78c7ece] +description = "Guessing after a win is error" diff --git a/exercises/practice/save-the-cow/SaveTheCow.php b/exercises/practice/save-the-cow/SaveTheCow.php new file mode 100644 index 000000000..e69de29bb diff --git a/exercises/practice/save-the-cow/SaveTheCowTest.php b/exercises/practice/save-the-cow/SaveTheCowTest.php new file mode 100644 index 000000000..e69de29bb From aabc4b0fe81d5e10174ffaa17c1b53a07c460082 Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Mon, 27 Jul 2026 08:21:50 +0200 Subject: [PATCH 2/6] Coded test and example --- .../practice/save-the-cow/.meta/example.php | 48 ++++++ .../practice/save-the-cow/SaveTheCow.php | 37 ++++ .../practice/save-the-cow/SaveTheCowTest.php | 162 ++++++++++++++++++ 3 files changed, 247 insertions(+) diff --git a/exercises/practice/save-the-cow/.meta/example.php b/exercises/practice/save-the-cow/.meta/example.php index e69de29bb..1ddebfdc1 100644 --- a/exercises/practice/save-the-cow/.meta/example.php +++ b/exercises/practice/save-the-cow/.meta/example.php @@ -0,0 +1,48 @@ +maskedWord = str_split(str_repeat("_", strlen($word))); + } + + public function guess(array $guesses): void + { + foreach ($guesses as $guess) { + if ($this->state === "Win") { + throw new Exception("cannot guess after the game is won"); + } else if ($this->state === "Lose") { + throw new Exception("cannot guess after the game is lost"); + } + + if (str_contains($this->word, $guess) && ! str_contains(implode("", $this->maskedWord), $guess)) { + for ($i = 0; $i < strlen($this->word); $i++) { + if ($this->word[$i] === $guess) { + $this->maskedWord[$i] = $guess; + } + } + if (! str_contains(implode("", $this->maskedWord), "_")) { + $this->state = "Win"; + } + } else { + if ($this->remainingFailures === 0) { + $this->state = "Lose"; + } else { + $this->remainingFailures--; + } + } + } + } + + public function maskedWord(): string + { + return implode("", $this->maskedWord); + } +} diff --git a/exercises/practice/save-the-cow/SaveTheCow.php b/exercises/practice/save-the-cow/SaveTheCow.php index e69de29bb..1bfa5b58e 100644 --- a/exercises/practice/save-the-cow/SaveTheCow.php +++ b/exercises/practice/save-the-cow/SaveTheCow.php @@ -0,0 +1,37 @@ +. + * + * To disable strict typing, comment out the directive below. + */ + +declare(strict_types=1); + +class SaveTheCow +{ + /** + * In PHP 8.4 and newer you can use Asymmetric Property Visibility to enhance data encapsulation + * @see https://www.php.net/manual/en/language.oop5.visibility.php#language.oop5.visibility-members-aviz + */ + public function __construct(string $word) + { + throw new \BadMethodCallException("Please implement the SaveTheCow class!"); + } +} diff --git a/exercises/practice/save-the-cow/SaveTheCowTest.php b/exercises/practice/save-the-cow/SaveTheCowTest.php index e69de29bb..299898d7f 100644 --- a/exercises/practice/save-the-cow/SaveTheCowTest.php +++ b/exercises/practice/save-the-cow/SaveTheCowTest.php @@ -0,0 +1,162 @@ +guess($guesses); + + $this->assertEquals("Ongoing", $saveTheCow->state); + $this->assertEquals("____", $saveTheCow->maskedWord()); + $this->assertEquals(9, $saveTheCow->remainingFailures); + } + + /** + * uuid: 76759c24-8f1a-4fc8-9ffd-d6a1ff0cf03b + */ + #[TestDox('After 10 failures the game is over')] + public function testAfterTenFailuresTheGameIsOver(): void + { + $guesses = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + $saveTheCow = new SaveTheCow("loot"); + $saveTheCow->guess($guesses); + + $this->assertEquals("Lose", $saveTheCow->state); + $this->assertEquals("____", $saveTheCow->maskedWord()); + $this->assertEquals(0, $saveTheCow->remainingFailures); + } + + /** + * uuid: d6f2e202-7857-46fb-b709-43a7f3f3b2de + */ + #[TestDox('Losing with several correct guesses')] + public function testLosingWithSeveralCorrectGuesses(): void + { + $guesses = ["t", "o", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + $saveTheCow = new SaveTheCow("loot"); + $saveTheCow->guess($guesses); + + $this->assertEquals("Lose", $saveTheCow->state); + $this->assertEquals("_oot", $saveTheCow->maskedWord()); + $this->assertEquals(0, $saveTheCow->remainingFailures); + } + + /** + * uuid: 71bc0cda-2032-4637-80c8-fc8771124c08 + */ + #[TestDox('Feeding a correct letter removes underscores')] + public function testFeedingACorrectLetterRemovesUnderscores(): void + { + $guesses = ["t"]; + $saveTheCow = new SaveTheCow("loot"); + $saveTheCow->guess($guesses); + + $this->assertEquals("Ongoing", $saveTheCow->state); + $this->assertEquals("___t", $saveTheCow->maskedWord()); + $this->assertEquals(9, $saveTheCow->remainingFailures); + } + + /** + * uuid: 5b568a1c-867d-418f-97a8-7b6f8a7ca0a2 + */ + #[TestDox('Feeding a correct letter twice counts as a failure')] + public function testFeedingACorrectLetterTwiceCountsAsAFailure(): void + { + $guesses = ["t", "t"]; + $saveTheCow = new SaveTheCow("loot"); + $saveTheCow->guess($guesses); + + $this->assertEquals("Ongoing", $saveTheCow->state); + $this->assertEquals("___t", $saveTheCow->maskedWord()); + $this->assertEquals(8, $saveTheCow->remainingFailures); + } + + /** + * uuid: 3d40f15b-0271-4c5d-b1a4-3e1f66ff221f + */ + #[TestDox('Guessing a repeated letter reveals all instances')] + public function testGuessingARepeatedLetterRevealsAllInstances(): void + { + $guesses = ["t", "t", "o"]; + $saveTheCow = new SaveTheCow("loot"); + $saveTheCow->guess($guesses); + + $this->assertEquals("Ongoing", $saveTheCow->state); + $this->assertEquals("_oot", $saveTheCow->maskedWord()); + $this->assertEquals(8, $saveTheCow->remainingFailures); + } + + /** + * uuid: 11a86435-e401-4250-a26e-3b0d8c4049ad + */ + #[TestDox('Getting all the letters right makes for a win')] + public function testGettingAllTheLettersRightMakesForAWin(): void + { + $guesses = ["t", "t", "o", "l"]; + $saveTheCow = new SaveTheCow("loot"); + $saveTheCow->guess($guesses); + + $this->assertEquals("Win", $saveTheCow->state); + $this->assertEquals("loot", $saveTheCow->maskedWord()); + $this->assertEquals(8, $saveTheCow->remainingFailures); + } + + /** + * uuid: b3d81876-84ee-45bb-b531-baa1b05b4709 + */ + #[TestDox('Winning on the last guess is still a win')] + public function testWinningOnTheLastGuessIsStillAWin(): void + { + $guesses = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "t", "o", "l"]; + $saveTheCow = new SaveTheCow("loot"); + $saveTheCow->guess($guesses); + + $this->assertEquals("Win", $saveTheCow->state); + $this->assertEquals("loot", $saveTheCow->maskedWord()); + $this->assertEquals(0, $saveTheCow->remainingFailures); + } + + /** + * uuid: cf204398-5e9f-402f-8bff-42cb7cbbbda9 + */ + #[TestDox('Guessing after a lose is error')] + public function testGuessingAfterALoseIsError(): void + { + $guesses = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]; + $saveTheCow = new SaveTheCow("loot"); + + $this->expectException(Exception::class); + $this->expectExceptionMessage('cannot guess after the game is lost'); + $saveTheCow->guess($guesses); + } + + /** + * uuid: c2ec5b3d-4923-4a0e-a485-6aa6e78c7ece + */ + #[TestDox('Guessing after a win is error')] + public function testGuessingAfterAWinIsError(): void + { + $guesses = ["t", "o", "l", "l"]; + $saveTheCow = new SaveTheCow("loot"); + + $this->expectException(Exception::class); + $this->expectExceptionMessage('cannot guess after the game is won'); + $saveTheCow->guess($guesses); + } +} From 87eb238e7c828c1b95807106071905d5a2a876da Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Sat, 12 Sep 2026 13:20:34 +0200 Subject: [PATCH 3/6] Set the difficulty rank to `3` --- config.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config.json b/config.json index 035719763..507b39ec4 100644 --- a/config.json +++ b/config.json @@ -977,6 +977,14 @@ "prerequisites": [], "difficulty": 3 }, + { + "slug": "save-the-cow", + "name": "Save the Cow", + "uuid": "ec60632c-c682-4f72-87a7-8601c960165b", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "bob", "name": "Bob", @@ -1386,14 +1394,6 @@ "practices": [], "prerequisites": [], "difficulty": 7 - }, - { - "slug": "save-the-cow", - "name": "Save the Cow", - "uuid": "ec60632c-c682-4f72-87a7-8601c960165b", - "practices": [], - "prerequisites": [], - "difficulty": 1 } ], "foregone": [ From 59d89bbf32bb93b9941c4ce73091144814317caa Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Sat, 12 Sep 2026 13:22:08 +0200 Subject: [PATCH 4/6] Added GitHub handle to `config.json` --- exercises/practice/save-the-cow/.meta/config.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exercises/practice/save-the-cow/.meta/config.json b/exercises/practice/save-the-cow/.meta/config.json index 251a749a1..6bf9600cc 100644 --- a/exercises/practice/save-the-cow/.meta/config.json +++ b/exercises/practice/save-the-cow/.meta/config.json @@ -1,5 +1,7 @@ { - "authors": [], + "authors": [ + "resu-xuniL" + ], "files": { "solution": [ "SaveTheCow.php" From 8215fefa771bcb921c940c31d806e772e362d8dc Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Sat, 12 Sep 2026 18:47:24 +0200 Subject: [PATCH 5/6] simplifying the code --- .../practice/save-the-cow/.meta/example.php | 13 ++++--------- .../practice/save-the-cow/SaveTheCowTest.php | 16 ++++++++-------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/exercises/practice/save-the-cow/.meta/example.php b/exercises/practice/save-the-cow/.meta/example.php index 1ddebfdc1..38d2b1591 100644 --- a/exercises/practice/save-the-cow/.meta/example.php +++ b/exercises/practice/save-the-cow/.meta/example.php @@ -6,11 +6,11 @@ class SaveTheCow { public function __construct( private string $word, - private array $maskedWord = [], + public string $maskedWord = "", public string $state = "Ongoing", public int $remainingFailures = 9 ) { - $this->maskedWord = str_split(str_repeat("_", strlen($word))); + $this->maskedWord = str_repeat("_", strlen($word)); } public function guess(array $guesses): void @@ -22,13 +22,13 @@ public function guess(array $guesses): void throw new Exception("cannot guess after the game is lost"); } - if (str_contains($this->word, $guess) && ! str_contains(implode("", $this->maskedWord), $guess)) { + if (str_contains($this->word, $guess) && ! str_contains($this->maskedWord, $guess)) { for ($i = 0; $i < strlen($this->word); $i++) { if ($this->word[$i] === $guess) { $this->maskedWord[$i] = $guess; } } - if (! str_contains(implode("", $this->maskedWord), "_")) { + if (! str_contains($this->maskedWord, "_")) { $this->state = "Win"; } } else { @@ -40,9 +40,4 @@ public function guess(array $guesses): void } } } - - public function maskedWord(): string - { - return implode("", $this->maskedWord); - } } diff --git a/exercises/practice/save-the-cow/SaveTheCowTest.php b/exercises/practice/save-the-cow/SaveTheCowTest.php index 299898d7f..c2084a106 100644 --- a/exercises/practice/save-the-cow/SaveTheCowTest.php +++ b/exercises/practice/save-the-cow/SaveTheCowTest.php @@ -23,7 +23,7 @@ public function testInitiallyNineFailuresAreAllowedAndNoLettersAreGuessed(): voi $saveTheCow->guess($guesses); $this->assertEquals("Ongoing", $saveTheCow->state); - $this->assertEquals("____", $saveTheCow->maskedWord()); + $this->assertEquals("____", $saveTheCow->maskedWord); $this->assertEquals(9, $saveTheCow->remainingFailures); } @@ -38,7 +38,7 @@ public function testAfterTenFailuresTheGameIsOver(): void $saveTheCow->guess($guesses); $this->assertEquals("Lose", $saveTheCow->state); - $this->assertEquals("____", $saveTheCow->maskedWord()); + $this->assertEquals("____", $saveTheCow->maskedWord); $this->assertEquals(0, $saveTheCow->remainingFailures); } @@ -53,7 +53,7 @@ public function testLosingWithSeveralCorrectGuesses(): void $saveTheCow->guess($guesses); $this->assertEquals("Lose", $saveTheCow->state); - $this->assertEquals("_oot", $saveTheCow->maskedWord()); + $this->assertEquals("_oot", $saveTheCow->maskedWord); $this->assertEquals(0, $saveTheCow->remainingFailures); } @@ -68,7 +68,7 @@ public function testFeedingACorrectLetterRemovesUnderscores(): void $saveTheCow->guess($guesses); $this->assertEquals("Ongoing", $saveTheCow->state); - $this->assertEquals("___t", $saveTheCow->maskedWord()); + $this->assertEquals("___t", $saveTheCow->maskedWord); $this->assertEquals(9, $saveTheCow->remainingFailures); } @@ -83,7 +83,7 @@ public function testFeedingACorrectLetterTwiceCountsAsAFailure(): void $saveTheCow->guess($guesses); $this->assertEquals("Ongoing", $saveTheCow->state); - $this->assertEquals("___t", $saveTheCow->maskedWord()); + $this->assertEquals("___t", $saveTheCow->maskedWord); $this->assertEquals(8, $saveTheCow->remainingFailures); } @@ -98,7 +98,7 @@ public function testGuessingARepeatedLetterRevealsAllInstances(): void $saveTheCow->guess($guesses); $this->assertEquals("Ongoing", $saveTheCow->state); - $this->assertEquals("_oot", $saveTheCow->maskedWord()); + $this->assertEquals("_oot", $saveTheCow->maskedWord); $this->assertEquals(8, $saveTheCow->remainingFailures); } @@ -113,7 +113,7 @@ public function testGettingAllTheLettersRightMakesForAWin(): void $saveTheCow->guess($guesses); $this->assertEquals("Win", $saveTheCow->state); - $this->assertEquals("loot", $saveTheCow->maskedWord()); + $this->assertEquals("loot", $saveTheCow->maskedWord); $this->assertEquals(8, $saveTheCow->remainingFailures); } @@ -128,7 +128,7 @@ public function testWinningOnTheLastGuessIsStillAWin(): void $saveTheCow->guess($guesses); $this->assertEquals("Win", $saveTheCow->state); - $this->assertEquals("loot", $saveTheCow->maskedWord()); + $this->assertEquals("loot", $saveTheCow->maskedWord); $this->assertEquals(0, $saveTheCow->remainingFailures); } From 2a9a4724583ebaf7dcd5fef26ccfc0881ba6e803 Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Sun, 13 Sep 2026 15:33:21 +0200 Subject: [PATCH 6/6] Apply `mk-mxp` suggestions --- config.json | 16 ++++---- .../practice/save-the-cow/.meta/example.php | 38 +++++++++--------- .../practice/save-the-cow/SaveTheCowTest.php | 40 ++++++++++++++----- 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/config.json b/config.json index 507b39ec4..aeba2635c 100644 --- a/config.json +++ b/config.json @@ -977,14 +977,6 @@ "prerequisites": [], "difficulty": 3 }, - { - "slug": "save-the-cow", - "name": "Save the Cow", - "uuid": "ec60632c-c682-4f72-87a7-8601c960165b", - "practices": [], - "prerequisites": [], - "difficulty": 3 - }, { "slug": "bob", "name": "Bob", @@ -1113,6 +1105,14 @@ "transforming" ] }, + { + "slug": "save-the-cow", + "name": "Save the Cow", + "uuid": "ec60632c-c682-4f72-87a7-8601c960165b", + "practices": [], + "prerequisites": [], + "difficulty": 4 + }, { "slug": "scale-generator", "name": "Scale Generator", diff --git a/exercises/practice/save-the-cow/.meta/example.php b/exercises/practice/save-the-cow/.meta/example.php index 38d2b1591..a9a06b0f5 100644 --- a/exercises/practice/save-the-cow/.meta/example.php +++ b/exercises/practice/save-the-cow/.meta/example.php @@ -13,30 +13,28 @@ public function __construct( $this->maskedWord = str_repeat("_", strlen($word)); } - public function guess(array $guesses): void + public function guess(string $guess): void { - foreach ($guesses as $guess) { - if ($this->state === "Win") { - throw new Exception("cannot guess after the game is won"); - } else if ($this->state === "Lose") { - throw new Exception("cannot guess after the game is lost"); - } + if ($this->state === "Win") { + throw new Exception("cannot guess after the game is won"); + } else if ($this->state === "Lose") { + throw new Exception("cannot guess after the game is lost"); + } - if (str_contains($this->word, $guess) && ! str_contains($this->maskedWord, $guess)) { - for ($i = 0; $i < strlen($this->word); $i++) { - if ($this->word[$i] === $guess) { - $this->maskedWord[$i] = $guess; - } - } - if (! str_contains($this->maskedWord, "_")) { - $this->state = "Win"; + if (str_contains($this->word, $guess) && ! str_contains($this->maskedWord, $guess)) { + for ($i = 0; $i < strlen($this->word); $i++) { + if ($this->word[$i] === $guess) { + $this->maskedWord[$i] = $guess; } + } + if (! str_contains($this->maskedWord, "_")) { + $this->state = "Win"; + } + } else { + if ($this->remainingFailures === 0) { + $this->state = "Lose"; } else { - if ($this->remainingFailures === 0) { - $this->state = "Lose"; - } else { - $this->remainingFailures--; - } + $this->remainingFailures--; } } } diff --git a/exercises/practice/save-the-cow/SaveTheCowTest.php b/exercises/practice/save-the-cow/SaveTheCowTest.php index c2084a106..3d98ae5a6 100644 --- a/exercises/practice/save-the-cow/SaveTheCowTest.php +++ b/exercises/practice/save-the-cow/SaveTheCowTest.php @@ -20,7 +20,9 @@ public function testInitiallyNineFailuresAreAllowedAndNoLettersAreGuessed(): voi { $guesses = []; $saveTheCow = new SaveTheCow("loot"); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } $this->assertEquals("Ongoing", $saveTheCow->state); $this->assertEquals("____", $saveTheCow->maskedWord); @@ -35,7 +37,9 @@ public function testAfterTenFailuresTheGameIsOver(): void { $guesses = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; $saveTheCow = new SaveTheCow("loot"); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } $this->assertEquals("Lose", $saveTheCow->state); $this->assertEquals("____", $saveTheCow->maskedWord); @@ -50,7 +54,9 @@ public function testLosingWithSeveralCorrectGuesses(): void { $guesses = ["t", "o", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; $saveTheCow = new SaveTheCow("loot"); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } $this->assertEquals("Lose", $saveTheCow->state); $this->assertEquals("_oot", $saveTheCow->maskedWord); @@ -65,7 +71,9 @@ public function testFeedingACorrectLetterRemovesUnderscores(): void { $guesses = ["t"]; $saveTheCow = new SaveTheCow("loot"); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } $this->assertEquals("Ongoing", $saveTheCow->state); $this->assertEquals("___t", $saveTheCow->maskedWord); @@ -80,7 +88,9 @@ public function testFeedingACorrectLetterTwiceCountsAsAFailure(): void { $guesses = ["t", "t"]; $saveTheCow = new SaveTheCow("loot"); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } $this->assertEquals("Ongoing", $saveTheCow->state); $this->assertEquals("___t", $saveTheCow->maskedWord); @@ -95,7 +105,9 @@ public function testGuessingARepeatedLetterRevealsAllInstances(): void { $guesses = ["t", "t", "o"]; $saveTheCow = new SaveTheCow("loot"); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } $this->assertEquals("Ongoing", $saveTheCow->state); $this->assertEquals("_oot", $saveTheCow->maskedWord); @@ -110,7 +122,9 @@ public function testGettingAllTheLettersRightMakesForAWin(): void { $guesses = ["t", "t", "o", "l"]; $saveTheCow = new SaveTheCow("loot"); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } $this->assertEquals("Win", $saveTheCow->state); $this->assertEquals("loot", $saveTheCow->maskedWord); @@ -125,7 +139,9 @@ public function testWinningOnTheLastGuessIsStillAWin(): void { $guesses = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "t", "o", "l"]; $saveTheCow = new SaveTheCow("loot"); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } $this->assertEquals("Win", $saveTheCow->state); $this->assertEquals("loot", $saveTheCow->maskedWord); @@ -143,7 +159,9 @@ public function testGuessingAfterALoseIsError(): void $this->expectException(Exception::class); $this->expectExceptionMessage('cannot guess after the game is lost'); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } } /** @@ -157,6 +175,8 @@ public function testGuessingAfterAWinIsError(): void $this->expectException(Exception::class); $this->expectExceptionMessage('cannot guess after the game is won'); - $saveTheCow->guess($guesses); + foreach ($guesses as $guess) { + $saveTheCow->guess($guess); + } } }