71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Services\Project;
|
|
|
|
use App\Services\Project\SupplierSnapshotGuard;
|
|
use Carbon\CarbonImmutable;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Unit-тесты для SupplierSnapshotGuard.
|
|
*
|
|
* Spec: docs/superpowers/plans/2026-05-26-supplier-snapshot-guard.md
|
|
*/
|
|
class SupplierSnapshotGuardTest extends TestCase
|
|
{
|
|
private SupplierSnapshotGuard $guard;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->guard = new SupplierSnapshotGuard;
|
|
}
|
|
|
|
public function test_grace_until_for_pause_before_21_msk_is_next_day_21_msk(): void
|
|
{
|
|
$pausedAt = CarbonImmutable::parse('2026-05-25 14:00:00', 'Europe/Moscow');
|
|
$graceUntil = $this->guard->computeGraceUntil($pausedAt);
|
|
|
|
$this->assertSame(
|
|
'2026-05-26 21:00:00',
|
|
$graceUntil->setTimezone('Europe/Moscow')->format('Y-m-d H:i:s'),
|
|
);
|
|
}
|
|
|
|
public function test_grace_until_for_pause_after_21_msk_is_day_plus_two_21_msk(): void
|
|
{
|
|
$pausedAt = CarbonImmutable::parse('2026-05-25 22:00:00', 'Europe/Moscow');
|
|
$graceUntil = $this->guard->computeGraceUntil($pausedAt);
|
|
|
|
$this->assertSame(
|
|
'2026-05-27 21:00:00',
|
|
$graceUntil->setTimezone('Europe/Moscow')->format('Y-m-d H:i:s'),
|
|
);
|
|
}
|
|
|
|
public function test_grace_until_for_pause_exactly_at_21_msk_is_day_plus_two_21_msk(): void
|
|
{
|
|
$pausedAt = CarbonImmutable::parse('2026-05-25 21:00:00', 'Europe/Moscow');
|
|
$graceUntil = $this->guard->computeGraceUntil($pausedAt);
|
|
|
|
$this->assertSame(
|
|
'2026-05-27 21:00:00',
|
|
$graceUntil->setTimezone('Europe/Moscow')->format('Y-m-d H:i:s'),
|
|
);
|
|
}
|
|
|
|
public function test_grace_until_handles_utc_input(): void
|
|
{
|
|
// 14:00 UTC = 17:00 MSK (до 21:00) → grace = следующее 21:00 МСК +24ч
|
|
$pausedAt = CarbonImmutable::parse('2026-05-25 14:00:00', 'UTC');
|
|
$graceUntil = $this->guard->computeGraceUntil($pausedAt);
|
|
|
|
$this->assertSame(
|
|
'2026-05-26 21:00:00',
|
|
$graceUntil->setTimezone('Europe/Moscow')->format('Y-m-d H:i:s'),
|
|
);
|
|
}
|
|
}
|