ldc-arcadia-api/tests/Unit/Shared/ValueObjects/Config/AppTimezoneTest.php

54 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Shared\ValueObjects\Config;
use Shared\ValueObjects\Config\AppTimezone;
covers(AppTimezone::class);
describe('AppTimezone Value Object Unit Tests', function (): void {
it('creates valid timezone from name', function (): void {
// GIVEN
$tz = new AppTimezone('Europe/Paris');
// THEN
expect($tz->name)->toBe('Europe/Paris')
->and((string) $tz)->toBe('Europe/Paris')
->and($tz->toDateTimeZone())->toBeInstanceOf(\DateTimeZone::class)
->and($tz->toDateTimeZone()->getName())->toBe('Europe/Paris');
});
it('creates default UTC timezone', function (): void {
// GIVEN
$tz = AppTimezone::utc();
// THEN
expect($tz->name)->toBe('UTC')
->and((string) $tz)->toBe('UTC');
});
it('rejects invalid timezone names', function (string $invalid): void {
// GIVEN & WHEN & THEN
expect(fn () => new AppTimezone($invalid))
->toThrow(\InvalidArgumentException::class);
})->with([
'',
' ',
'Invalid/Timezone_Name',
'Moon/Base',
]);
it('handles equality properly', function (): void {
// GIVEN
$tz1 = new AppTimezone('UTC');
$tz2 = AppTimezone::utc();
$tz3 = new AppTimezone('Europe/Paris');
// THEN
expect($tz1->equals($tz2))->toBeTrue()
->and($tz1->equals($tz3))->toBeFalse()
->and($tz1->equals('UTC'))->toBeFalse();
});
});