72 lines
2.1 KiB
PHP
72 lines
2.1 KiB
PHP
<?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))
|
|
;
|
|
}
|
|
}
|