Files
myep/tests/Service/BookingSummaryDataServiceTest.php
T

88 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Model\Booking;
use App\Form\Model\BookingDto;
use App\Form\Model\BookingSummaryDto;
use App\Service\BookingPriceCalculatorService;
use App\Service\BookingSummaryDataService;
use App\Service\BookingSummaryParticipantCountService;
use App\Service\CmsDataService;
use App\BusProNet\DataProvider\CountryDataProvider;
use App\BusProNet\XmlLoader\HotelLoader;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Contracts\Cache\CacheInterface;
class BookingSummaryDataServiceTest extends TestCase
{
public function testCreateStep1UsesExpectedParticipantCountFromSelectedRooms(): void
{
$service = $this->createService(8);
$bookingDto = $this->createBookingDto();
$summary = $service->getSummaryData($bookingDto);
$this->assertInstanceOf(BookingSummaryDto::class, $summary);
$this->assertSame(8, $summary->participantCount);
}
public function testLaterCreateStepsUseActualParticipantCount(): void
{
$service = $this->createService(3);
$bookingDto = $this->createBookingDto();
$bookingDto->currentStep = 2;
$summary = $service->getSummaryData($bookingDto);
$this->assertSame(3, $summary->participantCount);
}
public function testEditModeUsesActualParticipantCount(): void
{
$service = $this->createService(2);
$bookingDto = $this->createBookingDto();
$bookingDto->booking = new Booking();
$summary = $service->getSummaryData($bookingDto);
$this->assertSame(2, $summary->participantCount);
}
private function createService(int $participantCount): BookingSummaryDataService
{
$priceCalculator = $this->createMock(BookingPriceCalculatorService::class);
$priceCalculator->method('calculateAllParticipantIndividualPrices')->willReturn([]);
$priceCalculator->method('getPricingBreakdown')->willReturn([
'rooms' => [],
'services' => [],
'surcharges' => null,
'grandTotal' => 0.0,
]);
$participantCountService = $this->createMock(BookingSummaryParticipantCountService::class);
$participantCountService->method('calculate')
->willReturn($participantCount);
return new BookingSummaryDataService(
$priceCalculator,
$participantCountService,
$this->createMock(CmsDataService::class),
$this->createMock(HotelLoader::class),
$this->createMock(CountryDataProvider::class),
$this->createMock(CacheInterface::class),
new NullLogger(),
);
}
private function createBookingDto(): BookingDto
{
$bookingDto = new BookingDto(new \App\BusProNet\Model\Travel(), 157047);
return $bookingDto;
}
}