42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Service\Cron;
|
|
|
|
use App\Service\Cron\ReminderCadence;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ReminderCadenceTest extends TestCase
|
|
{
|
|
/**
|
|
* @return iterable<string, array{int, bool}>
|
|
*/
|
|
public static function nights(): iterable
|
|
{
|
|
yield 'the day the trip ends' => [0, false];
|
|
yield 'first night after' => [1, true];
|
|
yield 'last daily night' => [7, true];
|
|
yield 'first quiet night' => [8, false];
|
|
yield 'still quiet' => [13, false];
|
|
yield 'two weeks' => [14, true];
|
|
yield 'three weeks' => [21, true];
|
|
yield 'between the weeks' => [22, false];
|
|
yield 'months later' => [70, true];
|
|
}
|
|
|
|
#[DataProvider('nights')]
|
|
public function testDailyForAWeekThenWeekly(int $nights, bool $due): void
|
|
{
|
|
$today = new \DateTimeImmutable('2026-11-20');
|
|
|
|
$this->assertSame($due, ReminderCadence::isDue($today->modify(sprintf('-%d days', $nights)), $today));
|
|
}
|
|
|
|
public function testTheTimeOfDayDoesNotCount(): void
|
|
{
|
|
$this->assertTrue(ReminderCadence::isDue(new \DateTimeImmutable('2026-11-13 23:59'), new \DateTimeImmutable('2026-11-20 01:00')));
|
|
}
|
|
}
|