From f3a86f52bf2121eb031d476449ddc3315aa3746f Mon Sep 17 00:00:00 2001 From: Domuriko Date: Tue, 26 May 2026 22:25:50 +0200 Subject: [PATCH 01/17] Sync word-count --- bin/auto-sync.txt | 1 + .../practice/word-count/.meta/config.json | 3 +- .../practice/word-count/.meta/example.php | 22 --- .../practice/word-count/.meta/tests.toml | 12 +- .../practice/word-count/WordCountTest.php | 139 ++++++++++++++---- 5 files changed, 118 insertions(+), 59 deletions(-) diff --git a/bin/auto-sync.txt b/bin/auto-sync.txt index 262964b06..c84475c1f 100644 --- a/bin/auto-sync.txt +++ b/bin/auto-sync.txt @@ -81,5 +81,6 @@ sublist two-bucket two-fer wordy +word-count yacht zebra-puzzle diff --git a/exercises/practice/word-count/.meta/config.json b/exercises/practice/word-count/.meta/config.json index 7f04db3ad..deb82c070 100644 --- a/exercises/practice/word-count/.meta/config.json +++ b/exercises/practice/word-count/.meta/config.json @@ -6,7 +6,8 @@ "arueckauer", "kunicmarko20", "kytrinyx", - "petemcfarlane" + "petemcfarlane", + "hazeolation" ], "files": { "solution": [ diff --git a/exercises/practice/word-count/.meta/example.php b/exercises/practice/word-count/.meta/example.php index 0282ae35f..ef4133bd0 100644 --- a/exercises/practice/word-count/.meta/example.php +++ b/exercises/practice/word-count/.meta/example.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); function wordCount($phrase) diff --git a/exercises/practice/word-count/.meta/tests.toml b/exercises/practice/word-count/.meta/tests.toml index b00c20ae0..fbce5847e 100644 --- a/exercises/practice/word-count/.meta/tests.toml +++ b/exercises/practice/word-count/.meta/tests.toml @@ -1,7 +1,3 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. - [61559d5f-2cad-48fb-af53-d3973a9ee9ef] description = "count one word" @@ -28,6 +24,11 @@ description = "normalize case" [4185a902-bdb0-4074-864c-f416e42a0f19] description = "with apostrophes" +include = false + +[4ff6c7d7-fcfc-43ef-b8e7-34ff1837a2d3] +description = "with apostrophes" +reimplements = "4185a902-bdb0-4074-864c-f416e42a0f19" [be72af2b-8afe-4337-b151-b297202e4a7b] description = "with quotations" @@ -40,3 +41,6 @@ description = "multiple spaces not detected as a word" [50176e8a-fe8e-4f4c-b6b6-aa9cf8f20360] description = "alternating word separators not detected as a word" + +[6d00f1db-901c-4bec-9829-d20eb3044557] +description = "quotation for word with apostrophe" diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index ff41993b4..f99f2fc32 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); use PHPUnit\Framework\TestCase; @@ -33,59 +11,156 @@ public static function setUpBeforeClass(): void require_once 'WordCount.php'; } + /** + * UUID 61559d5f-2cad-48fb-af53-d3973a9ee9ef + */ + #[TestDox('count one word')] public function testCountOneWord(): void { $this->assertEquals(['word' => 1], wordCount('word')); } + /** + * UUID 5abd53a3-1aed-43a4-a15a-29f88c09cbbd + */ + #[TestDox('count one of each word')] public function testCountOneOfEachWord(): void { $this->assertEquals(['one' => 1, 'of' => 1, 'each' => 1], wordCount('one of each')); } + /** + * UUID 2a3091e5-952e-4099-9fac-8f85d9655c0e + */ + #[TestDox('multiple occurrences of a word')] public function testMultipleOccurrencesOfAWord(): void + { + $this->assertEquals(['one' => 1, 'fish' => 4, 'two' => 1, 'red' => 1, 'blue' => 1], wordCount('one fish two fish red fish blue fish')); + } + + /** + * UUID e81877ae-d4da-4af4-931c-d923cd621ca6 + */ + #[TestDox('handles cramped lists')] + public function testHandlesCrampedLists(): void + { + $this->assertEquals(['one' => 1, 'two' => 1, 'three' => 1], wordCount('one,two,three')); + } + + /** + * UUID 7349f682-9707-47c0-a9af-be56e1e7ff30 + */ + #[TestDox('handles expanded lists')] + public function testHandlesExpandedLists(): void { $this->assertEquals( - ['one' => 1, 'fish' => 4, 'two' => 1, 'red' => 1, 'blue' => 1], - wordCount('one fish two fish red fish blue fish') + ['one' => 1, 'two' => 1, 'three' => 1], + wordCount('one, two, three') ); } + /** + * UUID a514a0f2-8589-4279-8892-887f76a14c82 + */ + #[TestDox('ignore punctuation')] public function testIgnorePunctuation(): void { - $this->assertEquals( - ['car' => 1, 'carpet' => 1, 'as' => 1, 'java' => 1, 'javascript' => 1], - wordCount('car : carpet as java : javascript!!&@$%^&') - ); + $this->assertEquals(['car' => 1, 'carpet' => 1, 'as' => 1, 'java' => 1, 'javascript' => 1], wordCount('car : carpet as java : javascript!!&@$%^&')); } + /** + * UUID d2e5cee6-d2ec-497b-bdc9-3ebe092ce55e + */ + #[TestDox('include numbers')] public function testIncludeNumbers(): void { $this->assertEquals(['1' => 1, '2' => 1, 'testing' => 2], wordCount('testing, 1, 2 testing')); } + /** + * UUID dac6bc6a-21ae-4954-945d-d7f716392dbf + */ + #[TestDox('normalize case')] public function testNormalizeCase(): void { $this->assertEquals(['go' => 3, 'stop' => 2], wordCount('go Go GO Stop stop')); } - public function testCountsMultiline(): void + /** + * UUID 4ff6c7d7-fcfc-43ef-b8e7-34ff1837a2d3 + */ + #[TestDox('with apostrophes')] + public function testWithApostrophes(): void { - $this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\nworld")); + $this->assertEquals(['first' => 1, "don't" => 1, 'count' => 1], wordCount("first: don't count")); } - public function testCountsTabs(): void + /** + * UUID be72af2b-8afe-4337-b151-b297202e4a7b + */ + #[TestDox('with quotations')] + public function testWithQuotations(): void { - $this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\tworld")); + $this->assertEquals(['hello' => 1, "world" => 1], wordCount("hello \"world\"")); + } + + /** + * UUID 8d6815fe-8a51-4a65-96f9-2fb3f6dc6ed6 + */ + #[TestDox('starts from the beginning')] + public function testStartsFromTheBeginning(): void + { + $this->assertEquals(['goody' => 1, 'good' => 1, 'oody' => 1], wordCount('goody good oody')); } + /** + * UUID c5f4ef26-f3f7-4725-b314-855c04fb4c13 + */ + #[TestDox('counts multiple spaces as one')] public function testCountsMultipleSpacesAsOne(): void { $this->assertEquals(['hello' => 1, 'world' => 1], wordCount('hello world')); } + /** + * UUID 50176e8a-fe8e-4f4c-b6b6-aa9cf8f20360 + */ + #[TestDox('alternating word separators are not detected as words')] + public function testAlternatingWordSeparatorsNotDetectedAsWord(): void + { + $this->assertEquals(['one' => 1, 'two' => 1, 'three' => 1], wordCount("one,\ntwo,\nthree")); + } + + /** + * UUID 6d00f1db-901c-4bec-9829-d20eb3044557 + */ + #[TestDox('quotation for word with apostrophe')] + public function testQuotationForWordWithApostrophe(): void + { + $this->assertEquals(['well' => 1, 'happening' => 3, "what's" => 1], wordCount("well, \"what's\" happening")); + } + + /** + * UUID not found + */ public function testDoesNotCountLeadingOrTrailingWhitespace(): void { $this->assertEquals(['introductory' => 1, 'course' => 1], wordCount("\t\tIntroductory Course ")); } + + /** + * UUID not found + */ + public function testCountsMultiline(): void + { + $this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\nworld")); + } + + /** + * UUID not found + */ + public function testCountsTabs(): void + { + $this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\tworld")); + } } From 401518b05a23395618db5c569a86c407f2133667 Mon Sep 17 00:00:00 2001 From: Domuriko Date: Wed, 27 May 2026 16:11:58 +0200 Subject: [PATCH 02/17] Re-add comment to tests.toml --- exercises/practice/word-count/.meta/tests.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exercises/practice/word-count/.meta/tests.toml b/exercises/practice/word-count/.meta/tests.toml index fbce5847e..e80d70541 100644 --- a/exercises/practice/word-count/.meta/tests.toml +++ b/exercises/practice/word-count/.meta/tests.toml @@ -1,3 +1,7 @@ +# This is an auto-generated file. Regular comments will be removed when this +# file is regenerated. Regenerating will not touch any manually added keys, +# so comments can be added in a "comment" key. + [61559d5f-2cad-48fb-af53-d3973a9ee9ef] description = "count one word" From d6e143ab1b028d8b7e92597325ccdde1765094cd Mon Sep 17 00:00:00 2001 From: Domuriko Date: Wed, 27 May 2026 19:31:54 +0200 Subject: [PATCH 03/17] Fix workflow issues --- exercises/practice/word-count/WordCountTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index f99f2fc32..627e4f722 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -132,7 +132,7 @@ public function testAlternatingWordSeparatorsNotDetectedAsWord(): void } /** - * UUID 6d00f1db-901c-4bec-9829-d20eb3044557 + * UUID 6d00f1db-901c-4bec-9829-d20eb3044557 */ #[TestDox('quotation for word with apostrophe')] public function testQuotationForWordWithApostrophe(): void From 1ee318e0438c762617b8014e3695b3a9615393a7 Mon Sep 17 00:00:00 2001 From: Domuriko Date: Wed, 27 May 2026 19:35:19 +0200 Subject: [PATCH 04/17] Fix test for quotation and apostrophe --- exercises/practice/word-count/WordCountTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index 627e4f722..78229cb2f 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -137,7 +137,7 @@ public function testAlternatingWordSeparatorsNotDetectedAsWord(): void #[TestDox('quotation for word with apostrophe')] public function testQuotationForWordWithApostrophe(): void { - $this->assertEquals(['well' => 1, 'happening' => 3, "what's" => 1], wordCount("well, \"what's\" happening")); + $this->assertEquals(['well' => 1, 'happening' => 1, "what's" => 1], wordCount("well, \"what's\" happening")); } /** From a0b2237558e6ef2a92abde74bb2d48f7caa0dd2f Mon Sep 17 00:00:00 2001 From: Hazeolation <68810539+Hazeolation@users.noreply.github.com> Date: Mon, 1 Jun 2026 08:41:14 +0200 Subject: [PATCH 05/17] Update exercises/practice/word-count/WordCountTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- exercises/practice/word-count/WordCountTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index 78229cb2f..0afddfe20 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -55,7 +55,7 @@ public function testHandlesExpandedLists(): void { $this->assertEquals( ['one' => 1, 'two' => 1, 'three' => 1], - wordCount('one, two, three') + wordCount("one,\ntwo,\nthree"), ); } From 71d545a4b6968706fd6c165086ab9ae90a5e3514 Mon Sep 17 00:00:00 2001 From: Hazeolation <68810539+Hazeolation@users.noreply.github.com> Date: Mon, 1 Jun 2026 08:41:34 +0200 Subject: [PATCH 06/17] Update exercises/practice/word-count/WordCountTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- exercises/practice/word-count/WordCountTest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index 0afddfe20..a849eada1 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -101,7 +101,17 @@ public function testWithApostrophes(): void #[TestDox('with quotations')] public function testWithQuotations(): void { - $this->assertEquals(['hello' => 1, "world" => 1], wordCount("hello \"world\"")); + $this->assertEquals( + [ + 'joe' => 1, + "can't" => 1, + 'tell' => 1, + 'between' => 1, + 'large' => 2, + 'and' => 1, + ], + wordCount("Joe can't tell between 'large' and large."), + ); } /** From b545d04d3e6d9912c708373648167bc671614876 Mon Sep 17 00:00:00 2001 From: Hazeolation <68810539+Hazeolation@users.noreply.github.com> Date: Mon, 1 Jun 2026 08:41:52 +0200 Subject: [PATCH 07/17] Update exercises/practice/word-count/WordCountTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- .../practice/word-count/WordCountTest.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index a849eada1..e1d52cfa5 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -117,10 +117,22 @@ public function testWithQuotations(): void /** * UUID 8d6815fe-8a51-4a65-96f9-2fb3f6dc6ed6 */ - #[TestDox('starts from the beginning')] - public function testStartsFromTheBeginning(): void + #[TestDox('substrings from the beginning')] + public function testSubstringsFromTheBeginning(): void { - $this->assertEquals(['goody' => 1, 'good' => 1, 'oody' => 1], wordCount('goody good oody')); + $this->assertEquals( + [ + 'joe' => 1, + "can't" => 1, + 'tell' => 1, + 'between' => 1, + 'app' => 1, + 'apple' => 1, + 'and' => 1, + 'a' => 1, + ], + wordCount("Joe can't tell between app, apple and a."), + ); } /** From e504656c264667fceba3e376338723212604d847 Mon Sep 17 00:00:00 2001 From: Hazeolation <68810539+Hazeolation@users.noreply.github.com> Date: Mon, 1 Jun 2026 08:42:09 +0200 Subject: [PATCH 08/17] Update exercises/practice/word-count/WordCountTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- exercises/practice/word-count/WordCountTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index e1d52cfa5..a21f9043c 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -141,7 +141,7 @@ public function testSubstringsFromTheBeginning(): void #[TestDox('counts multiple spaces as one')] public function testCountsMultipleSpacesAsOne(): void { - $this->assertEquals(['hello' => 1, 'world' => 1], wordCount('hello world')); + $this->assertEquals(['multiple' => 1, 'whitespaces' => 1], wordCount(' multiple whitespaces')); } /** From 574a5c86d8d355d5555b401bea9c1a916396d05a Mon Sep 17 00:00:00 2001 From: Hazeolation <68810539+Hazeolation@users.noreply.github.com> Date: Mon, 1 Jun 2026 08:42:21 +0200 Subject: [PATCH 09/17] Update exercises/practice/word-count/WordCountTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- exercises/practice/word-count/WordCountTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index a21f9043c..602e77208 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -138,8 +138,8 @@ public function testSubstringsFromTheBeginning(): void /** * UUID c5f4ef26-f3f7-4725-b314-855c04fb4c13 */ - #[TestDox('counts multiple spaces as one')] - public function testCountsMultipleSpacesAsOne(): void + #[TestDox('multiple spaces not detected as a word')] + public function testMultipleSpacesNotDetectedAsAWord(): void { $this->assertEquals(['multiple' => 1, 'whitespaces' => 1], wordCount(' multiple whitespaces')); } From 6cf34094f46599af01ef371f1a17701b940f5059 Mon Sep 17 00:00:00 2001 From: Hazeolation <68810539+Hazeolation@users.noreply.github.com> Date: Mon, 1 Jun 2026 08:42:31 +0200 Subject: [PATCH 10/17] Update exercises/practice/word-count/WordCountTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- exercises/practice/word-count/WordCountTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index 602e77208..5615f1e52 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -147,10 +147,10 @@ public function testMultipleSpacesNotDetectedAsAWord(): void /** * UUID 50176e8a-fe8e-4f4c-b6b6-aa9cf8f20360 */ - #[TestDox('alternating word separators are not detected as words')] - public function testAlternatingWordSeparatorsNotDetectedAsWord(): void + #[TestDox('alternating word separators are not detected as a word')] + public function testAlternatingWordSeparatorsNotDetectedAsAWord(): void { - $this->assertEquals(['one' => 1, 'two' => 1, 'three' => 1], wordCount("one,\ntwo,\nthree")); + $this->assertEquals(['one' => 1, 'two' => 1, 'three' => 1], wordCount(",\n,one,\n ,two \n 'three'")); } /** From a1811e57e5d406d29593c121e5e58122e2d10ff6 Mon Sep 17 00:00:00 2001 From: Hazeolation <68810539+Hazeolation@users.noreply.github.com> Date: Mon, 1 Jun 2026 08:42:45 +0200 Subject: [PATCH 11/17] Update exercises/practice/word-count/WordCountTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- exercises/practice/word-count/WordCountTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index 5615f1e52..5cfc3ea92 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -159,7 +159,7 @@ public function testAlternatingWordSeparatorsNotDetectedAsAWord(): void #[TestDox('quotation for word with apostrophe')] public function testQuotationForWordWithApostrophe(): void { - $this->assertEquals(['well' => 1, 'happening' => 1, "what's" => 1], wordCount("well, \"what's\" happening")); + $this->assertEquals(['can' => 1, "can't" => 2], wordCount("can, can't, 'can't'")); } /** From 4fa4b5781e0c47595ee396b05642950bb496ca46 Mon Sep 17 00:00:00 2001 From: Hazeolation <68810539+Hazeolation@users.noreply.github.com> Date: Mon, 1 Jun 2026 08:42:57 +0200 Subject: [PATCH 12/17] Update exercises/practice/word-count/WordCountTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- .../practice/word-count/WordCountTest.php | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index 5cfc3ea92..53f4fb3ad 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -161,28 +161,4 @@ public function testQuotationForWordWithApostrophe(): void { $this->assertEquals(['can' => 1, "can't" => 2], wordCount("can, can't, 'can't'")); } - - /** - * UUID not found - */ - public function testDoesNotCountLeadingOrTrailingWhitespace(): void - { - $this->assertEquals(['introductory' => 1, 'course' => 1], wordCount("\t\tIntroductory Course ")); - } - - /** - * UUID not found - */ - public function testCountsMultiline(): void - { - $this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\nworld")); - } - - /** - * UUID not found - */ - public function testCountsTabs(): void - { - $this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\tworld")); - } } From 6082a2ebd296b366c66e98d3a1b4736fa19db1d8 Mon Sep 17 00:00:00 2001 From: Hazeolation <68810539+Hazeolation@users.noreply.github.com> Date: Mon, 1 Jun 2026 08:43:07 +0200 Subject: [PATCH 13/17] Update exercises/practice/word-count/WordCountTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- exercises/practice/word-count/WordCountTest.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index 53f4fb3ad..3158019be 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -92,7 +92,19 @@ public function testNormalizeCase(): void #[TestDox('with apostrophes')] public function testWithApostrophes(): void { - $this->assertEquals(['first' => 1, "don't" => 1, 'count' => 1], wordCount("first: don't count")); + $this->assertEquals( + [ + 'first' => 1, + "don't" => 2, + 'laugh' => 1, + 'then' => 1, + 'cry' => 1, + "you're" => 1, + 'getting' => 1, + 'it' => 1, + ], + wordCount("'First: don't laugh. Then: don't cry. You're getting it.'") + ); } /** From 28026c75cf1668ddd182b169c3d2ee4a722df5ae Mon Sep 17 00:00:00 2001 From: Hazeolation Date: Mon, 1 Jun 2026 08:48:06 +0200 Subject: [PATCH 14/17] Fix test formatting --- .../practice/word-count/WordCountTest.php | 86 ++++++++++++++++--- 1 file changed, 74 insertions(+), 12 deletions(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index 3158019be..8353cc210 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -17,7 +17,10 @@ public static function setUpBeforeClass(): void #[TestDox('count one word')] public function testCountOneWord(): void { - $this->assertEquals(['word' => 1], wordCount('word')); + $this->assertEquals( + ['word' => 1], + wordCount('word'), + ); } /** @@ -26,7 +29,14 @@ public function testCountOneWord(): void #[TestDox('count one of each word')] public function testCountOneOfEachWord(): void { - $this->assertEquals(['one' => 1, 'of' => 1, 'each' => 1], wordCount('one of each')); + $this->assertEquals( + [ + 'one' => 1, + 'of' => 1, + 'each' => 1 + ], + wordCount('one of each'), + ); } /** @@ -35,7 +45,16 @@ public function testCountOneOfEachWord(): void #[TestDox('multiple occurrences of a word')] public function testMultipleOccurrencesOfAWord(): void { - $this->assertEquals(['one' => 1, 'fish' => 4, 'two' => 1, 'red' => 1, 'blue' => 1], wordCount('one fish two fish red fish blue fish')); + $this->assertEquals( + [ + 'one' => 1, + 'fish' => 4, + 'two' => 1, + 'red' => 1, + 'blue' => 1 + ], + wordCount('one fish two fish red fish blue fish'), + ); } /** @@ -44,7 +63,14 @@ public function testMultipleOccurrencesOfAWord(): void #[TestDox('handles cramped lists')] public function testHandlesCrampedLists(): void { - $this->assertEquals(['one' => 1, 'two' => 1, 'three' => 1], wordCount('one,two,three')); + $this->assertEquals( + [ + 'one' => 1, + 'two' => 1, + 'three' => 1 + ], + wordCount('one,two,three'), + ); } /** @@ -54,7 +80,11 @@ public function testHandlesCrampedLists(): void public function testHandlesExpandedLists(): void { $this->assertEquals( - ['one' => 1, 'two' => 1, 'three' => 1], + [ + 'one' => 1, + 'two' => 1, + 'three' => 1 + ], wordCount("one,\ntwo,\nthree"), ); } @@ -65,7 +95,16 @@ public function testHandlesExpandedLists(): void #[TestDox('ignore punctuation')] public function testIgnorePunctuation(): void { - $this->assertEquals(['car' => 1, 'carpet' => 1, 'as' => 1, 'java' => 1, 'javascript' => 1], wordCount('car : carpet as java : javascript!!&@$%^&')); + $this->assertEquals( + [ + 'car' => 1, + 'carpet' => 1, + 'as' => 1, + 'java' => 1, + 'javascript' => 1 + ], + wordCount('car : carpet as java : javascript!!&@$%^&'), + ); } /** @@ -74,7 +113,14 @@ public function testIgnorePunctuation(): void #[TestDox('include numbers')] public function testIncludeNumbers(): void { - $this->assertEquals(['1' => 1, '2' => 1, 'testing' => 2], wordCount('testing, 1, 2 testing')); + $this->assertEquals( + [ + '1' => 1, + '2' => 1, + 'testing' => 2 + ], + wordCount('testing, 1, 2 testing'), + ); } /** @@ -83,7 +129,10 @@ public function testIncludeNumbers(): void #[TestDox('normalize case')] public function testNormalizeCase(): void { - $this->assertEquals(['go' => 3, 'stop' => 2], wordCount('go Go GO Stop stop')); + $this->assertEquals( + ['go' => 3, 'stop' => 2], + wordCount('go Go GO Stop stop'), + ); } /** @@ -103,7 +152,7 @@ public function testWithApostrophes(): void 'getting' => 1, 'it' => 1, ], - wordCount("'First: don't laugh. Then: don't cry. You're getting it.'") + wordCount("'First: don't laugh. Then: don't cry. You're getting it.'"), ); } @@ -153,7 +202,10 @@ public function testSubstringsFromTheBeginning(): void #[TestDox('multiple spaces not detected as a word')] public function testMultipleSpacesNotDetectedAsAWord(): void { - $this->assertEquals(['multiple' => 1, 'whitespaces' => 1], wordCount(' multiple whitespaces')); + $this->assertEquals( + ['multiple' => 1, 'whitespaces' => 1], + wordCount(' multiple whitespaces'), + ); } /** @@ -162,7 +214,14 @@ public function testMultipleSpacesNotDetectedAsAWord(): void #[TestDox('alternating word separators are not detected as a word')] public function testAlternatingWordSeparatorsNotDetectedAsAWord(): void { - $this->assertEquals(['one' => 1, 'two' => 1, 'three' => 1], wordCount(",\n,one,\n ,two \n 'three'")); + $this->assertEquals( + [ + 'one' => 1, + 'two' => 1, + 'three' => 1 + ], + wordCount(",\n,one,\n ,two \n 'three'"), + ); } /** @@ -171,6 +230,9 @@ public function testAlternatingWordSeparatorsNotDetectedAsAWord(): void #[TestDox('quotation for word with apostrophe')] public function testQuotationForWordWithApostrophe(): void { - $this->assertEquals(['can' => 1, "can't" => 2], wordCount("can, can't, 'can't'")); + $this->assertEquals( + ['can' => 1, "can't" => 2], + wordCount("can, can't, 'can't'"), + ); } } From 45846c3552b03d8c1ce8685f5f8db7127d397b6f Mon Sep 17 00:00:00 2001 From: Hazeolation Date: Mon, 1 Jun 2026 08:57:48 +0200 Subject: [PATCH 15/17] Add forgotten trailing commas --- exercises/practice/word-count/WordCountTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/exercises/practice/word-count/WordCountTest.php b/exercises/practice/word-count/WordCountTest.php index 8353cc210..f7b2556e8 100644 --- a/exercises/practice/word-count/WordCountTest.php +++ b/exercises/practice/word-count/WordCountTest.php @@ -33,7 +33,7 @@ public function testCountOneOfEachWord(): void [ 'one' => 1, 'of' => 1, - 'each' => 1 + 'each' => 1, ], wordCount('one of each'), ); @@ -51,7 +51,7 @@ public function testMultipleOccurrencesOfAWord(): void 'fish' => 4, 'two' => 1, 'red' => 1, - 'blue' => 1 + 'blue' => 1, ], wordCount('one fish two fish red fish blue fish'), ); @@ -67,7 +67,7 @@ public function testHandlesCrampedLists(): void [ 'one' => 1, 'two' => 1, - 'three' => 1 + 'three' => 1, ], wordCount('one,two,three'), ); @@ -83,7 +83,7 @@ public function testHandlesExpandedLists(): void [ 'one' => 1, 'two' => 1, - 'three' => 1 + 'three' => 1, ], wordCount("one,\ntwo,\nthree"), ); @@ -101,7 +101,7 @@ public function testIgnorePunctuation(): void 'carpet' => 1, 'as' => 1, 'java' => 1, - 'javascript' => 1 + 'javascript' => 1, ], wordCount('car : carpet as java : javascript!!&@$%^&'), ); @@ -117,7 +117,7 @@ public function testIncludeNumbers(): void [ '1' => 1, '2' => 1, - 'testing' => 2 + 'testing' => 2, ], wordCount('testing, 1, 2 testing'), ); @@ -218,7 +218,7 @@ public function testAlternatingWordSeparatorsNotDetectedAsAWord(): void [ 'one' => 1, 'two' => 1, - 'three' => 1 + 'three' => 1, ], wordCount(",\n,one,\n ,two \n 'three'"), ); From faf3c82274f30299b8d1502c0c726a44cbf72044 Mon Sep 17 00:00:00 2001 From: Hazeolation Date: Mon, 1 Jun 2026 18:55:09 +0200 Subject: [PATCH 16/17] Adjust example.php regex --- exercises/practice/word-count/.meta/example.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/word-count/.meta/example.php b/exercises/practice/word-count/.meta/example.php index ef4133bd0..d3b47cabe 100644 --- a/exercises/practice/word-count/.meta/example.php +++ b/exercises/practice/word-count/.meta/example.php @@ -6,7 +6,7 @@ function wordCount($phrase) { $count = []; - $phrase = preg_replace(['/[^a-zA-Z0-9]+/', '/\s\s/'], ' ', mb_strtolower($phrase)); + $phrase = preg_replace(['/[^a-zA-Z0-9\'\"]+/', '/\s\s/'], ' ', mb_strtolower($phrase)); foreach (explode(' ', $phrase) as $word) { if (!array_key_exists($word, $count) && !empty($word)) { From ea49c1ea319b246e5fdb61ecbf172d99bcabfa1c Mon Sep 17 00:00:00 2001 From: Hazeolation Date: Mon, 1 Jun 2026 22:22:02 +0200 Subject: [PATCH 17/17] Adjust regex in example.php --- exercises/practice/word-count/.meta/example.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/word-count/.meta/example.php b/exercises/practice/word-count/.meta/example.php index d3b47cabe..6e63af2e0 100644 --- a/exercises/practice/word-count/.meta/example.php +++ b/exercises/practice/word-count/.meta/example.php @@ -6,7 +6,7 @@ function wordCount($phrase) { $count = []; - $phrase = preg_replace(['/[^a-zA-Z0-9\'\"]+/', '/\s\s/'], ' ', mb_strtolower($phrase)); + $phrase = preg_replace(['/(?:[^a-zA-Z0-9\']|(?