feat: consolidated insurance service

This commit is contained in:
Björn Fromme
2026-03-16 11:59:11 +01:00
parent 4f951cdf8a
commit a0d5768752
12 changed files with 681 additions and 545 deletions
@@ -9,24 +9,30 @@ use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Service\ParticipantInsuranceFieldHandler;
use App\Service\InsuranceMatchingService;
use App\Service\InsuranceTypeFilterService;
use App\Service\BookingPriceCalculatorService;
use App\Service\InsuranceService;
use PHPUnit\Framework\TestCase;
class ParticipantInsuranceFieldHandlerTest extends TestCase
{
private ParticipantInsuranceFieldHandler $handler;
private InsuranceMatchingService $insuranceMatchingService;
private InsuranceService $insuranceService;
private BookingPriceCalculatorService $priceCalculatorService;
protected function setUp(): void
{
$this->insuranceMatchingService = $this->createMock(InsuranceMatchingService::class);
$this->insuranceService = $this->createMock(InsuranceService::class);
$this->priceCalculatorService = $this->createMock(BookingPriceCalculatorService::class);
$insuranceTypeFilterService = $this->createMock(InsuranceTypeFilterService::class);
$insuranceTypeFilterService->method('filterNonComplementary')
->willReturnArgument(0);
// Mock getSelectableInsurances to return input array
$this->insuranceService->method('getSelectableInsurances')
->willReturnCallback(fn (Travel $travel) => $travel->insurances ?? []);
$this->handler = new ParticipantInsuranceFieldHandler($this->insuranceMatchingService, $insuranceTypeFilterService);
// Mock price calculator to return a default price
$this->priceCalculatorService->method('calculateIndividualParticipantPriceExcludingInsurance')
->willReturn(500.0);
$this->handler = new ParticipantInsuranceFieldHandler($this->insuranceService, $this->priceCalculatorService);
}
public function testGetFieldName(): void
@@ -85,8 +91,12 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
$participant = new ParticipantDto();
$participant->insurance = $this->createInsurance('123');
$travel = new Travel();
$travel->insurances = [];
$bookingDto = $this->createMockBookingDto();
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
$bookingDto->travel = $travel;
$this->handler->processField(['insurance' => null], $bookingDto, 0);
@@ -98,8 +108,12 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
$participant = new ParticipantDto();
$participant->insurance = $this->createInsurance('123');
$travel = new Travel();
$travel->insurances = [];
$bookingDto = $this->createMockBookingDto();
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
$bookingDto->travel = $travel;
$this->handler->processField(['insurance' => ''], $bookingDto, 0);
@@ -111,8 +125,12 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
$participant = new ParticipantDto();
$participant->insurance = $this->createInsurance('123');
$travel = new Travel();
$travel->insurances = [];
$bookingDto = $this->createMockBookingDto();
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
$bookingDto->travel = $travel;
$this->handler->processField([], $bookingDto, 0);
@@ -145,10 +163,10 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
$bookingDto->travel = $travel;
$this->insuranceMatchingService
$this->insuranceService
->expects($this->once())
->method('getEligibleInsurances')
->with([$insurance], $participant, $bookingDto)
->with([$insurance], $participant, $bookingDto, 500.0)
->willReturn([$insurance]);
$this->handler->processField(['insurance' => '123'], $bookingDto, 0);
@@ -167,10 +185,10 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
$bookingDto->travel = $travel;
$this->insuranceMatchingService
$this->insuranceService
->expects($this->once())
->method('getEligibleInsurances')
->with([$insurance], $participant, $bookingDto)
->with([$insurance], $participant, $bookingDto, 500.0)
->willReturn([]); // Not eligible
$this->handler->processField(['insurance' => '123'], $bookingDto, 0);
@@ -189,7 +207,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
$bookingDto->travel = $travel;
$this->insuranceMatchingService
$this->insuranceService
->expects($this->once())
->method('getEligibleInsurances')
->willReturn([$insurance]);