wip: insurance booking phase 4
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Form\Model;
|
namespace App\Form\Model;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Insurance;
|
||||||
use App\BusProNet\Model\PersonalData;
|
use App\BusProNet\Model\PersonalData;
|
||||||
use App\BusProNet\Model\Pickup;
|
use App\BusProNet\Model\Pickup;
|
||||||
use App\BusProNet\Model\Service;
|
use App\BusProNet\Model\Service;
|
||||||
@@ -70,6 +71,9 @@ class ParticipantDto
|
|||||||
// License plate for participants with parking (optional, visible only when parking is selected)
|
// License plate for participants with parking (optional, visible only when parking is selected)
|
||||||
public ?string $licensePlate = null;
|
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
|
public static function fromPersonalData(PersonalData $personalData): static
|
||||||
{
|
{
|
||||||
$instance = new static();
|
$instance = new static();
|
||||||
@@ -127,4 +131,34 @@ class ParticipantDto
|
|||||||
|
|
||||||
return $this->dateOfBirth->diff($referenceDate)->y;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Tests\Form\Model;
|
namespace App\Tests\Form\Model;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Insurance;
|
||||||
use App\Form\Model\ParticipantDto;
|
use App\Form\Model\ParticipantDto;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
@@ -122,4 +123,85 @@ class ParticipantDtoTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals(84, $result);
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user