feat: extensible participant status determination for booking creation

Adds a rule-based system to determine participant status in CREATE
payloads. Participants selecting a 'Begleitperson' service now receive
status 'O' (Option), all others default to 'F' (Final).

- Add ParticipantStatusRuleInterface for defining status rules
- Add ParticipantStatusRuleRegistry for priority-based rule evaluation
- Add ChaperonServiceStatusRule for Begleitperson detection
- Integrate status evaluation into BookingPayloadBuilder
This commit is contained in:
Björn Fromme
2026-03-16 12:02:59 +01:00
parent e1f1b60608
commit c1425f0562
10 changed files with 525 additions and 4 deletions
@@ -18,6 +18,7 @@ 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;
@@ -52,7 +53,8 @@ class BookingDataProcessorTest extends TestCase
// Create the new dependencies
$mappingCollector = new ServiceMappingCollector();
$serviceProcessor = new ParticipantServiceProcessor(new NullLogger());
$payloadBuilder = new BookingPayloadBuilder($mappingCollector);
$statusRuleRegistry = new ParticipantStatusRuleRegistry([]);
$payloadBuilder = new BookingPayloadBuilder($mappingCollector, $statusRuleRegistry);
$personalDataSynchronizer = new PersonalDataSynchronizer();
$this->processor = new BookingDataProcessor(
@@ -0,0 +1,129 @@
<?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));
}
}
@@ -0,0 +1,160 @@
<?php
declare(strict_types=1);
namespace App\Tests\BusProNet\Service\StatusRule;
use App\BusProNet\Model\Service;
use App\BusProNet\Service\StatusRule\ChaperonServiceStatusRule;
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
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = 'Skibegleitperson Kurs';
$participant->additionalServices = [$service];
$this->assertTrue($this->rule->evaluate($participant));
}
public function testReturnsTrueWhenBegleitpersonInCourses(): void
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = 'Begleitperson Anfängerkurs';
$participant->courses = [$service];
$this->assertTrue($this->rule->evaluate($participant));
}
public function testReturnsTrueWhenBegleitpersonInBoard(): void
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = 'Halbpension Begleitperson';
$participant->board = [$service];
$this->assertTrue($this->rule->evaluate($participant));
}
public function testReturnsTrueWhenBegleitpersonInRentals(): void
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = 'Skiset Begleitperson';
$participant->rentals = [$service];
$this->assertTrue($this->rule->evaluate($participant));
}
public function testReturnsTrueWhenBegleitpersonInSkiPass(): void
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = 'Skipass Begleitperson 6 Tage';
$participant->skiPass = $service;
$this->assertTrue($this->rule->evaluate($participant));
}
public function testReturnsTrueWhenBegleitpersonInVeg(): void
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = 'Vegetarisch Begleitperson';
$participant->veg = $service;
$this->assertTrue($this->rule->evaluate($participant));
}
public function testReturnsFalseWhenNoBegleitpersonService(): void
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = 'Skipass 6 Tage Erwachsene';
$participant->skiPass = $service;
$this->assertFalse($this->rule->evaluate($participant));
}
public function testReturnsFalseWithEmptyServices(): void
{
$participant = new ParticipantDto();
$this->assertFalse($this->rule->evaluate($participant));
}
public function testCaseInsensitiveMatch(): void
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = 'BEGLEITPERSON Kurs';
$participant->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));
}
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);
}
public function testHandlesNullLabel(): void
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = null;
$participant->additionalServices = [$service];
$this->assertFalse($this->rule->evaluate($participant));
}
public function testMultipleServicesWithOneBegleitperson(): void
{
$participant = new ParticipantDto();
$normalService = new Service();
$normalService->label = 'Skipass 6 Tage';
$begleitpersonService = new Service();
$begleitpersonService->label = 'Skipass Begleitperson';
$participant->additionalServices = [$normalService, $begleitpersonService];
$this->assertTrue($this->rule->evaluate($participant));
}
}