feat: move scope of enforced 'option' status to full booking
addresses #869chtfeq
This commit is contained in:
@@ -18,7 +18,6 @@ use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\Service\ParticipantStatusRuleRegistry;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
@@ -53,8 +52,7 @@ class BookingDataProcessorTest extends TestCase
|
||||
// Create the new dependencies
|
||||
$mappingCollector = new ServiceMappingCollector();
|
||||
$serviceProcessor = new ParticipantServiceProcessor(new NullLogger());
|
||||
$statusRuleRegistry = new ParticipantStatusRuleRegistry([]);
|
||||
$payloadBuilder = new BookingPayloadBuilder($mappingCollector, $statusRuleRegistry);
|
||||
$payloadBuilder = new BookingPayloadBuilder($mappingCollector);
|
||||
$personalDataSynchronizer = new PersonalDataSynchronizer();
|
||||
|
||||
$this->processor = new BookingDataProcessor(
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\Service;
|
||||
|
||||
use App\BusProNet\Service\BookingStatusRuleRegistry;
|
||||
use App\BusProNet\Service\Contract\BookingStatusRuleInterface;
|
||||
use App\Form\Model\BookingDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BookingStatusRuleRegistryTest extends TestCase
|
||||
{
|
||||
public function testReturnsDefaultStatusWhenNoRulesMatch(): void
|
||||
{
|
||||
$rule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$rule->method('evaluate')->willReturn(false);
|
||||
$rule->method('getPriority')->willReturn(100);
|
||||
|
||||
$registry = new BookingStatusRuleRegistry([$rule]);
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
|
||||
$this->assertSame('F', $registry->evaluateStatus($bookingDto));
|
||||
}
|
||||
|
||||
public function testReturnsMatchingRuleStatus(): void
|
||||
{
|
||||
$rule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$rule->method('evaluate')->willReturn(true);
|
||||
$rule->method('getStatus')->willReturn('O');
|
||||
$rule->method('getPriority')->willReturn(100);
|
||||
|
||||
$registry = new BookingStatusRuleRegistry([$rule]);
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
|
||||
$this->assertSame('O', $registry->evaluateStatus($bookingDto));
|
||||
}
|
||||
|
||||
public function testHigherPriorityRuleTakesPrecedence(): void
|
||||
{
|
||||
$lowPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$lowPriorityRule->method('evaluate')->willReturn(true);
|
||||
$lowPriorityRule->method('getStatus')->willReturn('L');
|
||||
$lowPriorityRule->method('getPriority')->willReturn(50);
|
||||
|
||||
$highPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$highPriorityRule->method('evaluate')->willReturn(true);
|
||||
$highPriorityRule->method('getStatus')->willReturn('H');
|
||||
$highPriorityRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$registry = new BookingStatusRuleRegistry([$lowPriorityRule, $highPriorityRule]);
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
|
||||
$this->assertSame('H', $registry->evaluateStatus($bookingDto));
|
||||
}
|
||||
|
||||
public function testEmptyRulesArrayReturnsDefaultStatus(): void
|
||||
{
|
||||
$registry = new BookingStatusRuleRegistry([]);
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
|
||||
$this->assertSame('F', $registry->evaluateStatus($bookingDto));
|
||||
}
|
||||
|
||||
public function testFirstMatchingRuleWinsForSamePriority(): void
|
||||
{
|
||||
$firstMatchingRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$firstMatchingRule->method('evaluate')->willReturn(true);
|
||||
$firstMatchingRule->method('getStatus')->willReturn('A');
|
||||
$firstMatchingRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$secondMatchingRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$secondMatchingRule->method('evaluate')->willReturn(true);
|
||||
$secondMatchingRule->method('getStatus')->willReturn('B');
|
||||
$secondMatchingRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$registry = new BookingStatusRuleRegistry([$firstMatchingRule, $secondMatchingRule]);
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
|
||||
$this->assertSame('A', $registry->evaluateStatus($bookingDto));
|
||||
}
|
||||
|
||||
public function testNonMatchingHighPriorityRuleDoesNotBlockLowerPriority(): void
|
||||
{
|
||||
$highPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$highPriorityRule->method('evaluate')->willReturn(false);
|
||||
$highPriorityRule->method('getStatus')->willReturn('H');
|
||||
$highPriorityRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$lowPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$lowPriorityRule->method('evaluate')->willReturn(true);
|
||||
$lowPriorityRule->method('getStatus')->willReturn('L');
|
||||
$lowPriorityRule->method('getPriority')->willReturn(50);
|
||||
|
||||
$registry = new BookingStatusRuleRegistry([$highPriorityRule, $lowPriorityRule]);
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
|
||||
$this->assertSame('L', $registry->evaluateStatus($bookingDto));
|
||||
}
|
||||
|
||||
private function createMockTravel(): \App\BusProNet\Model\Travel
|
||||
{
|
||||
$travel = new \App\BusProNet\Model\Travel();
|
||||
$travel->id = 1;
|
||||
$travel->hotelId = 1;
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
|
||||
|
||||
return $travel;
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\Service;
|
||||
|
||||
use App\BusProNet\Service\Contract\ParticipantStatusRuleInterface;
|
||||
use App\BusProNet\Service\ParticipantStatusRuleRegistry;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantStatusRuleRegistryTest extends TestCase
|
||||
{
|
||||
public function testReturnsDefaultStatusWhenNoRulesMatch(): void
|
||||
{
|
||||
$rule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$rule->method('evaluate')->willReturn(false);
|
||||
$rule->method('getPriority')->willReturn(100);
|
||||
|
||||
$registry = new ParticipantStatusRuleRegistry([$rule]);
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->assertSame('F', $registry->evaluateStatus($participant));
|
||||
}
|
||||
|
||||
public function testReturnsMatchingRuleStatus(): void
|
||||
{
|
||||
$rule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$rule->method('evaluate')->willReturn(true);
|
||||
$rule->method('getStatus')->willReturn('O');
|
||||
$rule->method('getPriority')->willReturn(100);
|
||||
|
||||
$registry = new ParticipantStatusRuleRegistry([$rule]);
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->assertSame('O', $registry->evaluateStatus($participant));
|
||||
}
|
||||
|
||||
public function testHigherPriorityRuleTakesPrecedence(): void
|
||||
{
|
||||
$lowPriorityRule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$lowPriorityRule->method('evaluate')->willReturn(true);
|
||||
$lowPriorityRule->method('getStatus')->willReturn('L');
|
||||
$lowPriorityRule->method('getPriority')->willReturn(50);
|
||||
|
||||
$highPriorityRule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$highPriorityRule->method('evaluate')->willReturn(true);
|
||||
$highPriorityRule->method('getStatus')->willReturn('H');
|
||||
$highPriorityRule->method('getPriority')->willReturn(100);
|
||||
|
||||
// Register low priority first, high priority second
|
||||
$registry = new ParticipantStatusRuleRegistry([$lowPriorityRule, $highPriorityRule]);
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
// High priority rule should be evaluated first and match
|
||||
$this->assertSame('H', $registry->evaluateStatus($participant));
|
||||
}
|
||||
|
||||
public function testEmptyRulesArrayReturnsDefaultStatus(): void
|
||||
{
|
||||
$registry = new ParticipantStatusRuleRegistry([]);
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->assertSame('F', $registry->evaluateStatus($participant));
|
||||
}
|
||||
|
||||
public function testFirstMatchingRuleWins(): void
|
||||
{
|
||||
$firstMatchingRule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$firstMatchingRule->method('evaluate')->willReturn(true);
|
||||
$firstMatchingRule->method('getStatus')->willReturn('A');
|
||||
$firstMatchingRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$secondMatchingRule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$secondMatchingRule->method('evaluate')->willReturn(true);
|
||||
$secondMatchingRule->method('getStatus')->willReturn('B');
|
||||
$secondMatchingRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$registry = new ParticipantStatusRuleRegistry([$firstMatchingRule, $secondMatchingRule]);
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
// First rule with same priority registered first should win
|
||||
$this->assertSame('A', $registry->evaluateStatus($participant));
|
||||
}
|
||||
|
||||
public function testNonMatchingHighPriorityRuleDoesNotBlockLowerPriority(): void
|
||||
{
|
||||
$highPriorityRule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$highPriorityRule->method('evaluate')->willReturn(false);
|
||||
$highPriorityRule->method('getStatus')->willReturn('H');
|
||||
$highPriorityRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$lowPriorityRule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$lowPriorityRule->method('evaluate')->willReturn(true);
|
||||
$lowPriorityRule->method('getStatus')->willReturn('L');
|
||||
$lowPriorityRule->method('getPriority')->willReturn(50);
|
||||
|
||||
$registry = new ParticipantStatusRuleRegistry([$highPriorityRule, $lowPriorityRule]);
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
// High priority doesn't match, so low priority rule should be used
|
||||
$this->assertSame('L', $registry->evaluateStatus($participant));
|
||||
}
|
||||
|
||||
public function testMultipleRulesWithVariousPrioritiesAreSortedCorrectly(): void
|
||||
{
|
||||
$lowRule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$lowRule->method('evaluate')->willReturn(true);
|
||||
$lowRule->method('getStatus')->willReturn('LOW');
|
||||
$lowRule->method('getPriority')->willReturn(10);
|
||||
|
||||
$mediumRule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$mediumRule->method('evaluate')->willReturn(true);
|
||||
$mediumRule->method('getStatus')->willReturn('MED');
|
||||
$mediumRule->method('getPriority')->willReturn(50);
|
||||
|
||||
$highRule = $this->createMock(ParticipantStatusRuleInterface::class);
|
||||
$highRule->method('evaluate')->willReturn(true);
|
||||
$highRule->method('getStatus')->willReturn('HIGH');
|
||||
$highRule->method('getPriority')->willReturn(100);
|
||||
|
||||
// Register in random order
|
||||
$registry = new ParticipantStatusRuleRegistry([$mediumRule, $lowRule, $highRule]);
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
// Highest priority rule should match first
|
||||
$this->assertSame('HIGH', $registry->evaluateStatus($participant));
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@ 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;
|
||||
|
||||
@@ -20,99 +22,99 @@ class ChaperonServiceStatusRuleTest extends TestCase
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInAdditionalServices(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = $this->createBookingDtoWithParticipant();
|
||||
$service = new Service();
|
||||
$service->label = 'Skibegleitperson Kurs';
|
||||
$participant->additionalServices = [$service];
|
||||
$bookingDto->participants[0]->additionalServices = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
$this->assertTrue($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInCourses(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = $this->createBookingDtoWithParticipant();
|
||||
$service = new Service();
|
||||
$service->label = 'Begleitperson Anfängerkurs';
|
||||
$participant->courses = [$service];
|
||||
$service->label = 'Begleitperson Anfaengerkurs';
|
||||
$bookingDto->participants[0]->courses = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
$this->assertTrue($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInBoard(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = $this->createBookingDtoWithParticipant();
|
||||
$service = new Service();
|
||||
$service->label = 'Halbpension Begleitperson';
|
||||
$participant->board = [$service];
|
||||
$bookingDto->participants[0]->board = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
$this->assertTrue($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInRentals(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = $this->createBookingDtoWithParticipant();
|
||||
$service = new Service();
|
||||
$service->label = 'Skiset Begleitperson';
|
||||
$participant->rentals = [$service];
|
||||
$bookingDto->participants[0]->rentals = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
$this->assertTrue($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInSkiPass(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = $this->createBookingDtoWithParticipant();
|
||||
$service = new Service();
|
||||
$service->label = 'Skipass Begleitperson 6 Tage';
|
||||
$participant->skiPass = $service;
|
||||
$bookingDto->participants[0]->skiPass = $service;
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
$this->assertTrue($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInVeg(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = $this->createBookingDtoWithParticipant();
|
||||
$service = new Service();
|
||||
$service->label = 'Vegetarisch Begleitperson';
|
||||
$participant->veg = $service;
|
||||
$bookingDto->participants[0]->veg = $service;
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
$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
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = $this->createBookingDtoWithParticipant();
|
||||
$service = new Service();
|
||||
$service->label = 'Skipass 6 Tage Erwachsene';
|
||||
$participant->skiPass = $service;
|
||||
$bookingDto->participants[0]->skiPass = $service;
|
||||
|
||||
$this->assertFalse($this->rule->evaluate($participant));
|
||||
$this->assertFalse($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testReturnsFalseWithEmptyServices(): void
|
||||
public function testReturnsFalseWithEmptyParticipants(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = new BookingDto($this->createTravel(), 1);
|
||||
|
||||
$this->assertFalse($this->rule->evaluate($participant));
|
||||
$this->assertFalse($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testCaseInsensitiveMatch(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = $this->createBookingDtoWithParticipant();
|
||||
$service = new Service();
|
||||
$service->label = 'BEGLEITPERSON Kurs';
|
||||
$participant->additionalServices = [$service];
|
||||
$bookingDto->participants[0]->additionalServices = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testMixedCaseMatch(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'beGleitPerson Kurs';
|
||||
$participant->courses = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
$this->assertTrue($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testReturnsStatusO(): void
|
||||
@@ -133,28 +135,32 @@ class ChaperonServiceStatusRuleTest extends TestCase
|
||||
$this->assertNotEmpty($description);
|
||||
}
|
||||
|
||||
public function testHandlesNullLabel(): void
|
||||
private function createBookingDtoWithParticipant(): BookingDto
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = null;
|
||||
$participant->additionalServices = [$service];
|
||||
|
||||
$this->assertFalse($this->rule->evaluate($participant));
|
||||
return $this->createBookingDtoWithParticipantCount(1);
|
||||
}
|
||||
|
||||
public function testMultipleServicesWithOneBegleitperson(): void
|
||||
private function createBookingDtoWithParticipantCount(int $count): BookingDto
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$bookingDto = new BookingDto($this->createTravel(), 1);
|
||||
|
||||
$normalService = new Service();
|
||||
$normalService->label = 'Skipass 6 Tage';
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = $i;
|
||||
$bookingDto->participants[$i] = $participant;
|
||||
}
|
||||
|
||||
$begleitpersonService = new Service();
|
||||
$begleitpersonService->label = 'Skipass Begleitperson';
|
||||
return $bookingDto;
|
||||
}
|
||||
|
||||
$participant->additionalServices = [$normalService, $begleitpersonService];
|
||||
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');
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
return $travel;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user