Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/WordCaseConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions tests/Support/MockerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
17 changes: 17 additions & 0 deletions tests/WordCaseConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.",
);
}
}
Loading