Files
myep/tests/Validator/Constraints/ParticipantValidatorTest.php
T
2026-01-19 16:12:53 +01:00

157 lines
4.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Validator\Constraints;
use App\BusProNet\Model\Service;
use App\Form\Model\ParticipantDto;
use App\Validator\Constraints\Participant;
use App\Validator\Constraints\ParticipantValidator;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
class ParticipantValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator(): ParticipantValidator
{
return new ParticipantValidator();
}
public function testParticipantWithRentalsAndBodyMeasurementsPassesValidation(): void
{
$participant = $this->createValidParticipant();
$participant->rentals = [$this->createMockService()];
$participant->height = '170';
$participant->weight = '70';
$participant->shoeSize = '42';
$this->validator->validate($participant, new Participant());
$this->assertNoViolation();
}
public function testParticipantWithRentalsButNoHeightFailsValidation(): void
{
$participant = $this->createValidParticipant();
$participant->rentals = [$this->createMockService()];
$participant->height = null;
$participant->weight = '70';
$participant->shoeSize = '42';
$this->validator->validate($participant, new Participant());
$this->buildViolation('Bitte auswählen')
->atPath('property.path.height')
->assertRaised();
}
public function testParticipantWithRentalsButNoWeightFailsValidation(): void
{
$participant = $this->createValidParticipant();
$participant->rentals = [$this->createMockService()];
$participant->height = '170';
$participant->weight = null;
$participant->shoeSize = '42';
$this->validator->validate($participant, new Participant());
$this->buildViolation('Bitte auswählen')
->atPath('property.path.weight')
->assertRaised();
}
public function testParticipantWithRentalsButNoShoeSizeFailsValidation(): void
{
$participant = $this->createValidParticipant();
$participant->rentals = [$this->createMockService()];
$participant->height = '170';
$participant->weight = '70';
$participant->shoeSize = null;
$this->validator->validate($participant, new Participant());
$this->buildViolation('Bitte auswählen')
->atPath('property.path.shoeSize')
->assertRaised();
}
public function testParticipantWithoutRentalsAndNoBodyMeasurementsPassesValidation(): void
{
$participant = $this->createValidParticipant();
$participant->rentals = [];
$participant->height = null;
$participant->weight = null;
$participant->shoeSize = null;
$this->validator->validate($participant, new Participant());
$this->assertNoViolation();
}
public function testCanceledParticipantSkipsValidation(): void
{
$participant = $this->createValidParticipant();
$participant->status = 'S'; // Canceled
$participant->transportationOutbound = null;
$participant->transportationInbound = null;
$this->validator->validate($participant, new Participant());
$this->assertNoViolation();
}
public function testParticipantWithBusTransportationButNoPickupFailsValidation(): void
{
$participant = $this->createValidParticipant();
$busService = new Service();
$busService->subType = 'BUS';
$participant->transportationOutbound = $busService;
$participant->pickup = null;
$this->validator->validate($participant, new Participant());
$this->buildViolation('Bitte auswählen')
->atPath('property.path.pickup')
->assertRaised();
}
public function testParticipantWithNonBusTransportationPassesPickupValidation(): void
{
$participant = $this->createValidParticipant();
$trainService = new Service();
$trainService->subType = 'TRAIN';
$participant->transportationOutbound = $trainService;
$participant->pickup = null; // Not required for non-bus
$this->validator->validate($participant, new Participant());
$this->assertNoViolation();
}
private function createValidParticipant(): ParticipantDto
{
$participant = new ParticipantDto();
// Set valid transportation to avoid transportation validation errors
$participant->transportationOutbound = $this->createMockService();
$participant->transportationInbound = $this->createMockService();
// Set status to active
$participant->status = 'F';
return $participant;
}
private function createMockService(): Service
{
$service = new Service();
$service->id = 123;
$service->label = 'Test Service';
$service->subType = 'TRAIN'; // Non-bus to avoid pickup validation
return $service;
}
}