Files
myep/tests/BusProNet/Service/StatusRule/ChaperonServiceStatusRuleTest.php
T
2026-03-19 16:15:07 +01:00

167 lines
5.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\BusProNet\Service\StatusRule;
use App\BusProNet\Model\Service;
use App\BusProNet\Model\Travel;
use App\BusProNet\Service\StatusRule\ChaperonServiceStatusRule;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use PHPUnit\Framework\TestCase;
class ChaperonServiceStatusRuleTest extends TestCase
{
private ChaperonServiceStatusRule $rule;
protected function setUp(): void
{
$this->rule = new ChaperonServiceStatusRule();
}
public function testReturnsTrueWhenBegleitpersonInAdditionalServices(): void
{
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Skibegleitperson Kurs';
$bookingDto->participants[0]->additionalServices = [$service];
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInCourses(): void
{
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Begleitperson Anfaengerkurs';
$bookingDto->participants[0]->courses = [$service];
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInBoard(): void
{
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Halbpension Begleitperson';
$bookingDto->participants[0]->board = [$service];
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInRentals(): void
{
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Skiset Begleitperson';
$bookingDto->participants[0]->rentals = [$service];
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInSkiPass(): void
{
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Skipass Begleitperson 6 Tage';
$bookingDto->participants[0]->skiPass = $service;
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInVeg(): void
{
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Vegetarisch Begleitperson';
$bookingDto->participants[0]->veg = $service;
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenSecondParticipantMatches(): void
{
$bookingDto = $this->createBookingDtoWithParticipantCount(2);
$service = new Service();
$service->label = 'Begleitperson Service';
$bookingDto->participants[1]->additionalServices = [$service];
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsFalseWhenNoBegleitpersonService(): void
{
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Skipass 6 Tage Erwachsene';
$bookingDto->participants[0]->skiPass = $service;
$this->assertFalse($this->rule->evaluate($bookingDto));
}
public function testReturnsFalseWithEmptyParticipants(): void
{
$bookingDto = new BookingDto($this->createTravel(), 1);
$this->assertFalse($this->rule->evaluate($bookingDto));
}
public function testCaseInsensitiveMatch(): void
{
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'BEGLEITPERSON Kurs';
$bookingDto->participants[0]->additionalServices = [$service];
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsStatusO(): void
{
$this->assertSame('O', $this->rule->getStatus());
}
public function testGetPriorityReturns100(): void
{
$this->assertSame(100, $this->rule->getPriority());
}
public function testGetDescriptionReturnsNonEmptyString(): void
{
$description = $this->rule->getDescription();
$this->assertIsString($description);
$this->assertNotEmpty($description);
}
private function createBookingDtoWithParticipant(): BookingDto
{
return $this->createBookingDtoWithParticipantCount(1);
}
private function createBookingDtoWithParticipantCount(int $count): BookingDto
{
$bookingDto = new BookingDto($this->createTravel(), 1);
for ($i = 0; $i < $count; ++$i) {
$participant = new ParticipantDto();
$participant->index = $i;
$bookingDto->participants[$i] = $participant;
}
return $bookingDto;
}
private function createTravel(): Travel
{
$travel = new Travel();
$travel->id = 1;
$travel->hotelId = 1;
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
return $travel;
}
}