Files
myep-team/tests/Service/Season/SeasonAssignmentLabelerTest.php
T

74 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Service\Season;
use App\Config\HouseCatalog;
use App\Config\SeasonCalendar;
use App\Entity\SeasonAssignment;
use App\Service\Season\SeasonAssignmentLabeler;
use PHPUnit\Framework\TestCase;
/**
* Every list, dialog, log line and mail names a placement through this one class, so what it
* produces in the awkward cases - no dates yet, a date outside any season, a house that has left
* the configured map - is what the office would see there.
*/
class SeasonAssignmentLabelerTest extends TestCase
{
public function testItNamesTheSeasonAndTheHouse(): void
{
$this->assertSame(
'Saison 2026/27 - Rotbach',
$this->labeler()->label($this->seasonAssignment('2026-11-01', 'AGR'))
);
}
/**
* The season window is 01.11.-01.04., so a placement starting in July belongs to no season.
* It still has to name itself rather than render blank.
*/
public function testAPlacementOutsideAnySeasonSaysSo(): void
{
$this->assertSame(
'außerhalb der Saison - Rotbach',
$this->labeler()->label($this->seasonAssignment('2027-07-15', 'AGR'))
);
}
public function testAHalfFilledRecordStillNamesItself(): void
{
$this->assertSame('? - ?', $this->labeler()->label(new SeasonAssignment()));
}
/**
* The houses map is curated and can lose an entry; a placement that named that house falls
* back to the raw code rather than losing its name.
*/
public function testACodeThatLeftTheMapFallsBackToTheCode(): void
{
$this->assertSame(
'Saison 2026/27 - XYZ',
$this->labeler()->label($this->seasonAssignment('2026-11-01', 'XYZ'))
);
}
private function labeler(): SeasonAssignmentLabeler
{
return new SeasonAssignmentLabeler(
new SeasonCalendar('11-01', '04-01'),
new HouseCatalog(['AGR' => 'Rotbach'])
);
}
private function seasonAssignment(string $dateFrom, string $hotelCode): SeasonAssignment
{
return (new SeasonAssignment())
->setDateFrom(new \DateTimeImmutable($dateFrom))
->setDateTo(new \DateTimeImmutable($dateFrom.' +5 months'))
->setHotelCode($hotelCode)
;
}
}