feat: make body dimensions optional even with rentals selected
This commit is contained in:
@@ -39,7 +39,6 @@ class ParticipantValidator extends ConstraintValidator
|
|||||||
$this->assertPickupSelected($participant);
|
$this->assertPickupSelected($participant);
|
||||||
$this->assertDropOffSelected($participant);
|
$this->assertDropOffSelected($participant);
|
||||||
if (true === $this->hasRentalsSelected($participant)) {
|
if (true === $this->hasRentalsSelected($participant)) {
|
||||||
$this->assertBodyDimensionsWhenRentalsSelected($participant);
|
|
||||||
$this->assertBodyDimensionsInRange($participant);
|
$this->assertBodyDimensionsInRange($participant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,36 +81,6 @@ class ParticipantValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assertBodyDimensionsWhenRentalsSelected(ParticipantDto $participant): void
|
|
||||||
{
|
|
||||||
// Check if any rental services are selected
|
|
||||||
if (true === empty($participant->rentals)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Require body dimensions when rentals are selected
|
|
||||||
if (null === $participant->height || '' === $participant->height) {
|
|
||||||
$this->context->buildViolation('Bitte auswählen')
|
|
||||||
->atPath('height')
|
|
||||||
->addViolation()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $participant->weight || '' === $participant->weight) {
|
|
||||||
$this->context->buildViolation('Bitte auswählen')
|
|
||||||
->atPath('weight')
|
|
||||||
->addViolation()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $participant->shoeSize || '' === $participant->shoeSize) {
|
|
||||||
$this->context->buildViolation('Bitte auswählen')
|
|
||||||
->atPath('shoeSize')
|
|
||||||
->addViolation()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function assertBodyDimensionsInRange(ParticipantDto $participant): void
|
private function assertBodyDimensionsInRange(ParticipantDto $participant): void
|
||||||
{
|
{
|
||||||
$this->assertInRange(
|
$this->assertInRange(
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParticipantWithRentalsButNoHeightFailsValidation(): void
|
public function testParticipantWithRentalsAndMissingHeightPassesValidation(): void
|
||||||
{
|
{
|
||||||
$participant = $this->createValidParticipant();
|
$participant = $this->createValidParticipant();
|
||||||
$participant->rentals = [$this->createMockService()];
|
$participant->rentals = [$this->createMockService()];
|
||||||
@@ -41,12 +41,10 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->validator->validate($participant, new Participant());
|
$this->validator->validate($participant, new Participant());
|
||||||
|
|
||||||
$this->buildViolation('Bitte auswählen')
|
$this->assertNoViolation();
|
||||||
->atPath('property.path.height')
|
|
||||||
->assertRaised();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParticipantWithRentalsButNoWeightFailsValidation(): void
|
public function testParticipantWithRentalsAndMissingWeightPassesValidation(): void
|
||||||
{
|
{
|
||||||
$participant = $this->createValidParticipant();
|
$participant = $this->createValidParticipant();
|
||||||
$participant->rentals = [$this->createMockService()];
|
$participant->rentals = [$this->createMockService()];
|
||||||
@@ -56,12 +54,10 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->validator->validate($participant, new Participant());
|
$this->validator->validate($participant, new Participant());
|
||||||
|
|
||||||
$this->buildViolation('Bitte auswählen')
|
$this->assertNoViolation();
|
||||||
->atPath('property.path.weight')
|
|
||||||
->assertRaised();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParticipantWithRentalsButNoShoeSizeFailsValidation(): void
|
public function testParticipantWithRentalsAndMissingShoeSizePassesValidation(): void
|
||||||
{
|
{
|
||||||
$participant = $this->createValidParticipant();
|
$participant = $this->createValidParticipant();
|
||||||
$participant->rentals = [$this->createMockService()];
|
$participant->rentals = [$this->createMockService()];
|
||||||
@@ -71,9 +67,7 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->validator->validate($participant, new Participant());
|
$this->validator->validate($participant, new Participant());
|
||||||
|
|
||||||
$this->buildViolation('Bitte auswählen')
|
$this->assertNoViolation();
|
||||||
->atPath('property.path.shoeSize')
|
|
||||||
->assertRaised();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParticipantWithoutRentalsAndNoBodyMeasurementsPassesValidation(): void
|
public function testParticipantWithoutRentalsAndNoBodyMeasurementsPassesValidation(): void
|
||||||
@@ -89,7 +83,7 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParticipantWithoutRentalsIgnoresOutOfRangeBodyMeasurements(): void
|
public function testParticipantWithoutRentalsAndOutOfRangeBodyMeasurementsPassValidation(): void
|
||||||
{
|
{
|
||||||
$participant = $this->createValidParticipant();
|
$participant = $this->createValidParticipant();
|
||||||
$participant->rentals = [];
|
$participant->rentals = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user