feat: clarify booking summary participant count
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Model\RoomSelectionDto;
|
||||
use App\Service\BookingSummaryParticipantCountService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BookingSummaryParticipantCountServiceTest extends TestCase
|
||||
{
|
||||
public function testCreateStep1UsesExpectedParticipantCountFromSelectedRooms(): void
|
||||
{
|
||||
$service = new BookingSummaryParticipantCountService();
|
||||
$bookingDto = $this->createBookingDto();
|
||||
$bookingDto->currentStep = 1;
|
||||
$bookingDto->roomSelections = [
|
||||
$this->createRoomSelection(10, 1),
|
||||
$this->createRoomSelection(11, 2),
|
||||
];
|
||||
|
||||
self::assertSame(8, $service->calculate($bookingDto));
|
||||
}
|
||||
|
||||
public function testLaterCreateStepsUseActualParticipantCount(): void
|
||||
{
|
||||
$service = new BookingSummaryParticipantCountService();
|
||||
$bookingDto = $this->createBookingDto();
|
||||
$bookingDto->currentStep = 2;
|
||||
$bookingDto->participants = [
|
||||
new ParticipantDto(),
|
||||
new ParticipantDto(),
|
||||
new ParticipantDto(),
|
||||
];
|
||||
|
||||
self::assertSame(3, $service->calculate($bookingDto));
|
||||
}
|
||||
|
||||
public function testEditModeUsesActualParticipantCount(): void
|
||||
{
|
||||
$service = new BookingSummaryParticipantCountService();
|
||||
$bookingDto = $this->createBookingDto();
|
||||
$bookingDto->booking = new \App\BusProNet\Model\Booking();
|
||||
$bookingDto->participants = [
|
||||
new ParticipantDto(),
|
||||
new ParticipantDto(),
|
||||
];
|
||||
|
||||
self::assertSame(2, $service->calculate($bookingDto));
|
||||
}
|
||||
|
||||
private function createBookingDto(): BookingDto
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
||||
$travel->rooms = [
|
||||
10 => $this->createRoom(10, 2),
|
||||
11 => $this->createRoom(11, 3),
|
||||
];
|
||||
|
||||
return new BookingDto($travel, 157047);
|
||||
}
|
||||
|
||||
private function createRoom(int $id, int $maxPax): Room
|
||||
{
|
||||
$room = new Room();
|
||||
$room->id = $id;
|
||||
$room->label = 'Room '.$id;
|
||||
$room->available = 4;
|
||||
$room->status = 'Frei';
|
||||
$room->maxPax = $maxPax;
|
||||
|
||||
return $room;
|
||||
}
|
||||
|
||||
private function createRoomSelection(int $id, int $quantity): RoomSelectionDto
|
||||
{
|
||||
$selection = new RoomSelectionDto();
|
||||
$selection->id = $id;
|
||||
$selection->quantity = $quantity;
|
||||
|
||||
return $selection;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user