Files
ephub/tests/Booking/HorizonTest.php
T

51 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Booking;
use App\Booking\Horizon;
use PHPUnit\Framework\TestCase;
class HorizonTest extends TestCase
{
public function testTheHorizonIsThreeMonthsFromTheGivenDay(): void
{
self::assertSame(
'2026-12-14',
Horizon::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',
Horizon::latest(new \DateTimeImmutable('2026-08-31'))->format('Y-m-d'),
);
}
public function testTheTimePartIsDroppedSoTheComparisonIsPerDay(): void
{
self::assertSame(
'00:00:00',
Horizon::latest(new \DateTimeImmutable('2026-09-14 17:42:13'))->format('H:i:s'),
);
}
public function testItDefaultsToToday(): void
{
self::assertEquals(
Horizon::latest(new \DateTimeImmutable('today')),
Horizon::latest(),
);
}
}