createService(); $bookingDto = $this->createBookingDto(); $this->expectException(ParticipantNotFoundException::class); $this->expectExceptionMessage('Participant at index 2 does not exist'); $service->ensureParticipantExists($bookingDto, 2); } public function testCreateParticipantEditDtoWrapsParticipant(): void { $service = $this->createService(); $bookingDto = $this->createBookingDto(); $wrapper = $service->createParticipantEditDto($bookingDto, 0); $this->assertSame($bookingDto, $wrapper->bookingContext); $this->assertSame($bookingDto->participants[0], $wrapper->participant); } public function testCollectAndClearNotificationsFlattensAndClearsNotifications(): void { $service = $this->createService(); $bookingDto = $this->createBookingDto(); $bookingDto->participants[0]->notifications = [ ['type' => 'info', 'message' => 'First'], ]; $bookingDto->participants[1]->notifications = [ ['type' => 'warning', 'message' => 'Second'], ]; $notifications = $service->collectAndClearNotifications($bookingDto); $this->assertSame([ ['type' => 'info', 'message' => 'First'], ['type' => 'warning', 'message' => 'Second'], ], $notifications); $this->assertSame([], $bookingDto->participants[0]->notifications); $this->assertSame([], $bookingDto->participants[1]->notifications); } public function testGetParticipantFormOptionsIncludesValidationToggle(): void { $bodyDimensionRanges = [ 'height_min' => 145, 'height_max' => 210, 'weight_min' => 40, 'weight_max' => 120, 'shoe_size_min' => 35, 'shoe_size_max' => 50, ]; $service = $this->createService(bodyDimensionRanges: $bodyDimensionRanges); $bookingDto = $this->createBookingDto(); $options = $service->getParticipantFormOptions($bookingDto, true); $this->assertSame($bookingDto, $options['booking_context']); $this->assertSame($bodyDimensionRanges, $options['body_dimension_ranges']); $this->assertContains('validation_groups', array_keys($options)); } /** * array|null $bodyDimensionRanges. */ public function testBlankTravellerKeepsTheRoomAssignmentAndDropsTheRest(): void { $previous = new ParticipantDto(); $previous->index = 0; $previous->assignedRoomId = 4711; $previous->firstName = 'Elternteil'; $previous->email = 'elternteil@example.com'; $previous->dateOfBirth = new \DateTimeImmutable('1981-03-16'); $traveller = $this->createService()->createBlankTravellerFrom($previous); $this->assertSame(0, $traveller->index); $this->assertSame(4711, $traveller->assignedRoomId); $this->assertNull($traveller->firstName); $this->assertNull($traveller->email); $this->assertNull( $traveller->dateOfBirth, 'The services were derived from an age that no longer applies to this slot' ); } public function testClearFamilyInsuranceRemovesOnlyFamilyPolicies(): void { $bookingDto = $this->createBookingDto(); $familyInsurance = new Insurance(); $familyInsurance->familyInsurance = true; $bookingDto->participants[0]->insurance = $familyInsurance; $bookingDto->participants[0]->bulkInsuranceBooking = true; $ordinaryInsurance = new Insurance(); $ordinaryInsurance->familyInsurance = false; $bookingDto->participants[1]->insurance = $ordinaryInsurance; $this->createService()->clearFamilyInsurance($bookingDto); $this->assertNull($bookingDto->participants[0]->insurance); $this->assertFalse($bookingDto->participants[0]->bulkInsuranceBooking); $this->assertSame( $ordinaryInsurance, $bookingDto->participants[1]->insurance, 'Only the family policy goes; an ordinary one is still valid on a split booking' ); } private function createService(?array $bodyDimensionRanges = null): ParticipantFormSupport { $bodyDimensionRanges ??= [ 'height_min' => 145, 'height_max' => 210, 'weight_min' => 40, 'weight_max' => 120, 'shoe_size_min' => 35, 'shoe_size_max' => 50, ]; return new ParticipantFormSupport($bodyDimensionRanges); } private function createBookingDto(): BookingDto { $travel = new Travel(); $travel->dateFrom = new \DateTimeImmutable('2030-01-01'); $travel->dateTo = new \DateTimeImmutable('2030-01-06'); $bookingDto = new BookingDto($travel, 157047); $bookingDto->booking = new Booking(); $participantOne = new ParticipantDto(); $participantOne->index = 0; $participantOne->dateOfBirth = new \DateTimeImmutable('1990-01-01'); $bookingDto->participants[0] = $participantOne; $participantTwo = new ParticipantDto(); $participantTwo->index = 1; $participantTwo->dateOfBirth = new \DateTimeImmutable('1995-01-01'); $bookingDto->participants[1] = $participantTwo; return $bookingDto; } }