feat: teamer season disposition count in info modal

addresses #869dv94n4
This commit is contained in:
2026-08-31 16:26:53 +02:00
parent 39e6f35374
commit 86c5d23181
8 changed files with 344 additions and 2 deletions
+73
View File
@@ -0,0 +1,73 @@
<?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'));
}
}
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service\Teamer;
use App\Config\SeasonCalendar;
use App\Entity\Teamer;
use App\Repository\DispositionRepository;
use App\Service\Teamer\SeasonDispositionCounter;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class SeasonDispositionCounterTest extends TestCase
{
private DispositionRepository&MockObject $dispositionRepository;
private SeasonDispositionCounter $counter;
protected function setUp(): void
{
$this->dispositionRepository = $this->createMock(DispositionRepository::class);
$this->counter = new SeasonDispositionCounter(
$this->dispositionRepository,
new SeasonCalendar('11-01', '04-01'),
);
}
public function testCountsAreGroupedPerSeasonNewestFirstWithOffSeasonLast(): void
{
$this->stubDates([
'2024-12-10', // Saison 2024/25
'2025-02-01', // Saison 2024/25
'2024-01-15', // Saison 2023/24
'2025-07-20', // außerhalb der Saison
]);
$this->assertSame([
['label' => 'Saison 2024/25', 'count' => 2],
['label' => 'Saison 2023/24', 'count' => 1],
['label' => 'außerhalb der Saison', 'count' => 1],
], $this->counter->countPerSeason(new Teamer()));
}
public function testATeamerWithNoDispositionsYieldsNoRows(): void
{
$this->stubDates([]);
$this->assertSame([], $this->counter->countPerSeason(new Teamer()));
}
public function testOnlyOffSeasonDispositionsYieldASingleRow(): void
{
$this->stubDates(['2025-05-01', '2025-09-30']);
$this->assertSame([
['label' => 'außerhalb der Saison', 'count' => 2],
], $this->counter->countPerSeason(new Teamer()));
}
/**
* @param list<string> $dates
*/
private function stubDates(array $dates): void
{
$this->dispositionRepository
->method('findDispositionSeasonDatesByTeamer')
->willReturn(array_map(static fn (string $date): array => ['seasonDate' => $date], $dates))
;
}
}