82 lines
2.4 KiB
PHP
82 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Form\Service\Condition;
|
|
|
|
use App\BusProNet\Model\Booking;
|
|
use App\BusProNet\Model\Travel;
|
|
use App\Form\Model\BookingDto;
|
|
use App\Form\Service\Condition\TravelStartCutoffReachedCondition;
|
|
use Carbon\CarbonImmutable;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class TravelStartCutoffReachedConditionTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
CarbonImmutable::setTestNow();
|
|
}
|
|
|
|
public function testEvaluateReturnsFalseBeforeCutoff(): void
|
|
{
|
|
CarbonImmutable::setTestNow('2026-01-05 10:00:00');
|
|
$condition = new TravelStartCutoffReachedCondition(4);
|
|
|
|
$result = $condition->evaluate($this->createCreateDto('2026-01-10 12:00:00'), 0, []);
|
|
|
|
$this->assertFalse($result);
|
|
}
|
|
|
|
public function testEvaluateReturnsTrueAtInclusiveCutoffBoundary(): void
|
|
{
|
|
CarbonImmutable::setTestNow('2026-01-06 01:00:00');
|
|
$condition = new TravelStartCutoffReachedCondition(4);
|
|
|
|
$result = $condition->evaluate($this->createCreateDto('2026-01-10 12:00:00'), 0, []);
|
|
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testEvaluateReturnsTrueAfterCutoff(): void
|
|
{
|
|
CarbonImmutable::setTestNow('2026-01-08 09:00:00');
|
|
$condition = new TravelStartCutoffReachedCondition(4);
|
|
|
|
$result = $condition->evaluate($this->createCreateDto('2026-01-10 12:00:00'), 0, []);
|
|
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testEvaluateReturnsTrueInEditModeAfterCutoff(): void
|
|
{
|
|
CarbonImmutable::setTestNow('2026-01-08 09:00:00');
|
|
$condition = new TravelStartCutoffReachedCondition(4);
|
|
|
|
$this->assertTrue($condition->evaluate($this->createEditDto('2026-01-10 12:00:00'), 0, []));
|
|
}
|
|
|
|
public function testConstructorThrowsForNegativeDays(): void
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
new TravelStartCutoffReachedCondition(-1);
|
|
}
|
|
|
|
private function createCreateDto(string $travelStartDate): BookingDto
|
|
{
|
|
$travel = new Travel();
|
|
$travel->dateFrom = new \DateTimeImmutable($travelStartDate);
|
|
|
|
return new BookingDto($travel, 1);
|
|
}
|
|
|
|
private function createEditDto(string $travelStartDate): BookingDto
|
|
{
|
|
$dto = $this->createCreateDto($travelStartDate);
|
|
$dto->booking = new Booking();
|
|
|
|
return $dto;
|
|
}
|
|
}
|