provider = new CreateFieldStateProvider(new ParticipantEligibilityChecker( new ServiceAgeEvaluator(), new ServiceAvailabilityCalculator() )); } public function testDependentInsuranceFieldHidesWhenApplicantSelectsFamilyInsuranceThenReappearsAfterSwitch(): void { $travel = new Travel(); $travel->dateFrom = new \DateTimeImmutable('+30 days'); $travel->dateTo = new \DateTimeImmutable('+37 days'); $applicant = new ParticipantDto(); $applicant->index = 0; // Baby age (0-2 years at travel date) is always eligible regardless of skipass availability $applicant->dateOfBirth = $travel->dateFrom->modify('-1 year'); $dependent = new ParticipantDto(); $dependent->index = 1; $dependent->dateOfBirth = $travel->dateFrom->modify('-1 year'); $bookingDto = new BookingDto($travel, 1); $bookingDto->participants = [$applicant, $dependent]; $this->assertTrue( $this->provider->shouldIncludeField('insurance', $bookingDto, 1), 'Dependent should see their own insurance field before the applicant selects family insurance' ); $familyInsurance = new Insurance(); $familyInsurance->familyInsurance = true; $applicant->insurance = $familyInsurance; $this->assertFalse( $this->provider->shouldIncludeField('insurance', $bookingDto, 1), 'Dependent insurance field must be hidden once the applicant selects family insurance' ); $nonFamilyInsurance = new Insurance(); $nonFamilyInsurance->familyInsurance = false; $applicant->insurance = $nonFamilyInsurance; $this->assertTrue( $this->provider->shouldIncludeField('insurance', $bookingDto, 1), 'Dependent insurance field must reappear once the applicant switches away from family insurance' ); } }