Files
php-qml/framework/php/tests/Maker/Support/NamingTest.php
magdev 0710d81783 v0.2.0 (3/N): extract Maker shared helpers (NameInput, Naming)
DRY pass identified by the post-v0.1.2 audit: every make:bridge:*
maker re-implemented the same "prompt, trim, ucfirst, reject empty"
closure in interact(), and the camel-case-to-separator regex was
duplicated between BridgeResourceMaker (`_`-joined route plurals)
and BridgeCommandMaker (`-`-joined kebab slugs).

Two helpers under PhpQml\Bridge\Maker\Support:
  - NameInput::askOrFail() — replaces 3× inline closures
  - Naming::camelTo($name, $separator) — replaces 2× inline regexes

All 3 makers now go through the helpers; behaviour preserved
(maker snapshot test still passes — generated Todo / TodoController
/ TodoList / MarkAllDoneController / TodoWindow byte-identical to
the v0.1.2 baselines).

NamingTest covers the documented cases plus a regression case for
acronyms (HTTPClient → h-t-t-p-client; the regex splits at every
internal capital, which is correct for the route-slug use case).

Test count 17 → 23, all passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 20:02:03 +02:00

32 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpQml\Bridge\Tests\Maker\Support;
use PhpQml\Bridge\Maker\Support\Naming;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
#[CoversClass(Naming::class)]
final class NamingTest extends TestCase
{
#[DataProvider('camelToCases')]
public function testCamelTo(string $input, string $separator, string $expected): void
{
self::assertSame($expected, Naming::camelTo($input, $separator));
}
/** @return iterable<string, array{string, string, string}> */
public static function camelToCases(): iterable
{
yield 'single word, underscore' => ['Todo', '_', 'todo'];
yield 'two words, underscore' => ['TodoList', '_', 'todo_list'];
yield 'two words, dash' => ['MarkAllDone', '-', 'mark-all-done'];
yield 'leading uppercase, no split' => ['Todo', '-', 'todo'];
yield 'all caps stay together (acronym preserved)' => ['HTTPClient', '-', 'h-t-t-p-client'];
yield 'empty input' => ['', '-', ''];
}
}