fix: validate body dimensions when rentals are selected only

This commit is contained in:
Björn Fromme
2026-06-02 14:22:47 +02:00
parent f023bd9772
commit 00889318ee
2 changed files with 37 additions and 2 deletions
@@ -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<string, int> $options
*
@@ -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();