diff --git a/CHANGELOG.md b/CHANGELOG.md index 86fd4db..563e5ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.2.0 Under development - Enh #6: Refactor codebase to improve performance (@terabytesoftw) +- Bug #8: Raise Code Coverage `100%` (@terabytesoftw) ## 0.1.0 February 25, 2024 diff --git a/src/WordCaseConverter.php b/src/WordCaseConverter.php index 22351cb..9cdbc1a 100644 --- a/src/WordCaseConverter.php +++ b/src/WordCaseConverter.php @@ -8,7 +8,6 @@ use function ltrim; use function preg_match; use function preg_replace; -use function preg_split; use function strtolower; use function ucfirst; diff --git a/tests/Support/MockerExtension.php b/tests/Support/MockerExtension.php index e0180b0..53b5266 100644 --- a/tests/Support/MockerExtension.php +++ b/tests/Support/MockerExtension.php @@ -63,6 +63,10 @@ public static function load(): void 'namespace' => 'PHPForge\\Helper', 'name' => 'random_int', ], + [ + 'namespace' => 'PHPForge\\Helper', + 'name' => 'preg_split', + ], [ 'namespace' => 'PHPForge\\Helper', 'name' => 'str_contains', diff --git a/tests/WordCaseConverterTest.php b/tests/WordCaseConverterTest.php index b08fd6f..264854d 100644 --- a/tests/WordCaseConverterTest.php +++ b/tests/WordCaseConverterTest.php @@ -18,6 +18,7 @@ * - Ensures `snakeToCamel()` returns early without calling `explode()` when no underscore exists. * - Ensures `snakeToCamel()` returns expected camel case values. * - Ensures `toTitleWords()` formats snake case, camel case, and uppercase values consistently. + * - Ensures `toTitleWords()` falls back to `ucfirst()` when `preg_split()` fails. * * @copyright Copyright (C) 2026 Terabytesoftw. * @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License. @@ -74,4 +75,20 @@ public function testToTitleWords(string $input, string $expected, string $messag $message, ); } + + public function testToTitleWordsFallsBackWhenPregSplitFails(): void + { + MockerState::addCondition( + 'PHPForge\\Helper', + 'preg_split', + ['/(?<=[a-z])(?=[A-Z])|_/', 'foo_bar', -1, 0], + false, + ); + + self::assertSame( + 'Foo_bar', + WordCaseConverter::toTitleWords('foo_bar'), + "Should return ucfirst(input) when 'preg_split()' fails.", + ); + } }