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)); } #[\PHPUnit\Framework\Attributes\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')); } #[\PHPUnit\Framework\Attributes\DataProvider('currentOrUpcomingDates')] public function testCurrentOrUpcomingSeasonYear(string $date, int $expected): void { $this->assertSame( $expected, $this->winter()->currentOrUpcomingSeasonYear(new \DateTimeImmutable($date)) ); } public static function currentOrUpcomingDates(): iterable { yield 'inside the season' => ['2024-12-20', 2024]; yield 'last day of the season' => ['2025-04-01', 2024]; yield 'day after the season ends falls forward' => ['2025-04-02', 2025]; yield 'high summer falls forward' => ['2025-07-15', 2025]; yield 'day before the next season starts' => ['2025-10-31', 2025]; yield 'first day of the next season' => ['2025-11-01', 2025]; yield 'off-season in january is impossible for this window' => ['2025-01-05', 2024]; } public function testCurrentOrUpcomingSeasonYearFallsForwardAcrossTheTurnOfTheYear(): void { // A window that ends before it starts in the same calendar year is the wrapping case; // one that does not wrap has its off-season on both sides of the window instead. $summer = new SeasonCalendar('05-01', '09-30'); $this->assertSame(2025, $summer->currentOrUpcomingSeasonYear(new \DateTimeImmutable('2025-03-01'))); $this->assertSame(2025, $summer->currentOrUpcomingSeasonYear(new \DateTimeImmutable('2025-06-01'))); $this->assertSame(2026, $summer->currentOrUpcomingSeasonYear(new \DateTimeImmutable('2025-11-20'))); } public function testWindowFor(): void { [$start, $end] = $this->winter()->windowFor(2024); $this->assertSame('2024-11-01', $start->format('Y-m-d')); $this->assertSame('2025-04-01', $end->format('Y-m-d')); [$start, $end] = (new SeasonCalendar('05-01', '09-30'))->windowFor(2025); $this->assertSame('2025-05-01', $start->format('Y-m-d')); $this->assertSame('2025-09-30', $end->format('Y-m-d')); } #[\PHPUnit\Framework\Attributes\DataProvider('provideUpcomingSeasonDates')] public function testTheCurrentOrUpcomingSeasonYear(string $date, int $expected): void { $calendar = new SeasonCalendar('11-01', '04-01'); $this->assertSame($expected, $calendar->currentOrUpcomingSeasonYear(new \DateTimeImmutable($date))); } public static function provideUpcomingSeasonDates(): iterable { // Between two seasons: the winter ahead, which is what a recruiting mail means. yield 'September, before the season starts' => ['2026-09-24', 2026]; yield 'the day the season starts' => ['2026-11-01', 2026]; // Inside a season: that season, not the next one. yield 'December, mid season' => ['2026-12-15', 2026]; yield 'the last day of the season' => ['2027-04-01', 2026]; // After a season ended, so the next one to start. yield 'May, after the season ended' => ['2027-05-02', 2027]; } public function testTheShortLabelIsTheTwoDigitSpan(): void { $calendar = new SeasonCalendar('11-01', '04-01'); $this->assertSame('26/27', $calendar->shortLabel(2026)); // The turn of the century has to stay two digits on both ends. $this->assertSame('99/00', $calendar->shortLabel(1999)); } }