id = 123; $skiPassService->subType = 'SPA'; $skiPassService->mapping = [0, 2]; // Assigned to participants 0 and 2 // Create a non-ski pass service $otherService = new Service(); $otherService->id = 456; $otherService->subType = 'OTHER'; $otherService->mapping = [0]; $booking->additionalServices = [ 123 => $skiPassService, 456 => $otherService, ]; // Test: participant 0 should get the ski pass $result = $booking->getSkiPassForParticipant(0); $this->assertSame($skiPassService, $result); $this->assertEquals(123, $result->id); // Test: participant 1 should get null (no ski pass assigned) $result = $booking->getSkiPassForParticipant(1); $this->assertNull($result); // Test: participant 2 should get the ski pass $result = $booking->getSkiPassForParticipant(2); $this->assertSame($skiPassService, $result); } public function testGetSkiPassForParticipantReturnsNullWhenNoSkiPasses(): void { $booking = new Booking(); // Only non-ski pass services $otherService = new Service(); $otherService->id = 456; $otherService->subType = 'COURSES'; $otherService->mapping = [0]; $booking->additionalServices = [456 => $otherService]; $result = $booking->getSkiPassForParticipant(0); $this->assertNull($result); } public function testGetSkiPassForParticipantReturnsNullWhenNoServices(): void { $booking = new Booking(); $booking->additionalServices = []; $result = $booking->getSkiPassForParticipant(0); $this->assertNull($result); } public function testGetInsuranceForParticipantReturnsCorrectInsurance(): void { $booking = new Booking(); // Create insurance for participants 0 and 2 $insurance1 = new Insurance(); $insurance1->id = '100'; $insurance1->label = 'Reiseschutz Platin'; $insurance1->mapping = [0, 2]; // Create insurance for participant 1 $insurance2 = new Insurance(); $insurance2->id = '200'; $insurance2->label = 'Reiseschutz Gold'; $insurance2->mapping = [1]; $booking->insurances = [ 100 => $insurance1, 200 => $insurance2, ]; // Test: participant 0 should get insurance1 $result = $booking->getInsuranceForParticipant(0); $this->assertSame($insurance1, $result); $this->assertEquals(100, $result->id); // Test: participant 1 should get insurance2 $result = $booking->getInsuranceForParticipant(1); $this->assertSame($insurance2, $result); $this->assertEquals(200, $result->id); // Test: participant 2 should get insurance1 $result = $booking->getInsuranceForParticipant(2); $this->assertSame($insurance1, $result); // Test: participant 3 should get null (no insurance assigned) $result = $booking->getInsuranceForParticipant(3); $this->assertNull($result); } public function testGetInsuranceForParticipantReturnsNullWhenNoInsurances(): void { $booking = new Booking(); $booking->insurances = []; $result = $booking->getInsuranceForParticipant(0); $this->assertNull($result); } public function testGetInsuranceForParticipantHandlesEmptyMapping(): void { $booking = new Booking(); // Create insurance with empty mapping $insurance = new Insurance(); $insurance->id = '100'; $insurance->label = 'Reiseschutz'; $insurance->mapping = []; $booking->insurances = [100 => $insurance]; $result = $booking->getInsuranceForParticipant(0); $this->assertNull($result, 'Should return null when mapping is empty'); } }