feat: split booking participant controllers
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Service\ParticipantFormSupportService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
|
||||
class ParticipantFormSupportServiceTest extends TestCase
|
||||
{
|
||||
public function testEnsureParticipantExistsThrowsForMissingIndex(): void
|
||||
{
|
||||
$service = $this->createService();
|
||||
$bookingDto = $this->createBookingDto();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Participant at index 2 does not exist');
|
||||
|
||||
$service->ensureParticipantExists($bookingDto, 2);
|
||||
}
|
||||
|
||||
public function testCreateParticipantEditDtoWrapsParticipant(): void
|
||||
{
|
||||
$service = $this->createService();
|
||||
$bookingDto = $this->createBookingDto();
|
||||
|
||||
$wrapper = $service->createParticipantEditDto($bookingDto, 0);
|
||||
|
||||
$this->assertSame($bookingDto, $wrapper->bookingContext);
|
||||
$this->assertSame($bookingDto->participants[0], $wrapper->participant);
|
||||
}
|
||||
|
||||
public function testCollectAndClearNotificationsFlattensAndClearsNotifications(): void
|
||||
{
|
||||
$service = $this->createService();
|
||||
$bookingDto = $this->createBookingDto();
|
||||
|
||||
$bookingDto->participants[0]->notifications = [
|
||||
['type' => 'info', 'message' => 'First'],
|
||||
];
|
||||
$bookingDto->participants[1]->notifications = [
|
||||
['type' => 'warning', 'message' => 'Second'],
|
||||
];
|
||||
|
||||
$notifications = $service->collectAndClearNotifications($bookingDto);
|
||||
|
||||
$this->assertSame([
|
||||
['type' => 'info', 'message' => 'First'],
|
||||
['type' => 'warning', 'message' => 'Second'],
|
||||
], $notifications);
|
||||
$this->assertSame([], $bookingDto->participants[0]->notifications);
|
||||
$this->assertSame([], $bookingDto->participants[1]->notifications);
|
||||
}
|
||||
|
||||
public function testGetParticipantFormOptionsIncludesValidationToggle(): void
|
||||
{
|
||||
$parameterBag = $this->createMock(ParameterBagInterface::class);
|
||||
$parameterBag->expects($this->exactly(4))
|
||||
->method('get')
|
||||
->willReturnMap([
|
||||
['body_dimensions.height_choices', ['bis 148cm' => '-148']],
|
||||
['body_dimensions.weight_choices', ['42 - 48kg' => '42-48']],
|
||||
['body_dimensions.shoe_size_min', 36],
|
||||
['body_dimensions.shoe_size_max', 48],
|
||||
]);
|
||||
|
||||
$service = $this->createService(parameterBag: $parameterBag);
|
||||
$bookingDto = $this->createBookingDto();
|
||||
|
||||
$options = $service->getParticipantFormOptions($bookingDto, true);
|
||||
|
||||
$this->assertSame($bookingDto, $options['booking_context']);
|
||||
$this->assertSame(['bis 148cm' => '-148'], $options['height_choices']);
|
||||
$this->assertSame(['42 - 48kg' => '42-48'], $options['weight_choices']);
|
||||
$this->assertSame(36, $options['shoe_size_min']);
|
||||
$this->assertSame(48, $options['shoe_size_max']);
|
||||
$this->assertFalse($options['validation_groups']);
|
||||
}
|
||||
|
||||
private function createService(?ParameterBagInterface $parameterBag = null): ParticipantFormSupportService
|
||||
{
|
||||
$parameterBag ??= $this->createMock(ParameterBagInterface::class);
|
||||
|
||||
return new ParticipantFormSupportService($parameterBag);
|
||||
}
|
||||
|
||||
private function createBookingDto(): BookingDto
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
||||
|
||||
$bookingDto = new BookingDto($travel, 157047);
|
||||
$bookingDto->booking = new Booking();
|
||||
|
||||
$participantOne = new ParticipantDto();
|
||||
$participantOne->index = 0;
|
||||
$participantOne->dateOfBirth = new \DateTimeImmutable('1990-01-01');
|
||||
$bookingDto->participants[0] = $participantOne;
|
||||
|
||||
$participantTwo = new ParticipantDto();
|
||||
$participantTwo->index = 1;
|
||||
$participantTwo->dateOfBirth = new \DateTimeImmutable('1995-01-01');
|
||||
$bookingDto->participants[1] = $participantTwo;
|
||||
|
||||
return $bookingDto;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user