From 7f6cea9bf22995abd42f073582ff6ccd02b0e7dc Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Wed, 15 Jul 2026 14:03:12 +0200 Subject: [PATCH 1/5] Inlined object instantiation in `RobotNameTest` --- .../practice/robot-name/RobotNameTest.php | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/exercises/practice/robot-name/RobotNameTest.php b/exercises/practice/robot-name/RobotNameTest.php index ea17d738e..b1278c87c 100644 --- a/exercises/practice/robot-name/RobotNameTest.php +++ b/exercises/practice/robot-name/RobotNameTest.php @@ -11,42 +11,38 @@ public static function setUpBeforeClass(): void require_once 'RobotName.php'; } - /** @var Robot $robot */ - protected $robot = null; - - public function setUp(): void - { - $this->robot = new Robot(); - } - public function testHasName(): void { - $this->assertMatchesRegularExpression('/^[a-z]{2}\d{3}$/i', $this->robot->getName()); + $robot = new Robot(); + $this->assertMatchesRegularExpression('/^[a-z]{2}\d{3}$/i', $robot->getName()); } public function testNameSticks(): void { - $old = $this->robot->getName(); + $robot = new Robot(); + $old = $robot->getName(); - $this->assertSame($this->robot->getName(), $old); + $this->assertSame($robot->getName(), $old); } public function testDifferentRobotsHaveDifferentNames(): void { + $robot = new Robot(); $other_bot = new Robot(); - $this->assertNotSame($other_bot->getName(), $this->robot->getName()); + $this->assertNotSame($other_bot->getName(), $robot->getName()); unset($other_bot); } public function testResetName(): void { - $name1 = $this->robot->getName(); + $robot = new Robot(); + $name1 = $robot->getName(); - $this->robot->reset(); + $robot->reset(); - $name2 = $this->robot->getName(); + $name2 = $robot->getName(); $this->assertNotSame($name1, $name2); @@ -55,19 +51,21 @@ public function testResetName(): void public function testNamesArentRecycled(): void { + $robot = new Robot(); $names = []; for ($i = 0; $i < 10000; $i++) { - $name = $this->robot->getName(); + $name = $robot->getName(); $this->assertArrayNotHasKey($name, $names, sprintf('Name %s reissued after Reset.', $name)); $names[$name] = true; - $this->robot->reset(); + $robot->reset(); } } // This test is optional. public function testNameUniquenessManyRobots(): void { + $robot = new Robot(); $names = []; for ($i = 0; $i < 10000; $i++) { From c4eb74aa6120856252386f78d8c990c9745f8126 Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Wed, 15 Jul 2026 14:04:32 +0200 Subject: [PATCH 2/5] Inlined object instantiation in `SecretHandshakeTest` --- .../secret-handshake/SecretHandshakeTest.php | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/exercises/practice/secret-handshake/SecretHandshakeTest.php b/exercises/practice/secret-handshake/SecretHandshakeTest.php index 01ebaf90f..85f1b43f6 100644 --- a/exercises/practice/secret-handshake/SecretHandshakeTest.php +++ b/exercises/practice/secret-handshake/SecretHandshakeTest.php @@ -7,25 +7,19 @@ class SecretHandshakeTest extends TestCase { - private SecretHandshake $secretHandshake; - public static function setUpBeforeClass(): void { require_once 'SecretHandshake.php'; } - public function setUp(): void - { - $this->secretHandshake = new SecretHandshake(); - } - /** * uuid: b8496fbd-6778-468c-8054-648d03c4bb23 */ #[TestDox('Wink for 1')] public function testWinkForOne(): void { - $this->assertEquals(['wink'], $this->secretHandshake->commands(1)); + $secretHandshake = new SecretHandshake(); + $this->assertEquals(['wink'], $secretHandshake->commands(1)); } /** @@ -34,7 +28,8 @@ public function testWinkForOne(): void #[TestDox('Double blink for 10')] public function testDoubleBlinkForTen(): void { - $this->assertEquals(['double blink'], $this->secretHandshake->commands(0b0_0010)); + $secretHandshake = new SecretHandshake(); + $this->assertEquals(['double blink'], $secretHandshake->commands(0b0_0010)); } /** @@ -43,7 +38,8 @@ public function testDoubleBlinkForTen(): void #[TestDox('Close your eyes for 100')] public function testCloseYourEyesForHundred(): void { - $this->assertEquals(['close your eyes'], $this->secretHandshake->commands(0b100)); + $secretHandshake = new SecretHandshake(); + $this->assertEquals(['close your eyes'], $secretHandshake->commands(0b100)); } /** @@ -52,7 +48,8 @@ public function testCloseYourEyesForHundred(): void #[TestDox('Jump for 1000')] public function testJumpForThousand(): void { - $this->assertEquals(['jump'], $this->secretHandshake->commands(8)); + $secretHandshake = new SecretHandshake(); + $this->assertEquals(['jump'], $secretHandshake->commands(8)); } /** @@ -61,7 +58,8 @@ public function testJumpForThousand(): void #[TestDox('Combine two actions')] public function testCombineTwoActions(): void { - $this->assertEquals(['wink', 'double blink'], $this->secretHandshake->commands(3)); + $secretHandshake = new SecretHandshake(); + $this->assertEquals(['wink', 'double blink'], $secretHandshake->commands(3)); } /** @@ -70,7 +68,8 @@ public function testCombineTwoActions(): void #[TestDox('Reverse two actions')] public function testReverseTwoActions(): void { - $this->assertEquals(['double blink', 'wink'], $this->secretHandshake->commands(0b10011)); + $secretHandshake = new SecretHandshake(); + $this->assertEquals(['double blink', 'wink'], $secretHandshake->commands(0b10011)); } /** @@ -79,7 +78,8 @@ public function testReverseTwoActions(): void #[TestDox('Reversing one action gives the same action')] public function testReversingOneActionGivesTheSameAction(): void { - $this->assertEquals(['jump'], $this->secretHandshake->commands(24)); + $secretHandshake = new SecretHandshake(); + $this->assertEquals(['jump'], $secretHandshake->commands(24)); } /** @@ -88,7 +88,8 @@ public function testReversingOneActionGivesTheSameAction(): void #[TestDox('Reversing no actions still gives no actions')] public function testReversingNoActionsStillGivesNoActions(): void { - $this->assertEquals([], $this->secretHandshake->commands(16)); + $secretHandshake = new SecretHandshake(); + $this->assertEquals([], $secretHandshake->commands(16)); } /** @@ -97,9 +98,10 @@ public function testReversingNoActionsStillGivesNoActions(): void #[TestDox('All possible actions')] public function testAllPossibleActions(): void { + $secretHandshake = new SecretHandshake(); $this->assertEquals( ['wink', 'double blink', 'close your eyes', 'jump'], - $this->secretHandshake->commands(15) + $secretHandshake->commands(15) ); } @@ -109,9 +111,10 @@ public function testAllPossibleActions(): void #[TestDox('Reverse all possible actions')] public function testReverseAllPossibleActions(): void { + $secretHandshake = new SecretHandshake(); $this->assertEquals( ['jump', 'close your eyes', 'double blink', 'wink'], - $this->secretHandshake->commands(31) + $secretHandshake->commands(31) ); } @@ -121,6 +124,7 @@ public function testReverseAllPossibleActions(): void #[TestDox('Do nothing for zero')] public function testDoNothingForZero(): void { - $this->assertEquals([], $this->secretHandshake->commands(0b0)); + $secretHandshake = new SecretHandshake(); + $this->assertEquals([], $secretHandshake->commands(0b0)); } } From 1dba1482226435fcc73e51b09da0ecdfca7da5a2 Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Wed, 15 Jul 2026 14:07:15 +0200 Subject: [PATCH 3/5] Inlined object instantiation in `SpiralMatrixTest` --- .../spiral-matrix/SpiralMatrixTest.php | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/exercises/practice/spiral-matrix/SpiralMatrixTest.php b/exercises/practice/spiral-matrix/SpiralMatrixTest.php index bb231f348..e761916da 100644 --- a/exercises/practice/spiral-matrix/SpiralMatrixTest.php +++ b/exercises/practice/spiral-matrix/SpiralMatrixTest.php @@ -7,26 +7,20 @@ class SpiralMatrixTest extends TestCase { - private SpiralMatrix $spiralMatrix; - public static function setUpBeforeClass(): void { require_once 'SpiralMatrix.php'; } - public function setUp(): void - { - $this->spiralMatrix = new SpiralMatrix(); - } - /** * uuid: 8f584201-b446-4bc9-b132-811c8edd9040 */ #[TestDox('Empty spiral')] public function testEmptySpiral(): void { + $spiralMatrix = new SpiralMatrix(); $expected = []; - $actual = $this->spiralMatrix->draw(0); + $actual = $spiralMatrix->draw(0); $this->assertEquals($expected, $actual); } @@ -36,8 +30,9 @@ public function testEmptySpiral(): void #[TestDox('Trivial spiral')] public function testTrivialSpiral(): void { + $spiralMatrix = new SpiralMatrix(); $expected = [[1]]; - $actual = $this->spiralMatrix->draw(1); + $actual = $spiralMatrix->draw(1); $this->assertEquals($expected, $actual); } @@ -47,11 +42,12 @@ public function testTrivialSpiral(): void #[TestDox('Spiral of size 2')] public function testSpiralOfSize2(): void { + $spiralMatrix = new SpiralMatrix(); $expected = [ [1, 2], [4, 3], ]; - $actual = $this->spiralMatrix->draw(2); + $actual = $spiralMatrix->draw(2); $this->assertEquals($expected, $actual); } @@ -61,12 +57,13 @@ public function testSpiralOfSize2(): void #[TestDox('Spiral of size 3')] public function testSpiralOfSize3(): void { + $spiralMatrix = new SpiralMatrix(); $expected = [ [1, 2, 3], [8, 9, 4], [7, 6, 5], ]; - $actual = $this->spiralMatrix->draw(3); + $actual = $spiralMatrix->draw(3); $this->assertEquals($expected, $actual); } @@ -76,13 +73,14 @@ public function testSpiralOfSize3(): void #[TestDox('Spiral of size 4')] public function testSpiralOfSize4(): void { + $spiralMatrix = new SpiralMatrix(); $expected = [ [1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7], ]; - $actual = $this->spiralMatrix->draw(4); + $actual = $spiralMatrix->draw(4); $this->assertEquals($expected, $actual); } @@ -92,6 +90,7 @@ public function testSpiralOfSize4(): void #[TestDox('Spiral of size 5')] public function testSpiralOfSize5(): void { + $spiralMatrix = new SpiralMatrix(); $expected = [ [1, 2, 3, 4, 5], [16, 17, 18, 19, 6], @@ -99,7 +98,7 @@ public function testSpiralOfSize5(): void [14, 23, 22, 21, 8], [13, 12, 11, 10, 9], ]; - $actual = $this->spiralMatrix->draw(5); + $actual = $spiralMatrix->draw(5); $this->assertEquals($expected, $actual); } } From f21eb04d944fe0b4b5ebad720d1906f8ae0db25a Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Wed, 15 Jul 2026 14:09:18 +0200 Subject: [PATCH 4/5] Inlined object instantiation in `StrainTest` --- exercises/practice/strain/StrainTest.php | 49 ++++++++++++++---------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/exercises/practice/strain/StrainTest.php b/exercises/practice/strain/StrainTest.php index df53ba182..3af181a1f 100644 --- a/exercises/practice/strain/StrainTest.php +++ b/exercises/practice/strain/StrainTest.php @@ -7,30 +7,24 @@ class StrainTest extends TestCase { - private Strain $strain; - public static function setUpBeforeClass(): void { require_once 'Strain.php'; } - public function setUp(): void - { - $this->strain = new Strain(); - } - /** * uuid: 26af8c32-ba6a-4eb3-aa0a-ebd8f136e003 */ #[TestDox('Keep on empty list returns empty list')] public function testKeepOnEmptyListReturnsEmptyList(): void { + $strain = new Strain(); $list = []; $predicate = function ($x) { return true; }; - $this->assertEquals([], $this->strain->keep($list, $predicate)); + $this->assertEquals([], $strain->keep($list, $predicate)); } /** @@ -39,12 +33,13 @@ public function testKeepOnEmptyListReturnsEmptyList(): void #[TestDox('Keeps everything')] public function testKeepsEverything(): void { + $strain = new Strain(); $list = [1, 3, 5]; $predicate = function ($x) { return true; }; - $this->assertEquals([1, 3, 5], $this->strain->keep($list, $predicate)); + $this->assertEquals([1, 3, 5], $strain->keep($list, $predicate)); } /** @@ -53,12 +48,13 @@ public function testKeepsEverything(): void #[TestDox('Keeps nothing')] public function testKeepNothing(): void { + $strain = new Strain(); $list = [1, 3, 5]; $predicate = function ($x) { return false; }; - $this->assertEquals([], $this->strain->keep($list, $predicate)); + $this->assertEquals([], $strain->keep($list, $predicate)); } /** @@ -67,12 +63,13 @@ public function testKeepNothing(): void #[TestDox('Keeps first and last')] public function testKeepFirstAndLast(): void { + $strain = new Strain(); $list = [1, 2, 3]; $predicate = function ($x) { return $x % 2 === 1; }; - $this->assertEquals([1, 3], $this->strain->keep($list, $predicate)); + $this->assertEquals([1, 3], $strain->keep($list, $predicate)); } /** @@ -81,12 +78,13 @@ public function testKeepFirstAndLast(): void #[TestDox('Keeps neither first nor last')] public function testKeepNeitherFirstNorLast(): void { + $strain = new Strain(); $list = [1, 2, 3]; $predicate = function ($x) { return $x % 2 === 0; }; - $this->assertEquals([2], $this->strain->keep($list, $predicate)); + $this->assertEquals([2], $strain->keep($list, $predicate)); } /** @@ -95,12 +93,13 @@ public function testKeepNeitherFirstNorLast(): void #[TestDox('Keeps strings')] public function testKeepStrings(): void { + $strain = new Strain(); $list = ["apple", "zebra", "banana", "zombies", "cherimoya", "zealot"]; $predicate = function ($x) { return str_starts_with($x, 'z'); }; - $this->assertEquals(["zebra", "zombies", "zealot"], $this->strain->keep($list, $predicate)); + $this->assertEquals(["zebra", "zombies", "zealot"], $strain->keep($list, $predicate)); } /** @@ -109,6 +108,7 @@ public function testKeepStrings(): void #[TestDox('Keeps lists')] public function testKeepsLists(): void { + $strain = new Strain(); $list = [ [1, 2, 3], [5, 5, 5], @@ -129,7 +129,7 @@ public function testKeepsLists(): void [1, 2, 5] ]; - $this->assertEquals($expected, $this->strain->keep($list, $predicate)); + $this->assertEquals($expected, $strain->keep($list, $predicate)); } /** @@ -138,12 +138,13 @@ public function testKeepsLists(): void #[TestDox('Discard on empty list returns empty list')] public function testDiscardOnEmptyListReturnsEmptyList(): void { + $strain = new Strain(); $list = []; $predicate = function ($x) { return true; }; - $this->assertEquals([], $this->strain->discard($list, $predicate)); + $this->assertEquals([], $strain->discard($list, $predicate)); } /** @@ -152,12 +153,13 @@ public function testDiscardOnEmptyListReturnsEmptyList(): void #[TestDox('Discards everything')] public function testDiscardEverything(): void { + $strain = new Strain(); $list = [1, 3, 5]; $predicate = function ($x) { return true; }; - $this->assertEquals([], $this->strain->discard($list, $predicate)); + $this->assertEquals([], $strain->discard($list, $predicate)); } /** @@ -166,12 +168,13 @@ public function testDiscardEverything(): void #[TestDox('Discards nothing')] public function testDiscardNothing(): void { + $strain = new Strain(); $list = [1, 3, 5]; $predicate = function ($x) { return false; }; - $this->assertEquals([1, 3, 5], $this->strain->discard($list, $predicate)); + $this->assertEquals([1, 3, 5], $strain->discard($list, $predicate)); } /** @@ -180,12 +183,13 @@ public function testDiscardNothing(): void #[TestDox('Discards first and last')] public function testDiscardFirstAndLast(): void { + $strain = new Strain(); $list = [1, 2, 3]; $predicate = function ($x) { return $x % 2 === 1; }; - $this->assertEquals([2], $this->strain->discard($list, $predicate)); + $this->assertEquals([2], $strain->discard($list, $predicate)); } /** @@ -194,12 +198,13 @@ public function testDiscardFirstAndLast(): void #[TestDox('Discards neither first nor last')] public function testDiscardNeitherFirstNorLast(): void { + $strain = new Strain(); $list = [1, 2, 3]; $predicate = function ($x) { return $x % 2 === 0; }; - $this->assertEquals([1,3], $this->strain->discard($list, $predicate)); + $this->assertEquals([1,3], $strain->discard($list, $predicate)); } /** @@ -208,12 +213,13 @@ public function testDiscardNeitherFirstNorLast(): void #[TestDox('Discards strings')] public function testDiscardStrings(): void { + $strain = new Strain(); $list = ["apple", "zebra", "banana", "zombies", "cherimoya", "zealot"]; $predicate = function ($x) { return str_starts_with($x, 'z'); }; - $this->assertEquals(["apple", "banana", "cherimoya"], $this->strain->discard($list, $predicate)); + $this->assertEquals(["apple", "banana", "cherimoya"], $strain->discard($list, $predicate)); } /** @@ -222,6 +228,7 @@ public function testDiscardStrings(): void #[TestDox('Discards lists')] public function testDiscardLists(): void { + $strain = new Strain(); $list = [ [1, 2, 3], [5, 5, 5], @@ -241,6 +248,6 @@ public function testDiscardLists(): void [2, 2, 1] ]; - $this->assertEquals($expected, $this->strain->discard($list, $predicate)); + $this->assertEquals($expected, $strain->discard($list, $predicate)); } } From ca983f9e59862c283aa02d3a2a13637c7b129e12 Mon Sep 17 00:00:00 2001 From: resu-xuniL Date: Wed, 15 Jul 2026 14:10:13 +0200 Subject: [PATCH 5/5] Add github handle --- exercises/practice/robot-name/.meta/config.json | 3 ++- exercises/practice/secret-handshake/.meta/config.json | 3 +++ exercises/practice/spiral-matrix/.meta/config.json | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/exercises/practice/robot-name/.meta/config.json b/exercises/practice/robot-name/.meta/config.json index 2d550eb0b..f51505d2c 100644 --- a/exercises/practice/robot-name/.meta/config.json +++ b/exercises/practice/robot-name/.meta/config.json @@ -12,7 +12,8 @@ "masters3d", "petemcfarlane", "schorsch3000", - "hazeolation" + "hazeolation", + "resu-xuniL" ], "files": { "solution": [ diff --git a/exercises/practice/secret-handshake/.meta/config.json b/exercises/practice/secret-handshake/.meta/config.json index a826a7d39..9134649da 100644 --- a/exercises/practice/secret-handshake/.meta/config.json +++ b/exercises/practice/secret-handshake/.meta/config.json @@ -2,6 +2,9 @@ "authors": [ "tomasnorre" ], + "contributors": [ + "resu-xuniL" + ], "files": { "solution": [ "SecretHandshake.php" diff --git a/exercises/practice/spiral-matrix/.meta/config.json b/exercises/practice/spiral-matrix/.meta/config.json index 4d48ccaa0..67c549f0b 100644 --- a/exercises/practice/spiral-matrix/.meta/config.json +++ b/exercises/practice/spiral-matrix/.meta/config.json @@ -2,6 +2,9 @@ "authors": [ "tomasnorre" ], + "contributors": [ + "resu-xuniL" + ], "files": { "solution": [ "SpiralMatrix.php"