Files
myep/tests/Service/BookingSummaryAssemblerTest.php
T

148 lines
4.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\DataProvider\CountryDataProvider;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Room;
use App\BusProNet\Model\Travel;
use App\BusProNet\XmlLoader\HotelLoader;
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 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);
}
public function testCreateStep1CountsRoomsWithUnknownOccupancyAsZero(): void
{
$service = $this->createService();
$bookingDto = $this->createBookingDto();
$bookingDto->travel->rooms[12] = $this->createRoom(12, null);
$bookingDto->currentStep = 1;
$bookingDto->roomSelections = [
$this->createRoomSelection(10, 1),
$this->createRoomSelection(12, 2),
];
$summary = $service->getSummaryData($bookingDto);
// 1×2 for the known room; the room without occupancy contributes nothing.
$this->assertSame(2, $summary->participantCount);
}
private function createService(): BookingSummaryAssembler
{
$priceCalculator = $this->createStub(BookingPriceCalculator::class);
$priceCalculator->method('calculateAllParticipantIndividualPrices')->willReturn([]);
$pricingAssembler = $this->createStub(BookingPricingAssembler::class);
$pricingAssembler->method('getPricingBreakdown')->willReturn([
'rooms' => [],
'services' => [],
'surcharges' => null,
'grandTotal' => 0.0,
]);
return new BookingSummaryAssembler(
$priceCalculator,
$pricingAssembler,
$this->createStub(CmsDataProvider::class),
$this->createStub(HotelLoader::class),
$this->createStub(CountryDataProvider::class),
$this->createStub(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;
}
}