55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Infra\Adapters\Services;
|
|
|
|
use Infra\Adapters\Services\TimestampValidatorImpl;
|
|
use Shared\Time\FrozenClock;
|
|
|
|
covers(TimestampValidatorImpl::class);
|
|
|
|
describe('TimestampValidatorImpl Unit Tests', function (): void {
|
|
it('accepts timestamps within the 300 seconds skew window', function (string $modifier): void {
|
|
// GIVEN
|
|
$timezone = new \DateTimeZone('UTC');
|
|
$fixedTime = new \DateTimeImmutable('2026-08-21 12:00:00', $timezone);
|
|
$frozenClock = new FrozenClock($fixedTime);
|
|
$validator = new TimestampValidatorImpl($timezone, $frozenClock);
|
|
$timestamp = $fixedTime->modify($modifier);
|
|
|
|
// WHEN
|
|
$isValid = $validator->validate($timestamp);
|
|
|
|
// THEN
|
|
expect($isValid)->toBeTrue();
|
|
})->with([
|
|
'0 seconds',
|
|
'-2 minutes',
|
|
'+2 minutes',
|
|
'-299 seconds',
|
|
'+299 seconds',
|
|
]);
|
|
|
|
it('rejects timestamps outside the 300 seconds skew window', function (string $modifier): void {
|
|
// GIVEN
|
|
$timezone = new \DateTimeZone('UTC');
|
|
$fixedTime = new \DateTimeImmutable('2026-08-21 12:00:00', $timezone);
|
|
$frozenClock = new FrozenClock($fixedTime);
|
|
$validator = new TimestampValidatorImpl($timezone, $frozenClock);
|
|
$timestamp = $fixedTime->modify($modifier);
|
|
|
|
// WHEN
|
|
$isValid = $validator->validate($timestamp);
|
|
|
|
// THEN
|
|
expect($isValid)->toBeFalse();
|
|
})->with([
|
|
'-6 minutes',
|
|
'+6 minutes',
|
|
'-301 seconds',
|
|
'+301 seconds',
|
|
'-1 day',
|
|
'+1 day',
|
|
]);
|
|
});
|