feat: upgrade phpunit to 12.5
This commit is contained in:
@@ -52,7 +52,7 @@ class AccommodationBookingChangeAccommodationTypeTest extends TestCase
|
||||
{
|
||||
$fields = [];
|
||||
|
||||
$builder = $this->createMock(FormBuilderInterface::class);
|
||||
$builder = $this->createStub(FormBuilderInterface::class);
|
||||
$builder->method('add')->willReturnCallback(
|
||||
static function (string $name, ?string $type = null, array $fieldOptions = []) use (&$fields, $builder) {
|
||||
$fields[$name] = $fieldOptions;
|
||||
|
||||
@@ -75,7 +75,7 @@ class AccommodationBookingCreateTypeTest extends TestCase
|
||||
{
|
||||
$names = [];
|
||||
|
||||
$builder = $this->createMock(FormBuilderInterface::class);
|
||||
$builder = $this->createStub(FormBuilderInterface::class);
|
||||
$builder->method('add')->willReturnCallback(static function (string $name) use (&$names, $builder) {
|
||||
$names[] = $name;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Tests\Form\Admin\Groups;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Form\Admin\Groups\AccommodationBookingType;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@@ -17,17 +18,13 @@ use Symfony\Component\Validator\Validation;
|
||||
|
||||
class AccommodationBookingTypeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider statusesWithoutMandatoryFields
|
||||
*/
|
||||
#[DataProvider('statusesWithoutMandatoryFields')]
|
||||
public function testDraftAndDiscardedAreValidatedWithoutTheEditGroup(AccommodationBookingStatus $status): void
|
||||
{
|
||||
self::assertSame(['Default'], $this->resolveValidationGroups($status));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider customerFacingStatuses
|
||||
*/
|
||||
#[DataProvider('customerFacingStatuses')]
|
||||
public function testCustomerFacingStatusesAddTheEditGroup(AccommodationBookingStatus $status): void
|
||||
{
|
||||
self::assertSame(['Default', 'edit'], $this->resolveValidationGroups($status));
|
||||
@@ -52,9 +49,7 @@ class AccommodationBookingTypeTest extends TestCase
|
||||
yield 'confirmed' => [AccommodationBookingStatus::Confirmed];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider statusesWithoutMandatoryFields
|
||||
*/
|
||||
#[DataProvider('statusesWithoutMandatoryFields')]
|
||||
public function testEmptyContactDataPassesValidation(AccommodationBookingStatus $status): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
@@ -89,7 +84,7 @@ class AccommodationBookingTypeTest extends TestCase
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus($status);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form = $this->createStub(FormInterface::class);
|
||||
$form->method('getData')->willReturn($booking);
|
||||
|
||||
return ($resolver->resolve()['validation_groups'])($form);
|
||||
|
||||
@@ -5,13 +5,13 @@ declare(strict_types=1);
|
||||
namespace App\Tests\Form\Model;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Address;
|
||||
use App\Form\Model\AddressDto;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||
use App\Form\Model\AddressDto;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Model\ParticipantEditDto;
|
||||
@@ -47,10 +47,10 @@ class ParticipantEditDtoTest extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
// Create mock services for validator dependencies
|
||||
$mockVoucherService = $this->createMock(VoucherValidator::class);
|
||||
$mockPriceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$mockParticipantEligibilityChecker = $this->createMock(ParticipantEligibilityChecker::class);
|
||||
$mockServiceAgeEvaluator = $this->createMock(ServiceAgeEvaluator::class);
|
||||
$mockVoucherService = $this->createStub(VoucherValidator::class);
|
||||
$mockPriceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
$mockParticipantEligibilityChecker = $this->createStub(ParticipantEligibilityChecker::class);
|
||||
$mockServiceAgeEvaluator = $this->createStub(ServiceAgeEvaluator::class);
|
||||
|
||||
// Ski pass validation is exercised against the real gate, not a mock: which participant
|
||||
// needs a pass is exactly the behaviour under test here.
|
||||
|
||||
@@ -91,7 +91,7 @@ class PersonalDataTypeTest extends TestCase
|
||||
*/
|
||||
private function createForm(PersonalData $personalData, array $options = []): FormInterface
|
||||
{
|
||||
$countries = $this->createMock(CountryDataProvider::class);
|
||||
$countries = $this->createStub(CountryDataProvider::class);
|
||||
$countries->method('getAll')->willReturn([]);
|
||||
|
||||
return Forms::createFormFactoryBuilder()
|
||||
|
||||
@@ -28,17 +28,17 @@ class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
$this->serviceAvailabilityCalculator = $this->createStub(ServiceAvailabilityCalculator::class);
|
||||
// These tests target age filtering, so availability filtering passes everything through
|
||||
// unless a test stubs it explicitly
|
||||
$this->serviceAvailabilityCalculator
|
||||
->method('filterAvailableServices')
|
||||
->willReturnArgument(0)
|
||||
;
|
||||
$insuranceService = $this->createMock(InsuranceManager::class);
|
||||
$priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$insuranceService = $this->createStub(InsuranceManager::class);
|
||||
$priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
$serviceLabelFormatter = new ServiceLabelFormatter();
|
||||
$translator = $this->createMock(TranslatorInterface::class);
|
||||
$translator = $this->createStub(TranslatorInterface::class);
|
||||
$translator->method('trans')->willReturnCallback(
|
||||
function (string $message, array $parameters = []): string {
|
||||
return match ($message) {
|
||||
|
||||
@@ -29,13 +29,13 @@ class ParticipantFieldOptionsProviderInsuranceTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
$serviceAvailabilityCalculator = $this->createStub(ServiceAvailabilityCalculator::class);
|
||||
// InsuranceManager is stateless - use the real implementation so actual
|
||||
// eligibility/price-tier filtering runs, not a stubbed-out mock.
|
||||
$insuranceService = new InsuranceManager();
|
||||
$this->priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$this->priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
$serviceLabelFormatter = new ServiceLabelFormatter();
|
||||
$translator = $this->createMock(TranslatorInterface::class);
|
||||
$translator = $this->createStub(TranslatorInterface::class);
|
||||
$translator->method('trans')->willReturnCallback(fn (string $message) => $message);
|
||||
|
||||
$this->provider = new ParticipantFieldOptionsProvider(
|
||||
|
||||
@@ -28,11 +28,11 @@ class ParticipantFieldOptionsProviderMandatoryServiceTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
$insuranceService = $this->createMock(InsuranceManager::class);
|
||||
$priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$serviceAvailabilityCalculator = $this->createStub(ServiceAvailabilityCalculator::class);
|
||||
$insuranceService = $this->createStub(InsuranceManager::class);
|
||||
$priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
$serviceLabelFormatter = new ServiceLabelFormatter();
|
||||
$translator = $this->createMock(TranslatorInterface::class);
|
||||
$translator = $this->createStub(TranslatorInterface::class);
|
||||
|
||||
$this->provider = new ParticipantFieldOptionsProvider(
|
||||
$serviceAvailabilityCalculator,
|
||||
@@ -159,10 +159,10 @@ class ParticipantFieldOptionsProviderMandatoryServiceTest extends TestCase
|
||||
|
||||
$provider = new ParticipantFieldOptionsProvider(
|
||||
$serviceAvailabilityCalculator,
|
||||
$this->createMock(InsuranceManager::class),
|
||||
$this->createMock(BookingPriceCalculator::class),
|
||||
$this->createStub(InsuranceManager::class),
|
||||
$this->createStub(BookingPriceCalculator::class),
|
||||
new ServiceLabelFormatter(),
|
||||
$this->createMock(TranslatorInterface::class)
|
||||
$this->createStub(TranslatorInterface::class)
|
||||
);
|
||||
|
||||
$options = $provider->getFieldOptions('parking', $bookingDto, 0);
|
||||
|
||||
@@ -30,13 +30,13 @@ class ParticipantFieldOptionsProviderSkiPassAvailabilityTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$translator = $this->createMock(TranslatorInterface::class);
|
||||
$translator = $this->createStub(TranslatorInterface::class);
|
||||
$translator->method('trans')->willReturnArgument(0);
|
||||
|
||||
$this->provider = new ParticipantFieldOptionsProvider(
|
||||
new ServiceAvailabilityCalculator(),
|
||||
$this->createMock(InsuranceManager::class),
|
||||
$this->createMock(BookingPriceCalculator::class),
|
||||
$this->createStub(InsuranceManager::class),
|
||||
$this->createStub(BookingPriceCalculator::class),
|
||||
new ServiceLabelFormatter(),
|
||||
$translator
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -4,14 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Service;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\BusProNet\Constants;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\ParticipantParkingFieldHandler;
|
||||
use App\Service\ServiceAvailabilityCalculator;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
@@ -39,17 +40,13 @@ class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
$this->assertTrue($this->handler->shouldProcess(['some' => 'data'], BookingDto::MODE_EDIT, 5));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider normalizeCheckboxValueCheckedProvider
|
||||
*/
|
||||
#[DataProvider('normalizeCheckboxValueCheckedProvider')]
|
||||
public function testNormalizeCheckboxValueReturnsTrueWhenChecked(mixed $value): void
|
||||
{
|
||||
$this->assertTrue($this->invokeNormalizeCheckboxValue($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider normalizeCheckboxValueUncheckedProvider
|
||||
*/
|
||||
#[DataProvider('normalizeCheckboxValueUncheckedProvider')]
|
||||
public function testNormalizeCheckboxValueReturnsFalseWhenUnchecked(mixed $value): void
|
||||
{
|
||||
$this->assertFalse($this->invokeNormalizeCheckboxValue($value));
|
||||
|
||||
+35
-19
@@ -15,31 +15,35 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestCase
|
||||
{
|
||||
private ParticipantTransportationDiscountReplacementFieldHandler $handler;
|
||||
private ?ParticipantTransportationDiscountReplacementFieldHandler $handler = null;
|
||||
private ServiceAvailabilityCalculator $serviceAvailabilityCalculator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
$this->handler = new ParticipantTransportationDiscountReplacementFieldHandler(
|
||||
$this->serviceAvailabilityCalculator = $this->createStub(ServiceAvailabilityCalculator::class);
|
||||
}
|
||||
|
||||
private function handler(): ParticipantTransportationDiscountReplacementFieldHandler
|
||||
{
|
||||
return $this->handler ??= new ParticipantTransportationDiscountReplacementFieldHandler(
|
||||
$this->serviceAvailabilityCalculator
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetFieldName(): void
|
||||
{
|
||||
$this->assertSame('transportationDiscountReplacement', $this->handler->getFieldName());
|
||||
$this->assertSame('transportationDiscountReplacement', $this->handler()->getFieldName());
|
||||
}
|
||||
|
||||
public function testGetDependencies(): void
|
||||
{
|
||||
$this->assertSame(['transportationOutbound', 'transportationInbound'], $this->handler->getDependencies());
|
||||
$this->assertSame(['transportationOutbound', 'transportationInbound'], $this->handler()->getDependencies());
|
||||
}
|
||||
|
||||
public function testShouldProcessAlwaysReturnsTrue(): void
|
||||
{
|
||||
$this->assertTrue($this->handler->shouldProcess([], BookingDto::MODE_CREATE, 0));
|
||||
$this->assertTrue($this->handler->shouldProcess(['some' => 'data'], BookingDto::MODE_EDIT, 5));
|
||||
$this->assertTrue($this->handler()->shouldProcess([], BookingDto::MODE_CREATE, 0));
|
||||
$this->assertTrue($this->handler()->shouldProcess(['some' => 'data'], BookingDto::MODE_EDIT, 5));
|
||||
}
|
||||
|
||||
public function testProcessFieldReplacesDiscountedWithRegularWhenInboundIsBus(): void
|
||||
@@ -62,7 +66,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound was replaced with regular PKW
|
||||
$this->assertSame($regularPkw->id, $participant->transportationOutbound->id);
|
||||
@@ -79,6 +83,8 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
|
||||
public function testProcessFieldRestoresDiscountedPkwWhenInboundChangesToPkw(): void
|
||||
{
|
||||
$this->serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
|
||||
// Setup services
|
||||
$discountedPkw = $this->createPkwService(100, 'Selbstorganisiert (-15€ Rabatt)', -15.0);
|
||||
$regularPkw = $this->createPkwService(101, 'Selbstorganisiert', 0.0);
|
||||
@@ -104,7 +110,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound was replaced with discounted PKW
|
||||
$this->assertSame($discountedPkw->id, $participant->transportationOutbound->id);
|
||||
@@ -120,6 +126,8 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
|
||||
public function testProcessFieldDoesNotRestoreDiscountWhenUnavailable(): void
|
||||
{
|
||||
$this->serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
|
||||
// Setup services
|
||||
$discountedPkw = $this->createPkwService(100, 'Selbstorganisiert (-15€ Rabatt)', -15.0);
|
||||
$regularPkw = $this->createPkwService(101, 'Selbstorganisiert', 0.0);
|
||||
@@ -145,7 +153,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound remains regular PKW
|
||||
$this->assertSame($regularPkw, $participant->transportationOutbound);
|
||||
@@ -174,7 +182,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound remains BUS (no replacement)
|
||||
$this->assertSame($busOutbound, $participant->transportationOutbound);
|
||||
@@ -203,7 +211,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound remains regular PKW (already correct)
|
||||
$this->assertSame($regularPkw, $participant->transportationOutbound);
|
||||
@@ -232,7 +240,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound remains discounted PKW (already optimal)
|
||||
$this->assertSame($discountedPkw, $participant->transportationOutbound);
|
||||
@@ -256,7 +264,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process - should handle gracefully
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert no error and no notification
|
||||
$this->assertNull($participant->transportationOutbound);
|
||||
@@ -265,6 +273,8 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
|
||||
public function testProcessFieldHandlesNullInbound(): void
|
||||
{
|
||||
$this->serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
|
||||
// Setup services
|
||||
$discountedPkw = $this->createPkwService(100, 'Selbstorganisiert (-15€ Rabatt)', -15.0);
|
||||
$regularPkw = $this->createPkwService(101, 'Selbstorganisiert', 0.0);
|
||||
@@ -289,7 +299,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process - null inbound is treated as non-BUS, should attempt restoration
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound was replaced with discounted PKW
|
||||
$this->assertSame($discountedPkw->id, $participant->transportationOutbound->id);
|
||||
@@ -306,7 +316,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process - should handle gracefully
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Should not throw error
|
||||
$this->expectNotToPerformAssertions();
|
||||
@@ -314,6 +324,8 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
|
||||
public function testProcessFieldSkipsDiscountRestorationForBabyParticipant(): void
|
||||
{
|
||||
$this->serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
|
||||
// Setup services
|
||||
$discountedPkw = $this->createPkwService(100, 'Selbstorganisiert (-15€ Rabatt)', -15.0);
|
||||
$regularPkw = $this->createPkwService(101, 'Selbstorganisiert', 0.0);
|
||||
@@ -339,7 +351,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound remains regular PKW (no discount restoration for babies)
|
||||
$this->assertSame($regularPkw->id, $participant->transportationOutbound->id);
|
||||
@@ -350,6 +362,8 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
|
||||
public function testProcessFieldSkipsDiscountRestorationForTwoYearOldParticipant(): void
|
||||
{
|
||||
$this->serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
|
||||
// Setup services
|
||||
$discountedPkw = $this->createPkwService(100, 'Selbstorganisiert (-15€ Rabatt)', -15.0);
|
||||
$regularPkw = $this->createPkwService(101, 'Selbstorganisiert', 0.0);
|
||||
@@ -375,7 +389,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound remains regular PKW
|
||||
$this->assertSame($regularPkw->id, $participant->transportationOutbound->id);
|
||||
@@ -386,6 +400,8 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
|
||||
public function testProcessFieldRestoresDiscountForThreeYearOldParticipant(): void
|
||||
{
|
||||
$this->serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
|
||||
// Setup services
|
||||
$discountedPkw = $this->createPkwService(100, 'Selbstorganisiert (-15€ Rabatt)', -15.0);
|
||||
$regularPkw = $this->createPkwService(101, 'Selbstorganisiert', 0.0);
|
||||
@@ -414,7 +430,7 @@ class ParticipantTransportationDiscountReplacementFieldHandlerTest extends TestC
|
||||
$submittedData = [];
|
||||
|
||||
// Process
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
$this->handler()->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
// Assert outbound was replaced with discounted PKW (3-year-old is eligible)
|
||||
$this->assertSame($discountedPkw->id, $participant->transportationOutbound->id);
|
||||
|
||||
@@ -204,7 +204,7 @@ class ParticipantVegFieldHandlerTest extends TestCase
|
||||
|
||||
private function createMockBookingDto(?Travel $travel = null): BookingDto
|
||||
{
|
||||
$bookingDto = $this->createMock(BookingDto::class);
|
||||
$bookingDto = $this->createStub(BookingDto::class);
|
||||
|
||||
if (null !== $travel) {
|
||||
$bookingDto->travel = $travel;
|
||||
|
||||
Reference in New Issue
Block a user