feat: all-season assignments
This commit is contained in:
1 parent
675cec1b69
commit
cf876ed224
119 files changed
+6194
-294
No files matched your search
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service\Season;
|
||||
|
||||
use App\Config\SeasonTask;
|
||||
use App\Entity\SeasonAssignment;
|
||||
use App\Entity\SeasonAssignmentTask;
|
||||
use App\Service\Season\SeasonTaskDeadlineResolver;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Neither deadline is stored, so what is asserted here is the arithmetic every reminder, every
|
||||
* checklist row and the teamer's own page read - a deadline computed one day off is as silent a
|
||||
* failure as a reminder that never fires.
|
||||
*/
|
||||
class SeasonTaskDeadlineResolverTest extends TestCase
|
||||
{
|
||||
public function testTheFirstDeadlineIsTheOffsetAppliedToTheTravelStart(): void
|
||||
{
|
||||
$task = $this->task('2026-11-01');
|
||||
|
||||
$this->assertSame('2026-10-01', $this->resolver()->resolveFirst($task)?->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testTheOffsetComesFromTheParameter(): void
|
||||
{
|
||||
$task = $this->task('2026-11-01');
|
||||
|
||||
$this->assertSame(
|
||||
'2026-10-18',
|
||||
$this->resolver('-14 days')->resolveFirst($task)?->format('Y-m-d')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAnOverriddenFirstDeadlineWins(): void
|
||||
{
|
||||
$task = $this->task('2026-11-01')->setDeadlineOverride1(new \DateTimeImmutable('2026-09-15'));
|
||||
|
||||
$this->assertSame('2026-09-15', $this->resolver()->resolveFirst($task)?->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testTheSecondDeadlineDefaultsToTheFirst(): void
|
||||
{
|
||||
$task = $this->task('2026-11-01');
|
||||
|
||||
$this->assertSame('2026-10-01', $this->resolver()->resolveSecond($task)?->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testTheSecondDeadlineFollowsAnOverriddenFirstOne(): void
|
||||
{
|
||||
$task = $this->task('2026-11-01')->setDeadlineOverride1(new \DateTimeImmutable('2026-09-15'));
|
||||
|
||||
$this->assertSame('2026-09-15', $this->resolver()->resolveSecond($task)?->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testAnOverriddenSecondDeadlineWinsOverBoth(): void
|
||||
{
|
||||
$task = $this
|
||||
->task('2026-11-01')
|
||||
->setDeadlineOverride1(new \DateTimeImmutable('2026-09-15'))
|
||||
->setDeadlineOverride2(new \DateTimeImmutable('2026-10-20'))
|
||||
;
|
||||
|
||||
$this->assertSame('2026-09-15', $this->resolver()->resolveFirst($task)?->format('Y-m-d'));
|
||||
$this->assertSame('2026-10-20', $this->resolver()->resolveSecond($task)?->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testAnAssignmentWithoutAStartDateHasNoDeadlines(): void
|
||||
{
|
||||
$task = (new SeasonAssignmentTask())
|
||||
->setTaskKey(SeasonTask::CONTRACT->value)
|
||||
->setSeasonAssignment(new SeasonAssignment())
|
||||
;
|
||||
|
||||
$this->assertNull($this->resolver()->resolveFirst($task));
|
||||
$this->assertNull($this->resolver()->resolveSecond($task));
|
||||
}
|
||||
|
||||
private function resolver(string $offset = '-1 month'): SeasonTaskDeadlineResolver
|
||||
{
|
||||
return new SeasonTaskDeadlineResolver($offset);
|
||||
}
|
||||
|
||||
private function task(string $dateFrom): SeasonAssignmentTask
|
||||
{
|
||||
$seasonAssignment = (new SeasonAssignment())
|
||||
->setDateFrom(new \DateTimeImmutable($dateFrom))
|
||||
->setDateTo(new \DateTimeImmutable($dateFrom.' +5 months'))
|
||||
->setHotelCode('AGR')
|
||||
;
|
||||
|
||||
$task = (new SeasonAssignmentTask())->setTaskKey(SeasonTask::CONTRACT->value);
|
||||
$seasonAssignment->addTask($task);
|
||||
|
||||
return $task;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user