Files
myep/tests/Validator/SelectionBasedBodyDimensionExemptionTest.php

78 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Validator;
use App\BusProNet\Model\CrmSelection;
use App\BusProNet\Model\CrmSelectionGroup;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Model\ParticipantEditDto;
use App\Validator\SelectionBasedBodyDimensionExemption;
use PHPUnit\Framework\TestCase;
class SelectionBasedBodyDimensionExemptionTest extends TestCase
{
private SelectionBasedBodyDimensionExemption $exemption;
protected function setUp(): void
{
$this->exemption = new SelectionBasedBodyDimensionExemption();
}
public function testReturnsTrueWhenWrapperTravelContainsSelection1475(): void
{
$root = $this->createWrapperWithSelectionIds([1475]);
$this->assertTrue($this->exemption->isBodyDimensionValidationExempt($root));
}
public function testReturnsFalseWhenSelection1475IsAbsent(): void
{
$root = $this->createWrapperWithSelectionIds([2001]);
$this->assertFalse($this->exemption->isBodyDimensionValidationExempt($root));
}
public function testReturnsFalseWhenRootIsNotParticipantEditDto(): void
{
$this->assertFalse($this->exemption->isBodyDimensionValidationExempt(new \stdClass()));
}
private function createWrapperWithSelectionIds(array $selectionIds): ParticipantEditDto
{
$travel = new Travel();
$travel->selectionGroups = [
1 => $this->createSelectionGroup(1, $selectionIds),
];
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
return new ParticipantEditDto(
participant: $participant,
bookingContext: $bookingDto,
);
}
/**
* @param list<int> $selectionIds
*/
private function createSelectionGroup(int $groupId, array $selectionIds): CrmSelectionGroup
{
$group = new CrmSelectionGroup();
$group->id = $groupId;
$group->selections = [];
foreach ($selectionIds as $selectionId) {
$selection = new CrmSelection();
$selection->id = $selectionId;
$group->selections[] = $selection;
}
return $group;
}
}