Files
myep-team/tests/Config/SeasonCalendarTest.php
2026-08-31 16:26:53 +02:00

74 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Config;
use App\Config\SeasonCalendar;
use PHPUnit\Framework\TestCase;
class SeasonCalendarTest extends TestCase
{
private function winter(): SeasonCalendar
{
return new SeasonCalendar('11-01', '04-01');
}
/**
* @dataProvider winterDates
*/
public function testSeasonYearForTheWrappingWinterWindow(string $date, ?int $expected): void
{
$this->assertSame($expected, $this->winter()->seasonYearFor(new \DateTimeImmutable($date)));
}
public static function winterDates(): iterable
{
yield 'first day of the season' => ['2024-11-01', 2024];
yield 'december, same calendar year' => ['2024-12-20', 2024];
yield 'february, next calendar year' => ['2025-02-10', 2024];
yield 'last day of the season is inclusive' => ['2025-04-01', 2024];
yield 'time of day does not matter' => ['2025-04-01 23:59:00', 2024];
yield 'day after the season ends' => ['2025-04-02', null];
yield 'high summer' => ['2025-07-15', null];
yield 'day before the next season starts' => ['2025-10-31', null];
yield 'start of the following season' => ['2025-11-01', 2025];
}
public function testLabel(): void
{
$calendar = $this->winter();
$this->assertSame('Saison 2024/25', $calendar->label(2024));
$this->assertSame('Saison 2009/10', $calendar->label(2009));
$this->assertSame('außerhalb der Saison', $calendar->label(null));
}
/**
* @dataProvider summerDates
*/
public function testSeasonYearForANonWrappingWindow(string $date, ?int $expected): void
{
$calendar = new SeasonCalendar('06-01', '09-01');
$this->assertSame($expected, $calendar->seasonYearFor(new \DateTimeImmutable($date)));
}
public static function summerDates(): iterable
{
yield 'before the window' => ['2025-05-31', null];
yield 'first day' => ['2025-06-01', 2025];
yield 'inside' => ['2025-07-15', 2025];
yield 'last day' => ['2025-09-01', 2025];
yield 'after the window' => ['2025-09-02', null];
yield 'turn of the year is not in season' => ['2025-01-01', null];
}
public function testAnInvalidBoundaryIsRejected(): void
{
$this->expectException(\InvalidArgumentException::class);
(new SeasonCalendar('xx-yy', '04-01'))->seasonYearFor(new \DateTimeImmutable('2025-01-01'));
}
}