51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Config;
|
|
|
|
use App\Config\BookingHorizon;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class BookingHorizonTest extends TestCase
|
|
{
|
|
public function testTheHorizonIsThreeMonthsFromTheGivenDay(): void
|
|
{
|
|
self::assertSame(
|
|
'2026-12-14',
|
|
BookingHorizon::latest(new \DateTimeImmutable('2026-09-14'))->format('Y-m-d'),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* PHP's "+3 months" from a 31st overflows into the next month (31 November does not exist,
|
|
* so it becomes 1 December). Pinned rather than clamped: this is a cap, and one extra day of
|
|
* horizon four times a year is not worth the arithmetic it would take to remove. The
|
|
* recurrence code deliberately avoids months for exactly this reason -- see
|
|
* RecurrenceRule::intervalDays() -- but a single boundary can live with it.
|
|
*/
|
|
public function testAMonthEndOverflowsByADayAndThatIsAccepted(): void
|
|
{
|
|
self::assertSame(
|
|
'2026-12-01',
|
|
BookingHorizon::latest(new \DateTimeImmutable('2026-08-31'))->format('Y-m-d'),
|
|
);
|
|
}
|
|
|
|
public function testTheTimePartIsDroppedSoTheComparisonIsPerDay(): void
|
|
{
|
|
self::assertSame(
|
|
'00:00:00',
|
|
BookingHorizon::latest(new \DateTimeImmutable('2026-09-14 17:42:13'))->format('H:i:s'),
|
|
);
|
|
}
|
|
|
|
public function testItDefaultsToToday(): void
|
|
{
|
|
self::assertEquals(
|
|
BookingHorizon::latest(new \DateTimeImmutable('today')),
|
|
BookingHorizon::latest(),
|
|
);
|
|
}
|
|
}
|