Files
myep/tests/Service/BookingParticipantCountServiceTest.php
T

78 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Model\Room;
use App\BusProNet\Model\Travel;
use App\BusProNet\Constants;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Model\RoomSelectionDto;
use App\Service\BookingParticipantCountService;
use PHPUnit\Framework\TestCase;
class BookingParticipantCountServiceTest extends TestCase
{
private BookingParticipantCountService $service;
protected function setUp(): void
{
$this->service = new BookingParticipantCountService();
}
public function testEnsureCorrectNumberOfParticipantsExpandsToCalculatedCount(): void
{
$travel = $this->createTravel([
1 => 2,
2 => 3,
]);
$bookingDto = new BookingDto($travel, 123);
$bookingDto->roomSelections = [
$this->createRoomSelection(1, 1),
$this->createRoomSelection(2, 2),
];
$bookingDto->participants = [new ParticipantDto()];
$this->service->ensureCorrectNumberOfParticipants($bookingDto);
$this->assertCount(8, $bookingDto->participants);
$this->assertSame(0, $bookingDto->participants[0]->index);
$this->assertSame(7, $bookingDto->participants[7]->index);
}
private function createTravel(array $roomCapacities): Travel
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
$rooms = [];
foreach ($roomCapacities as $id => $minPax) {
$room = new Room();
$room->id = $id;
$room->label = 'Room '.$id;
$room->minPax = $minPax;
$room->maxPax = $minPax + 1;
$room->available = 5;
$room->status = Constants::STATUS_AVAILABLE;
$rooms[$id] = $room;
}
$travel->rooms = $rooms;
return $travel;
}
private function createRoomSelection(int $id, int $quantity): RoomSelectionDto
{
$selection = new RoomSelectionDto();
$selection->id = $id;
$selection->quantity = $quantity;
return $selection;
}
}