wip: insurance booking phases 1 and 2
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Model;
|
||||
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantDtoTest extends TestCase
|
||||
{
|
||||
public function testGetAgeReturnsNullWhenDateOfBirthIsNull(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$participant->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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user