From 199ef08e35feb640a379aa57f4eff20d406414e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 26 Sep 2025 16:48:48 +0200 Subject: [PATCH] wip: insurance booking phase 4 --- src/Form/Model/ParticipantDto.php | 34 ++++++++++ tests/Form/Model/ParticipantDtoTest.php | 82 +++++++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/src/Form/Model/ParticipantDto.php b/src/Form/Model/ParticipantDto.php index 4616e15..ddade64 100644 --- a/src/Form/Model/ParticipantDto.php +++ b/src/Form/Model/ParticipantDto.php @@ -2,6 +2,7 @@ namespace App\Form\Model; +use App\BusProNet\Model\Insurance; use App\BusProNet\Model\PersonalData; use App\BusProNet\Model\Pickup; use App\BusProNet\Model\Service; @@ -70,6 +71,9 @@ class ParticipantDto // License plate for participants with parking (optional, visible only when parking is selected) public ?string $licensePlate = null; + // Selected insurance for this participant (individual insurance selection per participant) + public ?Insurance $insurance = null; + public static function fromPersonalData(PersonalData $personalData): static { $instance = new static(); @@ -127,4 +131,34 @@ class ParticipantDto return $this->dateOfBirth->diff($referenceDate)->y; } + + /** + * Checks if the participant has selected an insurance. + * + * @return bool True if an insurance is selected + */ + public function hasInsurance(): bool + { + return null !== $this->insurance; + } + + /** + * Gets the insurance label for display purposes. + * + * @return string|null The insurance label or null if no insurance selected + */ + public function getInsuranceLabel(): ?string + { + return $this->insurance?->label; + } + + /** + * Gets the insurance price for pricing calculations. + * + * @return float The insurance price (0.0 if no insurance selected) + */ + public function getInsurancePrice(): float + { + return $this->insurance?->price ?? 0.0; + } } diff --git a/tests/Form/Model/ParticipantDtoTest.php b/tests/Form/Model/ParticipantDtoTest.php index 32cee75..e6a1c5b 100644 --- a/tests/Form/Model/ParticipantDtoTest.php +++ b/tests/Form/Model/ParticipantDtoTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Tests\Form\Model; +use App\BusProNet\Model\Insurance; use App\Form\Model\ParticipantDto; use PHPUnit\Framework\TestCase; @@ -122,4 +123,85 @@ class ParticipantDtoTest extends TestCase $this->assertEquals(84, $result); } + + public function testHasInsuranceReturnsFalseWhenNoInsuranceSelected(): void + { + $participant = new ParticipantDto(); + $participant->insurance = null; + + $result = $participant->hasInsurance(); + + $this->assertFalse($result); + } + + public function testHasInsuranceReturnsTrueWhenInsuranceSelected(): void + { + $participant = new ParticipantDto(); + $participant->insurance = $this->createInsurance(); + + $result = $participant->hasInsurance(); + + $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; + } }