fix: validate body dimensions when rentals are selected only
This commit is contained in:
@@ -38,9 +38,11 @@ class ParticipantValidator extends ConstraintValidator
|
|||||||
|
|
||||||
$this->assertPickupSelected($participant);
|
$this->assertPickupSelected($participant);
|
||||||
$this->assertDropOffSelected($participant);
|
$this->assertDropOffSelected($participant);
|
||||||
|
if (true === $this->hasRentalsSelected($participant)) {
|
||||||
$this->assertBodyDimensionsWhenRentalsSelected($participant);
|
$this->assertBodyDimensionsWhenRentalsSelected($participant);
|
||||||
$this->assertBodyDimensionsInRange($participant);
|
$this->assertBodyDimensionsInRange($participant);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function assertPickupSelected(ParticipantDto $participant): void
|
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
|
* @param array<string, int> $options
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -89,6 +89,34 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase
|
|||||||
$this->assertNoViolation();
|
$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
|
public function testCanceledParticipantSkipsValidation(): void
|
||||||
{
|
{
|
||||||
$participant = $this->createValidParticipant();
|
$participant = $this->createValidParticipant();
|
||||||
|
|||||||
Reference in New Issue
Block a user