From 00889318ee424605eeb8f5364b862d29bdde3b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 2 Jun 2026 14:22:47 +0200 Subject: [PATCH] fix: validate body dimensions when rentals are selected only --- .../Constraints/ParticipantValidator.php | 11 ++++++-- .../Constraints/ParticipantValidatorTest.php | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Validator/Constraints/ParticipantValidator.php b/src/Validator/Constraints/ParticipantValidator.php index a86fd6f..21acf83 100644 --- a/src/Validator/Constraints/ParticipantValidator.php +++ b/src/Validator/Constraints/ParticipantValidator.php @@ -38,8 +38,10 @@ class ParticipantValidator extends ConstraintValidator $this->assertPickupSelected($participant); $this->assertDropOffSelected($participant); - $this->assertBodyDimensionsWhenRentalsSelected($participant); - $this->assertBodyDimensionsInRange($participant); + if (true === $this->hasRentalsSelected($participant)) { + $this->assertBodyDimensionsWhenRentalsSelected($participant); + $this->assertBodyDimensionsInRange($participant); + } } public function assertPickupSelected(ParticipantDto $participant): void @@ -149,6 +151,11 @@ class ParticipantValidator extends ConstraintValidator } } + private function hasRentalsSelected(ParticipantDto $participant): bool + { + return false === empty($participant->rentals); + } + /** * @param array $options * diff --git a/tests/Validator/Constraints/ParticipantValidatorTest.php b/tests/Validator/Constraints/ParticipantValidatorTest.php index 362a455..fd8c73e 100644 --- a/tests/Validator/Constraints/ParticipantValidatorTest.php +++ b/tests/Validator/Constraints/ParticipantValidatorTest.php @@ -89,6 +89,34 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase $this->assertNoViolation(); } + public function testParticipantWithoutRentalsIgnoresOutOfRangeBodyMeasurements(): void + { + $participant = $this->createValidParticipant(); + $participant->rentals = []; + $participant->height = '999'; + $participant->weight = '999'; + $participant->shoeSize = '999'; + + $this->validator->validate($participant, new Participant()); + + $this->assertNoViolation(); + } + + public function testParticipantWithRentalsAndOutOfRangeShoeSizeFailsValidation(): void + { + $participant = $this->createValidParticipant(); + $participant->rentals = [$this->createMockService()]; + $participant->height = '170'; + $participant->weight = '70'; + $participant->shoeSize = '51'; + + $this->validator->validate($participant, new Participant()); + + $this->buildViolation('Bitte gib eine Zahl zwischen 35 und 50 ein. Falls du außerhalb dieses Bereichs bist, ruf gerne unser Kundenoffice an.') + ->atPath('property.path.shoeSize') + ->assertRaised(); + } + public function testCanceledParticipantSkipsValidation(): void { $participant = $this->createValidParticipant();