dateOfBirth = null; $this->assertNull($participant->getAge()); } public function testGetAgeCalculatesCurrentAgeWhenNoReferenceDateProvided(): void { $participant = new ParticipantDto(); $participant->dateOfBirth = new \DateTimeImmutable('1990-06-15'); $expectedAge = (new \DateTimeImmutable())->diff($participant->dateOfBirth)->y; $actualAge = $participant->getAge(); $this->assertEquals($expectedAge, $actualAge); } public function testGetAgeCalculatesAgeAtSpecificReferenceDate(): void { $participant = new ParticipantDto(); $participant->dateOfBirth = new \DateTimeImmutable('1990-06-15'); $referenceDate = new \DateTimeImmutable('2024-06-14'); // Day before 34th birthday $result = $participant->getAge($referenceDate); $this->assertEquals(33, $result); // Still 33 years old } public function testGetAgeCalculatesAgeAtSpecificReferenceDateAfterBirthday(): void { $participant = new ParticipantDto(); $participant->dateOfBirth = new \DateTimeImmutable('1990-06-15'); $referenceDate = new \DateTimeImmutable('2024-06-15'); // Exactly 34th birthday $result = $participant->getAge($referenceDate); $this->assertEquals(34, $result); // Now 34 years old } public function testGetAgeCalculatesAgeForInsuranceEligibilityScenario(): void { // Travel starts on 2024-08-01, participant born 1989-12-25 $participant = new ParticipantDto(); $participant->dateOfBirth = new \DateTimeImmutable('1989-12-25'); $travelStartDate = new \DateTimeImmutable('2024-08-01'); $result = $participant->getAge($travelStartDate); // On 2024-08-01, they are still 34 (birthday not yet reached) $this->assertEquals(34, $result); } public function testGetAgeCalculatesAgeForInsuranceEligibilityScenarioAfterBirthday(): void { // Travel starts on 2024-12-26, participant born 1989-12-25 $participant = new ParticipantDto(); $participant->dateOfBirth = new \DateTimeImmutable('1989-12-25'); $travelStartDate = new \DateTimeImmutable('2024-12-26'); $result = $participant->getAge($travelStartDate); // On 2024-12-26, they just turned 35 $this->assertEquals(35, $result); } public function testGetAgeHandlesLeapYearScenarios(): void { // Born on Feb 29, 2000 (leap year) $participant = new ParticipantDto(); $participant->dateOfBirth = new \DateTimeImmutable('2000-02-29'); $referenceDate = new \DateTimeImmutable('2023-02-28'); // Non-leap year $result = $participant->getAge($referenceDate); $this->assertEquals(22, $result); // Still 22, birthday is technically next day } public function testGetAgeReturnsNullWithReferenceDateWhenDateOfBirthIsNull(): void { $participant = new ParticipantDto(); $participant->dateOfBirth = null; $referenceDate = new \DateTimeImmutable('2024-08-01'); $result = $participant->getAge($referenceDate); $this->assertNull($result); } public function testGetAgeWithYoungParticipant(): void { // Child born in 2020 $participant = new ParticipantDto(); $participant->dateOfBirth = new \DateTimeImmutable('2020-03-15'); $referenceDate = new \DateTimeImmutable('2024-08-01'); $result = $participant->getAge($referenceDate); $this->assertEquals(4, $result); } public function testGetAgeWithElderlyParticipant(): void { // Elderly participant born in 1940 $participant = new ParticipantDto(); $participant->dateOfBirth = new \DateTimeImmutable('1940-05-20'); $referenceDate = new \DateTimeImmutable('2024-08-01'); $result = $participant->getAge($referenceDate); $this->assertEquals(84, $result); } public function testHasInsuranceReturnsFalseWhenNoInsuranceSelected(): void { $participant = new ParticipantDto(); $participant->insurance = null; $result = $participant->hasInsuranceSelected(); $this->assertFalse($result); } public function testHasInsuranceReturnsTrueWhenInsuranceSelected(): void { $participant = new ParticipantDto(); $participant->insurance = $this->createInsurance(); $result = $participant->hasInsuranceSelected(); $this->assertTrue($result); } public function testGetInsuranceLabelReturnsNullWhenNoInsurance(): void { $participant = new ParticipantDto(); $participant->insurance = null; $result = $participant->getInsuranceLabel(); $this->assertNull($result); } public function testGetInsuranceLabelReturnsLabelWhenInsuranceSelected(): void { $participant = new ParticipantDto(); $participant->insurance = $this->createInsurance('Reise-Rücktritt'); $result = $participant->getInsuranceLabel(); $this->assertEquals('Reise-Rücktritt', $result); } public function testGetInsurancePriceReturnsZeroWhenNoInsurance(): void { $participant = new ParticipantDto(); $participant->insurance = null; $result = $participant->getInsurancePrice(); $this->assertEquals(0.0, $result); } public function testGetInsurancePriceReturnsPriceWhenInsuranceSelected(): void { $participant = new ParticipantDto(); $participant->insurance = $this->createInsurance('Travel Insurance', 25.50); $result = $participant->getInsurancePrice(); $this->assertEquals(25.50, $result); } public function testGetInsurancePriceReturnsZeroWhenInsuranceHasNullPrice(): void { $participant = new ParticipantDto(); $insurance = $this->createInsurance('Free Insurance'); $insurance->price = null; $participant->insurance = $insurance; $result = $participant->getInsurancePrice(); $this->assertEquals(0.0, $result); } private function createInsurance(string $label = 'Test Insurance', float $price = 10.0): Insurance { $insurance = new Insurance(); $insurance->label = $label; $insurance->price = $price; return $insurance; } }