52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Shared\ValueObjects\Config;
|
||
|
|
|
||
|
|
use Shared\ValueObjects\Config\Locale;
|
||
|
|
|
||
|
|
covers(Locale::class);
|
||
|
|
|
||
|
|
describe('Locale Value Object Unit Tests', function (): void {
|
||
|
|
it('creates valid locale', function (string $raw, string $expectedPrimary): void {
|
||
|
|
// WHEN
|
||
|
|
$locale = new Locale($raw);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($locale->value())->toBe(trim($raw))
|
||
|
|
->and((string) $locale)->toBe(trim($raw))
|
||
|
|
->and($locale->primaryLanguage())->toBe($expectedPrimary);
|
||
|
|
})->with([
|
||
|
|
['fr', 'fr'],
|
||
|
|
['en', 'en'],
|
||
|
|
['fr_FR', 'fr'],
|
||
|
|
['en_US', 'en'],
|
||
|
|
['en-GB', 'en'],
|
||
|
|
]);
|
||
|
|
|
||
|
|
it('rejects invalid locale formats', function (string $invalid): void {
|
||
|
|
// GIVEN & WHEN & THEN
|
||
|
|
expect(fn () => new Locale($invalid))
|
||
|
|
->toThrow(\InvalidArgumentException::class);
|
||
|
|
})->with([
|
||
|
|
'',
|
||
|
|
' ',
|
||
|
|
'f',
|
||
|
|
'123',
|
||
|
|
'invalid_locale_format_too_long',
|
||
|
|
]);
|
||
|
|
|
||
|
|
it('handles equality properly', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$locale1 = new Locale('fr');
|
||
|
|
$locale2 = new Locale('fr');
|
||
|
|
$locale3 = new Locale('en');
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($locale1->equals($locale2))->toBeTrue()
|
||
|
|
->and($locale1->equals($locale3))->toBeFalse()
|
||
|
|
->and($locale1->equals('fr'))->toBeFalse();
|
||
|
|
});
|
||
|
|
});
|