From d33ff9779cdb835bdcfb2b27e14ac78ca47b883d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 25 Feb 2026 16:55:00 +0100 Subject: [PATCH] fix: correctly validate pickup selection closes #869c94jqn --- .../Constraints/ParticipantValidator.php | 8 ++- .../Constraints/ParticipantValidatorTest.php | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/Validator/Constraints/ParticipantValidator.php b/src/Validator/Constraints/ParticipantValidator.php index 8b8e5fb..add6eb6 100644 --- a/src/Validator/Constraints/ParticipantValidator.php +++ b/src/Validator/Constraints/ParticipantValidator.php @@ -28,14 +28,12 @@ class ParticipantValidator extends ConstraintValidator public function assertPickupSelected(ParticipantDto $participant): void { - // Check if either outbound or inbound transportation is bus + // Pickup applies only to outbound bus journey $hasOutboundBus = null !== $participant->transportationOutbound && 'BUS' === $participant->transportationOutbound->subType; - $hasInboundBus = null !== $participant->transportationInbound - && 'BUS' === $participant->transportationInbound->subType; - // Require pickup if at least one direction has bus transport - if (($hasOutboundBus || $hasInboundBus) && null === $participant->pickup) { + // Require pickup only when outbound transportation is bus + if (true === $hasOutboundBus && null === $participant->pickup) { $this->context->buildViolation('Bitte auswählen') ->atPath('pickup') ->addViolation() diff --git a/tests/Validator/Constraints/ParticipantValidatorTest.php b/tests/Validator/Constraints/ParticipantValidatorTest.php index 542ed9c..362a455 100644 --- a/tests/Validator/Constraints/ParticipantValidatorTest.php +++ b/tests/Validator/Constraints/ParticipantValidatorTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Tests\Validator\Constraints; +use App\BusProNet\Model\Pickup; use App\BusProNet\Model\Service; use App\Form\Model\ParticipantDto; use App\Validator\Constraints\Participant; @@ -107,6 +108,7 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase $busService = new Service(); $busService->subType = 'BUS'; $participant->transportationOutbound = $busService; + $participant->transportationInbound = $this->createMockService(); $participant->pickup = null; $this->validator->validate($participant, new Participant()); @@ -116,6 +118,46 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase ->assertRaised(); } + public function testParticipantWithInboundBusOnlyAndNoPickupPassesValidation(): void + { + $participant = $this->createValidParticipant(); + $participant->transportationOutbound = $this->createMockService(); + + $busService = new Service(); + $busService->subType = 'BUS'; + $participant->transportationInbound = $busService; + + $participant->pickup = null; + $participant->dropOff = $this->createMockPickup(); + + $this->validator->validate($participant, new Participant()); + + $this->assertNoViolation(); + } + + public function testParticipantWithPkwOutboundBusInboundRequiresDropOffButNotPickup(): void + { + $participant = $this->createValidParticipant(); + + $carService = new Service(); + $carService->subType = 'PKW'; + $participant->transportationOutbound = $carService; + + $busService = new Service(); + $busService->subType = 'BUS'; + $participant->transportationInbound = $busService; + + $participant->pickup = null; + $participant->dropOff = null; + + $this->validator->validate($participant, new Participant()); + + $this->buildViolation('Bitte auswählen') + ->atPath('property.path.dropOff') + ->assertRaised(); + $this->assertCount(1, $this->context->getViolations()); + } + public function testParticipantWithNonBusTransportationPassesPickupValidation(): void { $participant = $this->createValidParticipant(); @@ -153,4 +195,13 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase return $service; } + + private function createMockPickup(): Pickup + { + $pickup = new Pickup(); + $pickup->id = 123; + $pickup->city = 'Test City'; + + return $pickup; + } }