feat: upgrade phpunit to 12.5
This commit is contained in:
1 parent
010cfe56b2
commit
5396cbb548
95 files changed
+1435
-1224
No files matched your search
@@ -12,32 +12,46 @@ use App\Form\Service\ParticipantInsuranceFieldHandler;
|
||||
use App\Service\BookingPriceCalculator;
|
||||
use App\Service\FamilyInsuranceAvailabilityChecker;
|
||||
use App\Service\InsuranceManager;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
{
|
||||
private ParticipantInsuranceFieldHandler $handler;
|
||||
private ?ParticipantInsuranceFieldHandler $handler = null;
|
||||
private InsuranceManager $insuranceService;
|
||||
private BookingPriceCalculator $priceCalculatorService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->insuranceService = $this->createMock(InsuranceManager::class);
|
||||
$this->priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$this->useInsuranceService($this->createStub(InsuranceManager::class));
|
||||
|
||||
// Mock getSelectableInsurances to return input array
|
||||
$this->insuranceService->method('getSelectableInsurances')
|
||||
->willReturnCallback(fn (Travel $travel) => $travel->insurances ?? []);
|
||||
$this->priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
|
||||
// Mock price calculator to return a default price
|
||||
// Price calculator returns a default price
|
||||
$this->priceCalculatorService->method('calculateIndividualParticipantPriceExcludingInsurance')
|
||||
->willReturn(500.0);
|
||||
$this->priceCalculatorService->method('resolveInsuranceTravelPrice')
|
||||
->willReturn(500.0);
|
||||
}
|
||||
|
||||
// Real checker over the mocked collaborators - the selection-time recording below is
|
||||
/**
|
||||
* Installs the insurance service every test runs against, applying the
|
||||
* getSelectableInsurances() pass-through they all rely on. Tests that set
|
||||
* expectations pass a mock in here instead of the setUp() stub.
|
||||
*/
|
||||
private function useInsuranceService(InsuranceManager&Stub $insuranceService): void
|
||||
{
|
||||
$insuranceService->method('getSelectableInsurances')
|
||||
->willReturnCallback(fn (Travel $travel) => $travel->insurances ?? []);
|
||||
|
||||
$this->insuranceService = $insuranceService;
|
||||
}
|
||||
|
||||
private function handler(): ParticipantInsuranceFieldHandler
|
||||
{
|
||||
// Real checker over the doubled collaborators - the selection-time recording below is
|
||||
// only meaningful against the actual "is a family insurance available" definition
|
||||
$this->handler = new ParticipantInsuranceFieldHandler(
|
||||
return $this->handler ??= new ParticipantInsuranceFieldHandler(
|
||||
$this->insuranceService,
|
||||
$this->priceCalculatorService,
|
||||
new FamilyInsuranceAvailabilityChecker($this->insuranceService, $this->priceCalculatorService),
|
||||
@@ -46,12 +60,12 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
|
||||
public function testGetFieldName(): void
|
||||
{
|
||||
$this->assertEquals('insurance', $this->handler->getFieldName());
|
||||
$this->assertEquals('insurance', $this->handler()->getFieldName());
|
||||
}
|
||||
|
||||
public function testGetDependencies(): void
|
||||
{
|
||||
$dependencies = $this->handler->getDependencies();
|
||||
$dependencies = $this->handler()->getDependencies();
|
||||
|
||||
// Insurance handler depends on all price-affecting fields to ensure accurate reassignment
|
||||
$expectedDependencies = [
|
||||
@@ -72,14 +86,14 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
|
||||
public function testShouldProcessReturnsTrueInCreateMode(): void
|
||||
{
|
||||
$result = $this->handler->shouldProcess([], BookingDto::MODE_CREATE, 0);
|
||||
$result = $this->handler()->shouldProcess([], BookingDto::MODE_CREATE, 0);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testShouldProcessReturnsFalseInEditMode(): void
|
||||
{
|
||||
$result = $this->handler->shouldProcess([], BookingDto::MODE_EDIT, 0);
|
||||
$result = $this->handler()->shouldProcess([], BookingDto::MODE_EDIT, 0);
|
||||
|
||||
$this->assertFalse($result, 'Insurance handler should not process in edit mode as API does not return insurance data');
|
||||
}
|
||||
@@ -89,7 +103,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
$bookingDto = $this->createMockBookingDto();
|
||||
$bookingDto->method('getParticipant')->with(0)->willReturn(null);
|
||||
|
||||
$this->handler->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
|
||||
// No assertions needed - just ensure no exceptions are thrown
|
||||
$this->addToAssertionCount(1);
|
||||
@@ -107,7 +121,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
|
||||
$bookingDto->travel = $travel;
|
||||
|
||||
$this->handler->processField(['insurance' => null], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => null], $bookingDto, 0);
|
||||
|
||||
$this->assertNull($participant->insurance);
|
||||
}
|
||||
@@ -124,7 +138,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
|
||||
$bookingDto->travel = $travel;
|
||||
|
||||
$this->handler->processField(['insurance' => ''], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => ''], $bookingDto, 0);
|
||||
|
||||
$this->assertNull($participant->insurance);
|
||||
}
|
||||
@@ -141,7 +155,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
|
||||
$bookingDto->travel = $travel;
|
||||
|
||||
$this->handler->processField([], $bookingDto, 0);
|
||||
$this->handler()->processField([], $bookingDto, 0);
|
||||
|
||||
$this->assertNull($participant->insurance);
|
||||
}
|
||||
@@ -156,13 +170,15 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
|
||||
$bookingDto->travel = $travel;
|
||||
|
||||
$this->handler->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
|
||||
$this->assertNull($participant->insurance);
|
||||
}
|
||||
|
||||
public function testProcessFieldSetsInsuranceWhenEligible(): void
|
||||
{
|
||||
$this->useInsuranceService($this->createMock(InsuranceManager::class));
|
||||
|
||||
$insurance = $this->createInsurance('123');
|
||||
$participant = new ParticipantDto();
|
||||
$travel = new Travel();
|
||||
@@ -178,13 +194,15 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
->with([$insurance], $participant, $bookingDto, 500.0)
|
||||
->willReturn([$insurance]);
|
||||
|
||||
$this->handler->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
|
||||
$this->assertSame($insurance, $participant->insurance);
|
||||
}
|
||||
|
||||
public function testProcessFieldClearsInsuranceWhenNotEligible(): void
|
||||
{
|
||||
$this->useInsuranceService($this->createMock(InsuranceManager::class));
|
||||
|
||||
$insurance = $this->createInsurance('123');
|
||||
$participant = new ParticipantDto();
|
||||
$travel = new Travel();
|
||||
@@ -200,13 +218,15 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
->with([$insurance], $participant, $bookingDto, 500.0)
|
||||
->willReturn([]); // Not eligible
|
||||
|
||||
$this->handler->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
|
||||
$this->assertNull($participant->insurance);
|
||||
}
|
||||
|
||||
public function testProcessFieldSwitchingToNewInsuranceIsNotOverwrittenByStaleResubmissionCheck(): void
|
||||
{
|
||||
$this->useInsuranceService($this->createMock(InsuranceManager::class));
|
||||
|
||||
// Regression: switching from one already-selected insurance to a different one must
|
||||
// not be re-validated (and potentially overwritten) against the OLD, now-stale
|
||||
// insurance by the "form resubmission" block afterward.
|
||||
@@ -230,13 +250,15 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
->method('getEligibleInsurances')
|
||||
->willReturn([$newInsurance]);
|
||||
|
||||
$this->handler->processField(['insurance' => '2'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '2'], $bookingDto, 0);
|
||||
|
||||
$this->assertSame($newInsurance, $participant->insurance);
|
||||
}
|
||||
|
||||
public function testProcessFieldWorksWithStringAndIntegerIds(): void
|
||||
{
|
||||
$this->useInsuranceService($this->createMock(InsuranceManager::class));
|
||||
|
||||
$insurance = $this->createInsurance(123); // Integer ID
|
||||
$participant = new ParticipantDto();
|
||||
$travel = new Travel();
|
||||
@@ -251,7 +273,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
->method('getEligibleInsurances')
|
||||
->willReturn([$insurance]);
|
||||
|
||||
$this->handler->processField(['insurance' => '123'], $bookingDto, 0); // String selection
|
||||
$this->handler()->processField(['insurance' => '123'], $bookingDto, 0); // String selection
|
||||
|
||||
$this->assertSame($insurance, $participant->insurance);
|
||||
}
|
||||
@@ -266,7 +288,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
|
||||
$bookingDto->travel = $travel;
|
||||
|
||||
$this->handler->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
|
||||
$this->assertNull($participant->insurance);
|
||||
}
|
||||
@@ -281,7 +303,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
$bookingDto->method('getParticipant')->with(0)->willReturn($participant);
|
||||
$bookingDto->travel = $travel;
|
||||
|
||||
$this->handler->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '123'], $bookingDto, 0);
|
||||
|
||||
$this->assertNull($participant->insurance);
|
||||
}
|
||||
@@ -306,7 +328,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
|
||||
$this->insuranceService->method('getEligibleInsurances')->willReturn([$nonFamilyInsurance]);
|
||||
|
||||
$this->handler->processField(['insurance' => '1'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '1'], $bookingDto, 0);
|
||||
|
||||
$this->assertTrue(
|
||||
$bookingDto->applicantInsuranceChosenWhileFamilyIneligible,
|
||||
@@ -346,7 +368,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
fn (array $insurances) => $insurances
|
||||
);
|
||||
|
||||
$this->handler->processField(['insurance' => '1'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '1'], $bookingDto, 0);
|
||||
|
||||
$this->assertFalse(
|
||||
$bookingDto->applicantInsuranceChosenWhileFamilyIneligible,
|
||||
@@ -389,7 +411,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
fn (array $insurances) => array_values(array_filter($insurances, fn ($i) => false === $i->familyInsurance))
|
||||
);
|
||||
|
||||
$this->handler->processField(['insurance' => '1'], $bookingDto, 0);
|
||||
$this->handler()->processField(['insurance' => '1'], $bookingDto, 0);
|
||||
|
||||
$this->assertTrue(
|
||||
$bookingDto->applicantInsuranceChosenWhileFamilyIneligible,
|
||||
@@ -399,9 +421,9 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
|
||||
public function testGetFieldStateModificationsReturnsEmptyArray(): void
|
||||
{
|
||||
$bookingDto = $this->createMockBookingDto();
|
||||
$bookingDto = $this->createStub(BookingDto::class);
|
||||
|
||||
$result = $this->handler->getFieldStateModifications([], $bookingDto, 0);
|
||||
$result = $this->handler()->getFieldStateModifications([], $bookingDto, 0);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertEmpty($result);
|
||||
@@ -409,7 +431,7 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
|
||||
public function testGetAffectedFieldNamesReturnsEmptyArray(): void
|
||||
{
|
||||
$result = $this->handler->getAffectedFieldNames();
|
||||
$result = $this->handler()->getAffectedFieldNames();
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertEmpty($result);
|
||||
|
||||
Reference in new issue
Block a user