131 lines
4.0 KiB
PHP
131 lines
4.0 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Tests\Service;
|
||
|
||
use App\BusProNet\Model\Booking;
|
||
use App\BusProNet\Model\Room;
|
||
use App\BusProNet\Model\Travel;
|
||
use App\Form\Model\BookingDto;
|
||
use App\Form\Model\BookingSummaryDto;
|
||
use App\Form\Model\ParticipantDto;
|
||
use App\Form\Model\RoomSelectionDto;
|
||
use App\Service\BookingPriceCalculator;
|
||
use App\Service\BookingPricingAssembler;
|
||
use App\Service\BookingSummaryAssembler;
|
||
use App\Service\CmsDataProvider;
|
||
use App\BusProNet\DataProvider\CountryDataProvider;
|
||
use App\BusProNet\XmlLoader\HotelLoader;
|
||
use PHPUnit\Framework\TestCase;
|
||
use Psr\Log\NullLogger;
|
||
use Symfony\Contracts\Cache\CacheInterface;
|
||
|
||
class BookingSummaryAssemblerTest extends TestCase
|
||
{
|
||
public function testCreateStep1UsesExpectedParticipantCountFromSelectedRooms(): void
|
||
{
|
||
$service = $this->createService();
|
||
$bookingDto = $this->createBookingDto();
|
||
$bookingDto->currentStep = 1;
|
||
$bookingDto->roomSelections = [
|
||
$this->createRoomSelection(10, 1),
|
||
$this->createRoomSelection(11, 2),
|
||
];
|
||
|
||
$summary = $service->getSummaryData($bookingDto);
|
||
|
||
$this->assertInstanceOf(BookingSummaryDto::class, $summary);
|
||
$this->assertSame(8, $summary->participantCount); // 1×2 + 2×3 = 8
|
||
}
|
||
|
||
public function testLaterCreateStepsUseActualParticipantCount(): void
|
||
{
|
||
$service = $this->createService();
|
||
$bookingDto = $this->createBookingDto();
|
||
$bookingDto->currentStep = 2;
|
||
$bookingDto->participants = [
|
||
new ParticipantDto(),
|
||
new ParticipantDto(),
|
||
new ParticipantDto(),
|
||
];
|
||
|
||
$summary = $service->getSummaryData($bookingDto);
|
||
|
||
$this->assertSame(3, $summary->participantCount);
|
||
}
|
||
|
||
public function testEditModeUsesActualParticipantCount(): void
|
||
{
|
||
$service = $this->createService();
|
||
$bookingDto = $this->createBookingDto();
|
||
$bookingDto->booking = new Booking();
|
||
$bookingDto->participants = [
|
||
new ParticipantDto(),
|
||
new ParticipantDto(),
|
||
];
|
||
|
||
$summary = $service->getSummaryData($bookingDto);
|
||
|
||
$this->assertSame(2, $summary->participantCount);
|
||
}
|
||
|
||
private function createService(): BookingSummaryAssembler
|
||
{
|
||
$priceCalculator = $this->createMock(BookingPriceCalculator::class);
|
||
$priceCalculator->method('calculateAllParticipantIndividualPrices')->willReturn([]);
|
||
|
||
$pricingAssembler = $this->createMock(BookingPricingAssembler::class);
|
||
$pricingAssembler->method('getPricingBreakdown')->willReturn([
|
||
'rooms' => [],
|
||
'services' => [],
|
||
'surcharges' => null,
|
||
'grandTotal' => 0.0,
|
||
]);
|
||
|
||
return new BookingSummaryAssembler(
|
||
$priceCalculator,
|
||
$pricingAssembler,
|
||
$this->createMock(CmsDataProvider::class),
|
||
$this->createMock(HotelLoader::class),
|
||
$this->createMock(CountryDataProvider::class),
|
||
$this->createMock(CacheInterface::class),
|
||
new NullLogger(),
|
||
);
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|