chore: major code cleanup and type safety using phpstan
This commit is contained in:
1 parent
060cbea9da
commit
3da73d626b
103 files changed
+976
-1192
No files matched your search
@@ -15,13 +15,15 @@ use App\Service\BookingPriceCalculator;
|
||||
use App\Service\InsuranceManager;
|
||||
use App\Service\ServiceLabelFormatter;
|
||||
use App\Service\ServiceAvailabilityCalculator;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
{
|
||||
private ParticipantFieldOptionsProvider $provider;
|
||||
private ServiceAvailabilityCalculator $serviceAvailabilityCalculator;
|
||||
/** @var ServiceAvailabilityCalculator&MockObject */
|
||||
private $serviceAvailabilityCalculator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
@@ -57,9 +59,9 @@ class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
$choiceIds = array_map(fn (Service $service) => $service->id, $choices);
|
||||
|
||||
// Baby should see only service with age range 0-14 that includes them
|
||||
$this->assertContains(1, $choiceIds, 'Service with age range 0-14 should be shown for baby');
|
||||
$this->assertNotContains(2, $choiceIds, 'Service with age range 6-14 should be hidden for baby (age < 6)');
|
||||
$this->assertNotContains(3, $choiceIds, 'Service without age restrictions should be hidden for baby');
|
||||
self::assertContains(1, $choiceIds, 'Service with age range 0-14 should be shown for baby');
|
||||
self::assertNotContains(2, $choiceIds, 'Service with age range 6-14 should be hidden for baby (age < 6)');
|
||||
self::assertNotContains(3, $choiceIds, 'Service without age restrictions should be hidden for baby');
|
||||
}
|
||||
|
||||
public function testTwoYearOldOnlySeesServicesWithExplicitAgeRange(): void
|
||||
@@ -79,9 +81,9 @@ class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
$choiceIds = array_map(fn (Service $service) => $service->id, $choices);
|
||||
|
||||
// 2-year-old should see only service with age range that includes them
|
||||
$this->assertContains(1, $choiceIds, 'Service with age range 0-14 should be shown for 2-year-old');
|
||||
$this->assertNotContains(2, $choiceIds, 'Service with age range 6-14 should be hidden for 2-year-old');
|
||||
$this->assertNotContains(3, $choiceIds, 'Service without age restrictions should be hidden for 2-year-old');
|
||||
self::assertContains(1, $choiceIds, 'Service with age range 0-14 should be shown for 2-year-old');
|
||||
self::assertNotContains(2, $choiceIds, 'Service with age range 6-14 should be hidden for 2-year-old');
|
||||
self::assertNotContains(3, $choiceIds, 'Service without age restrictions should be hidden for 2-year-old');
|
||||
}
|
||||
|
||||
public function testThreeYearOldSeesAllApplicableServices(): void
|
||||
@@ -101,9 +103,9 @@ class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
$choiceIds = array_map(fn (Service $service) => $service->id, $choices);
|
||||
|
||||
// 3-year-old is not a baby, should see service with age range that includes them AND no-restriction services
|
||||
$this->assertContains(1, $choiceIds, 'Service with age range 0-14 should be shown for 3-year-old');
|
||||
$this->assertNotContains(2, $choiceIds, 'Service with age range 6-14 should be hidden for 3-year-old (age < 6)');
|
||||
$this->assertContains(3, $choiceIds, 'Service without age restrictions should be shown for non-baby');
|
||||
self::assertContains(1, $choiceIds, 'Service with age range 0-14 should be shown for 3-year-old');
|
||||
self::assertNotContains(2, $choiceIds, 'Service with age range 6-14 should be hidden for 3-year-old (age < 6)');
|
||||
self::assertContains(3, $choiceIds, 'Service without age restrictions should be shown for non-baby');
|
||||
}
|
||||
|
||||
public function testAdultSeesAllApplicableServices(): void
|
||||
@@ -123,9 +125,9 @@ class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
$choiceIds = array_map(fn (Service $service) => $service->id, $choices);
|
||||
|
||||
// Adult should see service without age restrictions but not children services
|
||||
$this->assertNotContains(1, $choiceIds, 'Service with age range 0-14 should be hidden for adult (age > 14)');
|
||||
$this->assertNotContains(2, $choiceIds, 'Service with age range 6-14 should be hidden for adult (age > 14)');
|
||||
$this->assertContains(3, $choiceIds, 'Service without age restrictions should be shown for adult');
|
||||
self::assertNotContains(1, $choiceIds, 'Service with age range 0-14 should be hidden for adult (age > 14)');
|
||||
self::assertNotContains(2, $choiceIds, 'Service with age range 6-14 should be hidden for adult (age > 14)');
|
||||
self::assertContains(3, $choiceIds, 'Service without age restrictions should be shown for adult');
|
||||
}
|
||||
|
||||
public function testBabyGetRegularPkwInTransportation(): void
|
||||
@@ -145,9 +147,9 @@ class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
$choiceIds = array_map(fn (Service $service) => $service->id, $choices);
|
||||
|
||||
// Baby should see BUS and regular PKW, but NOT discounted PKW
|
||||
$this->assertContains(1, $choiceIds, 'BUS should be shown for baby');
|
||||
$this->assertContains(3, $choiceIds, 'Regular PKW should be shown for baby');
|
||||
$this->assertNotContains(2, $choiceIds, 'Discounted PKW should be hidden for baby');
|
||||
self::assertContains(1, $choiceIds, 'BUS should be shown for baby');
|
||||
self::assertContains(3, $choiceIds, 'Regular PKW should be shown for baby');
|
||||
self::assertNotContains(2, $choiceIds, 'Discounted PKW should be hidden for baby');
|
||||
}
|
||||
|
||||
public function testTwoYearOldGetRegularPkwInTransportation(): void
|
||||
@@ -167,9 +169,9 @@ class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
$choiceIds = array_map(fn (Service $service) => $service->id, $choices);
|
||||
|
||||
// 2-year-old (at BABY_MAX_AGE) should see BUS and regular PKW, but NOT discounted PKW
|
||||
$this->assertContains(1, $choiceIds, 'BUS should be shown for 2-year-old');
|
||||
$this->assertContains(3, $choiceIds, 'Regular PKW should be shown for 2-year-old');
|
||||
$this->assertNotContains(2, $choiceIds, 'Discounted PKW should be hidden for 2-year-old');
|
||||
self::assertContains(1, $choiceIds, 'BUS should be shown for 2-year-old');
|
||||
self::assertContains(3, $choiceIds, 'Regular PKW should be shown for 2-year-old');
|
||||
self::assertNotContains(2, $choiceIds, 'Discounted PKW should be hidden for 2-year-old');
|
||||
}
|
||||
|
||||
public function testThreeYearOldGetSmartPkwFiltering(): void
|
||||
@@ -194,9 +196,9 @@ class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
$choiceIds = array_map(fn (Service $service) => $service->id, $choices);
|
||||
|
||||
// 3-year-old is not a baby, should get smart filtering (discounted when available)
|
||||
$this->assertContains(1, $choiceIds, 'BUS should be shown for 3-year-old');
|
||||
$this->assertContains(2, $choiceIds, 'Discounted PKW should be shown for 3-year-old when available');
|
||||
$this->assertNotContains(3, $choiceIds, 'Regular PKW should be hidden when discounted is available');
|
||||
self::assertContains(1, $choiceIds, 'BUS should be shown for 3-year-old');
|
||||
self::assertContains(2, $choiceIds, 'Discounted PKW should be shown for 3-year-old when available');
|
||||
self::assertNotContains(3, $choiceIds, 'Regular PKW should be hidden when discounted is available');
|
||||
}
|
||||
|
||||
public function testBabyFilteringAppliesToMultipleServiceTypes(): void
|
||||
@@ -214,15 +216,15 @@ class ParticipantFieldOptionsProviderBabyTest extends TestCase
|
||||
$boardOptions = $this->provider->getFieldOptions('board', $bookingDto, 0);
|
||||
$boardChoiceIds = array_map(fn (Service $service) => $service->id, $boardOptions['choices']);
|
||||
|
||||
$this->assertContains(10, $boardChoiceIds, 'Board with age range 0-5 should be shown for baby');
|
||||
$this->assertNotContains(11, $boardChoiceIds, 'Board without age range should be hidden for baby');
|
||||
self::assertContains(10, $boardChoiceIds, 'Board with age range 0-5 should be shown for baby');
|
||||
self::assertNotContains(11, $boardChoiceIds, 'Board without age range should be hidden for baby');
|
||||
|
||||
// Test courses services
|
||||
$coursesOptions = $this->provider->getFieldOptions('courses', $bookingDto, 0);
|
||||
$coursesChoiceIds = array_map(fn (Service $service) => $service->id, $coursesOptions['choices']);
|
||||
|
||||
$this->assertContains(20, $coursesChoiceIds, 'Course with age range 0-3 should be shown for baby');
|
||||
$this->assertNotContains(21, $coursesChoiceIds, 'Course without age range should be hidden for baby');
|
||||
self::assertContains(20, $coursesChoiceIds, 'Course with age range 0-3 should be shown for baby');
|
||||
self::assertNotContains(21, $coursesChoiceIds, 'Course without age range should be hidden for baby');
|
||||
}
|
||||
|
||||
private function createTravelWithMixedServices(): Travel
|
||||
|
||||
Reference in new issue
Block a user