Compare commits

...
2 Commits
Author SHA1 Message Date
Björn Fromme 10d5356381 chore: update project dependencies 2026-07-23 17:54:47 +02:00
Björn Fromme b323c120f9 fix: consider parking space availability 2026-07-23 17:44:08 +02:00
9 changed files with 279 additions and 45 deletions

No files matched your search

Generated
+41 -41
View File
@@ -306,16 +306,16 @@
}, },
{ {
"name": "doctrine/dbal", "name": "doctrine/dbal",
"version": "3.10.5", "version": "3.10.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/doctrine/dbal.git", "url": "https://github.com/doctrine/dbal.git",
"reference": "95d84866bf3c04b2ddca1df7c049714660959aef" "reference": "c95589d775a0b2e543467d40f8c3ecccf586f2b4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/95d84866bf3c04b2ddca1df7c049714660959aef", "url": "https://api.github.com/repos/doctrine/dbal/zipball/c95589d775a0b2e543467d40f8c3ecccf586f2b4",
"reference": "95d84866bf3c04b2ddca1df7c049714660959aef", "reference": "c95589d775a0b2e543467d40f8c3ecccf586f2b4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -400,7 +400,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/doctrine/dbal/issues", "issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.10.5" "source": "https://github.com/doctrine/dbal/tree/3.10.6"
}, },
"funding": [ "funding": [
{ {
@@ -416,7 +416,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2026-02-24T08:03:57+00:00" "time": "2026-07-21T12:57:49+00:00"
}, },
{ {
"name": "doctrine/deprecations", "name": "doctrine/deprecations",
@@ -468,16 +468,16 @@
}, },
{ {
"name": "doctrine/doctrine-bundle", "name": "doctrine/doctrine-bundle",
"version": "2.18.3", "version": "2.19.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/doctrine/DoctrineBundle.git", "url": "https://github.com/doctrine/DoctrineBundle.git",
"reference": "241d61f6bbc77275d5a9f95d514241c058bf2d0a" "reference": "07b90f707b82981097731c419f546e7ba97fba3c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/241d61f6bbc77275d5a9f95d514241c058bf2d0a", "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/07b90f707b82981097731c419f546e7ba97fba3c",
"reference": "241d61f6bbc77275d5a9f95d514241c058bf2d0a", "reference": "07b90f707b82981097731c419f546e7ba97fba3c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -499,7 +499,7 @@
"doctrine/cache": "< 1.11", "doctrine/cache": "< 1.11",
"doctrine/orm": "<2.17 || >=4.0", "doctrine/orm": "<2.17 || >=4.0",
"symfony/var-exporter": "< 6.4.1 || 7.0.0", "symfony/var-exporter": "< 6.4.1 || 7.0.0",
"twig/twig": "<2.13 || >=3.0 <3.0.4" "twig/twig": "<2.13 || >=3.0 <3.0.4 || >=5"
}, },
"require-dev": { "require-dev": {
"doctrine/annotations": "^1 || ^2", "doctrine/annotations": "^1 || ^2",
@@ -513,10 +513,12 @@
"phpunit/phpunit": "^10.5.53 || ^12.3.10", "phpunit/phpunit": "^10.5.53 || ^12.3.10",
"psr/log": "^1.1.4 || ^2.0 || ^3.0", "psr/log": "^1.1.4 || ^2.0 || ^3.0",
"symfony/doctrine-messenger": "^6.4 || ^7.0", "symfony/doctrine-messenger": "^6.4 || ^7.0",
"symfony/event-dispatcher": "^6.4 || ^7.0",
"symfony/expression-language": "^6.4 || ^7.0", "symfony/expression-language": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0", "symfony/http-kernel": "^6.4 || ^7.0",
"symfony/messenger": "^6.4 || ^7.0", "symfony/messenger": "^6.4 || ^7.0",
"symfony/property-info": "^6.4 || ^7.0", "symfony/property-info": "^6.4 || ^7.0",
"symfony/runtime": "^6.4 || ^7.0",
"symfony/security-bundle": "^6.4 || ^7.0", "symfony/security-bundle": "^6.4 || ^7.0",
"symfony/stopwatch": "^6.4 || ^7.0", "symfony/stopwatch": "^6.4 || ^7.0",
"symfony/string": "^6.4 || ^7.0", "symfony/string": "^6.4 || ^7.0",
@@ -525,7 +527,7 @@
"symfony/var-exporter": "^6.4.1 || ^7.0.1", "symfony/var-exporter": "^6.4.1 || ^7.0.1",
"symfony/web-profiler-bundle": "^6.4 || ^7.0", "symfony/web-profiler-bundle": "^6.4 || ^7.0",
"symfony/yaml": "^6.4 || ^7.0", "symfony/yaml": "^6.4 || ^7.0",
"twig/twig": "^2.14.7 || ^3.0.4" "twig/twig": "^2.14.7 || ^3.0.4 || ^4"
}, },
"suggest": { "suggest": {
"doctrine/orm": "The Doctrine ORM integration is optional in the bundle.", "doctrine/orm": "The Doctrine ORM integration is optional in the bundle.",
@@ -570,7 +572,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/doctrine/DoctrineBundle/issues", "issues": "https://github.com/doctrine/DoctrineBundle/issues",
"source": "https://github.com/doctrine/DoctrineBundle/tree/2.18.3" "source": "https://github.com/doctrine/DoctrineBundle/tree/2.19.0"
}, },
"funding": [ "funding": [
{ {
@@ -586,7 +588,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2026-06-08T08:22:50+00:00" "time": "2026-07-23T14:52:05+00:00"
}, },
{ {
"name": "doctrine/doctrine-migrations-bundle", "name": "doctrine/doctrine-migrations-bundle",
@@ -2511,16 +2513,16 @@
}, },
{ {
"name": "league/oauth2-server-bundle", "name": "league/oauth2-server-bundle",
"version": "v1.1.1", "version": "v1.2.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/oauth2-server-bundle.git", "url": "https://github.com/thephpleague/oauth2-server-bundle.git",
"reference": "b0094bef19cb0dfa526ea9eec6d8a863b91a3f7d" "reference": "6e1d8775ca64c9d93e4be9fadd7a0a15b8898532"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/oauth2-server-bundle/zipball/b0094bef19cb0dfa526ea9eec6d8a863b91a3f7d", "url": "https://api.github.com/repos/thephpleague/oauth2-server-bundle/zipball/6e1d8775ca64c9d93e4be9fadd7a0a15b8898532",
"reference": "b0094bef19cb0dfa526ea9eec6d8a863b91a3f7d", "reference": "6e1d8775ca64c9d93e4be9fadd7a0a15b8898532",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -2529,16 +2531,18 @@
"nyholm/psr7": "^1.4", "nyholm/psr7": "^1.4",
"php": "^8.1", "php": "^8.1",
"psr/http-factory": "^1.0", "psr/http-factory": "^1.0",
"symfony/deprecation-contracts": "^3", "symfony/deprecation-contracts": "^3.0",
"symfony/event-dispatcher": "^6.4|^7.0|^8.0", "symfony/event-dispatcher": "^6.4|^7.4|^8.0",
"symfony/filesystem": "^6.4|^7.0|^8.0", "symfony/filesystem": "^6.4|^7.4|^8.0",
"symfony/framework-bundle": "^6.4|^7.0|^8.0", "symfony/framework-bundle": "^6.4|^7.4|^8.0",
"symfony/psr-http-message-bridge": "^6.4|^7.0|^8.0", "symfony/password-hasher": "^6.4|^7.4|^8.0",
"symfony/security-bundle": "^6.4|^7.0|^8.0" "symfony/psr-http-message-bridge": "^6.4|^7.4|^8.0",
"symfony/security-bundle": "^6.4|^7.4|^8.0"
}, },
"conflict": { "conflict": {
"doctrine/doctrine-bundle": "<2.8.0", "doctrine/doctrine-bundle": "<2.8.0",
"doctrine/orm": "<2.14" "doctrine/orm": "<2.14",
"symfony/console": "<6.1"
}, },
"require-dev": { "require-dev": {
"doctrine/doctrine-bundle": "^2.8|^3.0", "doctrine/doctrine-bundle": "^2.8|^3.0",
@@ -2548,19 +2552,15 @@
"php-cs-fixer/shim": "^3.38", "php-cs-fixer/shim": "^3.38",
"phpstan/phpstan": "^2.1", "phpstan/phpstan": "^2.1",
"phpstan/phpstan-symfony": "^2.0", "phpstan/phpstan-symfony": "^2.0",
"symfony/browser-kit": "^6.4|^7.0|^8.0", "rector/rector": "^2.5",
"symfony/phpunit-bridge": "^7.3" "symfony/browser-kit": "^6.4|^7.4|^8.0",
"symfony/phpunit-bridge": "^8.1"
}, },
"suggest": { "suggest": {
"doctrine/doctrine-bundle": "Allow usage of doctrine as persistence layer", "doctrine/doctrine-bundle": "Allow usage of doctrine as persistence layer",
"doctrine/orm": "Allow usage of doctrine as persistence layer" "doctrine/orm": "Allow usage of doctrine as persistence layer"
}, },
"type": "symfony-bundle", "type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"League\\Bundle\\OAuth2ServerBundle\\": "src/" "League\\Bundle\\OAuth2ServerBundle\\": "src/"
@@ -2591,9 +2591,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/thephpleague/oauth2-server-bundle/issues", "issues": "https://github.com/thephpleague/oauth2-server-bundle/issues",
"source": "https://github.com/thephpleague/oauth2-server-bundle/tree/v1.1.1" "source": "https://github.com/thephpleague/oauth2-server-bundle/tree/v1.2.1"
}, },
"time": "2026-02-06T11:56:53+00:00" "time": "2026-07-22T08:57:59+00:00"
}, },
{ {
"name": "league/uri", "name": "league/uri",
@@ -11533,16 +11533,16 @@
}, },
{ {
"name": "friendsofphp/php-cs-fixer", "name": "friendsofphp/php-cs-fixer",
"version": "v3.95.13", "version": "v3.95.15",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
"reference": "ea941114a002eb5e5876f190223deec1066c482c" "reference": "3e47e5d50046f87e3244acde2fe655d1a3b72555"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/ea941114a002eb5e5876f190223deec1066c482c", "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/3e47e5d50046f87e3244acde2fe655d1a3b72555",
"reference": "ea941114a002eb5e5876f190223deec1066c482c", "reference": "3e47e5d50046f87e3244acde2fe655d1a3b72555",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -11582,7 +11582,7 @@
"php-coveralls/php-coveralls": "^2.9.1", "php-coveralls/php-coveralls": "^2.9.1",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.8", "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.8",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.8", "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.8",
"phpunit/phpunit": "^9.6.35 || ^10.5.64 || ^11.5.56", "phpunit/phpunit": "^9.6.35 || ^10.5.64 || ^11.5.56 || ^12.5.31",
"symfony/polyfill-php85": "^1.38", "symfony/polyfill-php85": "^1.38",
"symfony/var-dumper": "^5.4.48 || ^6.4.36 || ^7.4.8 || ^8.1.0", "symfony/var-dumper": "^5.4.48 || ^6.4.36 || ^7.4.8 || ^8.1.0",
"symfony/yaml": "^5.4.53 || ^6.4.41 || ^7.4.13 || ^8.1.0" "symfony/yaml": "^5.4.53 || ^6.4.41 || ^7.4.13 || ^8.1.0"
@@ -11626,7 +11626,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",
"source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.95.13" "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.95.15"
}, },
"funding": [ "funding": [
{ {
@@ -11634,7 +11634,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2026-07-10T09:23:21+00:00" "time": "2026-07-15T09:51:47+00:00"
}, },
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
@@ -8,6 +8,7 @@ league_oauth2_server:
enable_auth_code_grant: true enable_auth_code_grant: true
enable_refresh_token_grant: true enable_refresh_token_grant: true
enable_password_grant: false enable_password_grant: false
enable_implicit_grant: false
access_token_ttl: PT10M access_token_ttl: PT10M
resource_server: resource_server:
public_key: '%env(resolve:OAUTH_PUBLIC_KEY)%' public_key: '%env(resolve:OAUTH_PUBLIC_KEY)%'
+1 -1
View File
@@ -195,7 +195,6 @@ services:
- 'App\Form\Service\ParticipantTransportationInboundFieldHandler' - 'App\Form\Service\ParticipantTransportationInboundFieldHandler'
- 'App\Form\Service\ParticipantPickupFieldHandler' - 'App\Form\Service\ParticipantPickupFieldHandler'
- 'App\Form\Service\ParticipantDropOffFieldHandler' - 'App\Form\Service\ParticipantDropOffFieldHandler'
- 'App\Form\Service\ParticipantParkingFieldHandler'
- 'App\Form\Service\ParticipantRentalInsuranceFieldHandler' - 'App\Form\Service\ParticipantRentalInsuranceFieldHandler'
- 'App\Form\Service\ParticipantLicensePlateFieldHandler' - 'App\Form\Service\ParticipantLicensePlateFieldHandler'
# Complex handlers with dependencies - use service references # Complex handlers with dependencies - use service references
@@ -205,6 +204,7 @@ services:
- '@App\Form\Service\ParticipantInsuranceFieldHandler' - '@App\Form\Service\ParticipantInsuranceFieldHandler'
- '@App\Form\Service\ParticipantPurchaseVoucherFieldHandler' - '@App\Form\Service\ParticipantPurchaseVoucherFieldHandler'
- '@App\Form\Service\ParticipantPromoVoucherFieldHandler' - '@App\Form\Service\ParticipantPromoVoucherFieldHandler'
- '@App\Form\Service\ParticipantParkingFieldHandler'
# Booking Status Rules # Booking Status Rules
App\BusProNet\Service\StatusRule\Selection1473StatusRule: ~ App\BusProNet\Service\StatusRule\Selection1473StatusRule: ~
@@ -647,13 +647,24 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
return []; return [];
} }
return [ $fieldOptions = [
'label' => $this->serviceLabelFormatter->formatServiceLabelForServices( 'label' => $this->serviceLabelFormatter->formatServiceLabelForServices(
Constants::SERVICE_LABELS[Constants::TOKEN_PARKING], Constants::SERVICE_LABELS[Constants::TOKEN_PARKING],
$parkingServices $parkingServices
), ),
'required' => false, 'required' => false,
]; ];
// There's only ever one parking type, so check readonly state against the single service
$parkingService = reset($parkingServices);
if ($this->shouldMakeServiceReadonly($parkingService, $bookingDto, $participantIndex, 'parking')) {
$fieldOptions['attr'] = [
'readonly' => true,
'data-tooltip' => 'ausgebucht',
];
}
return $fieldOptions;
}; };
// Bulk insurance booking checkbox (applicant only - controls insurance assignment for all participants) // Bulk insurance booking checkbox (applicant only - controls insurance assignment for all participants)
@@ -10,6 +10,7 @@ use App\BusProNet\Utility\DirectionMapper;
use App\Form\Model\BookingDto; use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto; use App\Form\Model\ParticipantDto;
use App\Form\Service\Abstract\AbstractParticipantFieldHandler; use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
use App\Service\ServiceAvailabilityCalculator;
/** /**
* Handles parking service selection for self-organized transportation. * Handles parking service selection for self-organized transportation.
@@ -20,6 +21,11 @@ use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
*/ */
class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
{ {
public function __construct(
private readonly ServiceAvailabilityCalculator $serviceAvailabilityCalculator,
) {
}
public function getFieldName(): string public function getFieldName(): string
{ {
return 'parking'; return 'parking';
@@ -73,7 +79,22 @@ class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
// Store parking service object for pricing calculation // Store parking service object for pricing calculation
if (true === $isParkingSelected) { if (true === $isParkingSelected) {
$participant->parkingService = $this->findParkingService($bookingDto, $participantIndex); $parkingService = $this->findParkingService($bookingDto, $participantIndex);
// Reject the selection if the service is sold out, in case the client
// bypassed the readonly UI state (e.g. a stale form or manual submission)
if (
null !== $parkingService
&& BookingDto::MODE_EDIT !== $bookingDto->getMode()
&& $this->serviceAvailabilityCalculator->isServiceUnavailable($parkingService->id, $bookingDto, $participantIndex)
) {
$participant->parking = false;
$participant->parkingService = null;
return;
}
$participant->parkingService = $parkingService;
} else { } else {
$participant->parkingService = null; $participant->parkingService = null;
} }
@@ -173,6 +173,11 @@ class ServiceAvailabilityCalculator
$serviceUsage[$participant->skiPass->id] = ($serviceUsage[$participant->skiPass->id] ?? 0) + 1; $serviceUsage[$participant->skiPass->id] = ($serviceUsage[$participant->skiPass->id] ?? 0) + 1;
} }
// Parking service (single selection)
if (null !== $participant->parkingService && null !== $participant->parkingService->id) {
$serviceUsage[$participant->parkingService->id] = ($serviceUsage[$participant->parkingService->id] ?? 0) + 1;
}
// Transportation services (single selection each) // Transportation services (single selection each)
if (null !== $participant->transportationOutbound && null !== $participant->transportationOutbound->id) { if (null !== $participant->transportationOutbound && null !== $participant->transportationOutbound->id) {
$serviceUsage[$participant->transportationOutbound->id] = ($serviceUsage[$participant->transportationOutbound->id] ?? 0) + 1; $serviceUsage[$participant->transportationOutbound->id] = ($serviceUsage[$participant->transportationOutbound->id] ?? 0) + 1;
@@ -231,6 +236,7 @@ class ServiceAvailabilityCalculator
Constants::TOKEN_RENTALS, Constants::TOKEN_RENTALS,
Constants::TOKEN_SKI_PASS, Constants::TOKEN_SKI_PASS,
Constants::TOKEN_BOARD, Constants::TOKEN_BOARD,
Constants::TOKEN_PARKING,
]; ];
foreach ($additionalServiceTokens as $token) { foreach ($additionalServiceTokens as $token) {
@@ -135,6 +135,64 @@ class ParticipantFieldOptionsProviderMandatoryServiceTest extends TestCase
$this->assertSame('Parkplatz (€12,50)', $options['label']); $this->assertSame('Parkplatz (€12,50)', $options['label']);
} }
public function testParkingIsReadonlyWhenSoldOut(): void
{
$parkingService = new Service();
$parkingService->id = 3;
$parkingService->label = 'Parkplatz';
$parkingService->subType = Constants::TOKEN_PARKING;
$parkingService->available = 0;
$parkingService->price = 12.5;
$travel = $this->createTravelWithAdditionalServices([$parkingService]);
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$bookingDto->participants[0] = $participant;
$serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
$serviceAvailabilityCalculator->method('isServiceUnavailable')
->with($parkingService->id, $bookingDto, 0)
->willReturn(true);
$provider = new ParticipantFieldOptionsProvider(
$serviceAvailabilityCalculator,
$this->createMock(InsuranceManager::class),
$this->createMock(BookingPriceCalculator::class),
new ServiceLabelFormatter(),
$this->createMock(TranslatorInterface::class)
);
$options = $provider->getFieldOptions('parking', $bookingDto, 0);
$this->assertTrue($options['attr']['readonly']);
$this->assertSame('ausgebucht', $options['attr']['data-tooltip']);
}
public function testParkingIsNotReadonlyWhenAvailable(): void
{
$parkingService = new Service();
$parkingService->id = 3;
$parkingService->label = 'Parkplatz';
$parkingService->subType = Constants::TOKEN_PARKING;
$parkingService->available = 10;
$parkingService->price = 12.5;
$travel = $this->createTravelWithAdditionalServices([$parkingService]);
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$bookingDto->participants[0] = $participant;
$options = $this->provider->getFieldOptions('parking', $bookingDto, 0);
$this->assertArrayNotHasKey('attr', $options);
}
public function testNullParticipantReturnsEmptyOptions(): void public function testNullParticipantReturnsEmptyOptions(): void
{ {
$mandatoryService = $this->createMandatoryService(1, 'Ortstaxe'); $mandatoryService = $this->createMandatoryService(1, 'Ortstaxe');
@@ -7,9 +7,11 @@ namespace App\Tests\Form\Service;
use App\BusProNet\Model\Service; use App\BusProNet\Model\Service;
use App\BusProNet\Model\Travel; use App\BusProNet\Model\Travel;
use App\BusProNet\Utility\DirectionMapper; use App\BusProNet\Utility\DirectionMapper;
use App\BusProNet\Constants;
use App\Form\Model\BookingDto; use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto; use App\Form\Model\ParticipantDto;
use App\Form\Service\ParticipantParkingFieldHandler; use App\Form\Service\ParticipantParkingFieldHandler;
use App\Service\ServiceAvailabilityCalculator;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ParticipantParkingFieldHandlerTest extends TestCase class ParticipantParkingFieldHandlerTest extends TestCase
@@ -18,7 +20,7 @@ class ParticipantParkingFieldHandlerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
$this->handler = new ParticipantParkingFieldHandler(); $this->handler = new ParticipantParkingFieldHandler(new ServiceAvailabilityCalculator());
} }
public function testGetFieldName(): void public function testGetFieldName(): void
@@ -237,6 +239,50 @@ class ParticipantParkingFieldHandlerTest extends TestCase
$this->assertFalse($participant->parking); $this->assertFalse($participant->parking);
} }
public function testProcessFieldRejectsParkingWhenSoldOut(): void
{
$pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API);
$parkingService = $this->createParkingService(available: 0);
$participant = new ParticipantDto();
$participant->dateOfBirth = new \DateTimeImmutable('-25 years');
$participant->transportationOutbound = $pkwService;
$travel = new Travel();
$travel->additionalServices = [$parkingService->id => $parkingService];
$bookingDto = new BookingDto($travel, 1);
$bookingDto->participants = [$participant];
$submittedData = ['parking' => true];
$this->handler->processField($submittedData, $bookingDto, 0);
$this->assertFalse($participant->parking);
$this->assertNull($participant->parkingService);
}
public function testProcessFieldAllowsParkingWhenAvailable(): void
{
$pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API);
$parkingService = $this->createParkingService(available: 5);
$participant = new ParticipantDto();
$participant->dateOfBirth = new \DateTimeImmutable('-25 years');
$participant->transportationOutbound = $pkwService;
$travel = new Travel();
$travel->additionalServices = [$parkingService->id => $parkingService];
$bookingDto = new BookingDto($travel, 1);
$bookingDto->participants = [$participant];
$submittedData = ['parking' => true];
$this->handler->processField($submittedData, $bookingDto, 0);
$this->assertTrue($participant->parking);
$this->assertSame($parkingService, $participant->parkingService);
}
public function testProcessFieldSetsParkingToFalseWhenNotSelected(): void public function testProcessFieldSetsParkingToFalseWhenNotSelected(): void
{ {
$pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API); $pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API);
@@ -300,4 +346,15 @@ class ParticipantParkingFieldHandlerTest extends TestCase
return $service; return $service;
} }
private function createParkingService(int $available): Service
{
$service = new Service();
$service->id = 200;
$service->label = 'Parkplatz';
$service->subType = Constants::TOKEN_PARKING;
$service->available = $available;
return $service;
}
} }
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Constants;
use App\BusProNet\Model\Service;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Service\ServiceAvailabilityCalculator;
use PHPUnit\Framework\TestCase;
class ServiceAvailabilityCalculatorTest extends TestCase
{
private ServiceAvailabilityCalculator $calculator;
protected function setUp(): void
{
$this->calculator = new ServiceAvailabilityCalculator();
}
public function testParkingServiceIsUnavailableWhenSoldOut(): void
{
$parkingService = $this->createParkingService(id: 1, available: 0);
$bookingDto = $this->createBookingDtoWithServices([$parkingService]);
$this->assertTrue($this->calculator->isServiceUnavailable(1, $bookingDto, 0));
}
public function testParkingServiceIsAvailableWhenQuotaRemains(): void
{
$parkingService = $this->createParkingService(id: 1, available: 5);
$bookingDto = $this->createBookingDtoWithServices([$parkingService]);
$this->assertFalse($this->calculator->isServiceUnavailable(1, $bookingDto, 0));
}
public function testParkingSelectedByOtherParticipantCountsTowardUsage(): void
{
$parkingService = $this->createParkingService(id: 1, available: 1);
$bookingDto = $this->createBookingDtoWithServices([$parkingService]);
$otherParticipant = new ParticipantDto();
$otherParticipant->parkingService = $parkingService;
$bookingDto->participants[1] = $otherParticipant;
// Only one parking slot remains, and another participant already claimed it,
// so it must show unavailable for the current participant (index 0)
$this->assertTrue($this->calculator->isServiceUnavailable(1, $bookingDto, 0));
}
private function createParkingService(int $id, int $available): Service
{
$service = new Service();
$service->id = $id;
$service->label = 'Parkplatz';
$service->subType = Constants::TOKEN_PARKING;
$service->available = $available;
return $service;
}
private function createBookingDtoWithServices(array $services): BookingDto
{
$travel = new Travel();
$indexed = [];
foreach ($services as $service) {
$indexed[$service->id] = $service;
}
$travel->additionalServices = $indexed;
$bookingDto = new BookingDto($travel, 1);
$bookingDto->participants[0] = new ParticipantDto();
return $bookingDto;
}
}