ldc-arcadia-api/tests/Unit/Shared/Helpers/StringHelperTest.php

41 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Shared\Helpers;
use Shared\Helpers\StringHelper;
covers(StringHelper::class);
describe('StringHelper Unit Tests', function (): void {
it('prevents direct instantiation', function (): void {
// GIVEN
$reflection = new \ReflectionClass(StringHelper::class);
// WHEN & THEN
expect(fn () => $reflection->newInstance())
->toThrow(\ReflectionException::class);
});
it('transliterates accented and special characters to ascii', function (): void {
// GIVEN
$input = 'Émincés & Rôti, crème brûlée, ça va ?';
// WHEN
$result = StringHelper::transliterate($input);
// THEN
expect($result)->toBe('Eminces & Roti, creme brulee, ca va ?');
});
it('handles empty strings and plain ascii strings without modification', function (): void {
// GIVEN
$empty = '';
$ascii = 'hello world 123';
// WHEN & THEN
expect(StringHelper::transliterate($empty))->toBe('')
->and(StringHelper::transliterate($ascii))->toBe('hello world 123');
});
});