chore: adopt namespace pattern for accommodation booking controllers
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Groups\Booking;
|
||||
|
||||
use App\Controller\Groups\Booking\IndexController;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class IndexControllerTest extends TestCase
|
||||
{
|
||||
public function testSuccessRendersAndConsumesFlashOnFirstLoad(): void
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$session->getFlashBag()->add('groups_booking_result', 'booking');
|
||||
|
||||
$request = Request::create('/groups/booking/success', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$controller = $this->makeController();
|
||||
|
||||
$response = $controller->success($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('groups/booking/success.html.twig', $controller->renderedView);
|
||||
self::assertSame('booking', $controller->renderedParameters['resultType']);
|
||||
// The flash is read-once: a second read on the same request returns nothing.
|
||||
self::assertSame([], $session->getFlashBag()->get('groups_booking_result'));
|
||||
}
|
||||
|
||||
public function testSuccessRedirectsToLoginWhenFlashIsMissing(): void
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$request = Request::create('/groups/booking/success', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$controller = $this->makeController();
|
||||
|
||||
$response = $controller->success($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_login', $response->headers->get('Location'));
|
||||
}
|
||||
|
||||
private function makeController(): TestableAccommodationIndexController
|
||||
{
|
||||
return new TestableAccommodationIndexController(
|
||||
$this->createMock(AccommodationBookingService::class),
|
||||
$this->createMock(AccommodationSessionManager::class),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableAccommodationIndexController extends IndexController
|
||||
{
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $renderedParameters = [];
|
||||
|
||||
public string $renderedView = '';
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
|
||||
{
|
||||
return new RedirectResponse('/'.$route, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
$this->renderedView = $view;
|
||||
$this->renderedParameters = $parameters;
|
||||
|
||||
return new Response('ok');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Groups\Booking;
|
||||
|
||||
use App\BpnConnect\ContingentsClient;
|
||||
use App\BpnConnect\Model\ContingentCalendarEntry;
|
||||
use App\BpnConnect\Model\ContingentCalendarMeta;
|
||||
use App\BpnConnect\Model\ContingentCalendarResponse;
|
||||
use App\BpnConnect\Model\ContingentStatus;
|
||||
use App\Controller\Groups\Booking\Step1Controller;
|
||||
use App\Entity\Groups\AccommodationPrice;
|
||||
use App\Repository\Groups\AccommodationPriceRepository;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationPriceCoverage;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
use App\Service\CalendarGridBuilder;
|
||||
use App\Service\GroupsPriceCalculator;
|
||||
use App\Service\PriceTimelineBuilder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
class Step1CalendarDataTest extends TestCase
|
||||
{
|
||||
public function testDaysWithoutPriceAreBlockedEvenWhenContingentIsOk(): void
|
||||
{
|
||||
// Contingent says OK for the whole week, prices only cover 03.–05.
|
||||
$price = new AccommodationPrice();
|
||||
$price->setDateFrom(new \DateTimeImmutable('2026-06-03'));
|
||||
$price->setDateTo(new \DateTimeImmutable('2026-06-05'));
|
||||
$price->setMinNights(2);
|
||||
|
||||
$enriched = $this->buildEnrichedDayData(
|
||||
$this->calendarResponse([
|
||||
'2026-06-01' => ContingentStatus::Ok,
|
||||
'2026-06-02' => ContingentStatus::Ok,
|
||||
'2026-06-03' => ContingentStatus::Ok,
|
||||
'2026-06-04' => ContingentStatus::Ok,
|
||||
'2026-06-05' => ContingentStatus::Ok,
|
||||
'2026-06-06' => ContingentStatus::Ok,
|
||||
'2026-06-07' => ContingentStatus::Ok,
|
||||
]),
|
||||
[$price],
|
||||
'2026-06-01',
|
||||
'2026-06-07',
|
||||
);
|
||||
|
||||
self::assertSame('blocked', $enriched['2026-06-01']['status']);
|
||||
self::assertSame('blocked', $enriched['2026-06-02']['status']);
|
||||
// First priced night — arrival only
|
||||
self::assertSame('blocked-to-ok', $enriched['2026-06-03']['status']);
|
||||
self::assertSame('ok', $enriched['2026-06-04']['status']);
|
||||
self::assertSame('ok', $enriched['2026-06-05']['status']);
|
||||
// Day after the last priced night — still valid as checkout
|
||||
self::assertSame('checkout-only', $enriched['2026-06-06']['status']);
|
||||
self::assertSame('blocked', $enriched['2026-06-07']['status']);
|
||||
|
||||
self::assertSame(2, $enriched['2026-06-04']['minNights']);
|
||||
self::assertSame(0, $enriched['2026-06-07']['minNights']);
|
||||
}
|
||||
|
||||
public function testBlockedContingentWinsOverExistingPrice(): void
|
||||
{
|
||||
$price = new AccommodationPrice();
|
||||
$price->setDateFrom(new \DateTimeImmutable('2026-06-01'));
|
||||
$price->setDateTo(new \DateTimeImmutable('2026-06-03'));
|
||||
$price->setMinNights(1);
|
||||
|
||||
$enriched = $this->buildEnrichedDayData(
|
||||
$this->calendarResponse([
|
||||
'2026-06-01' => ContingentStatus::Ok,
|
||||
'2026-06-02' => ContingentStatus::Blocked,
|
||||
'2026-06-03' => ContingentStatus::Ok,
|
||||
]),
|
||||
[$price],
|
||||
'2026-06-01',
|
||||
'2026-06-03',
|
||||
);
|
||||
|
||||
self::assertSame('blocked-to-ok', $enriched['2026-06-01']['status']);
|
||||
self::assertSame('checkout-only', $enriched['2026-06-02']['status']);
|
||||
self::assertSame('blocked-to-ok', $enriched['2026-06-03']['status']);
|
||||
}
|
||||
|
||||
public function testPriceCoverageStillAppliesWhenContingentApiIsUnavailable(): void
|
||||
{
|
||||
$price = new AccommodationPrice();
|
||||
$price->setDateFrom(new \DateTimeImmutable('2026-06-01'));
|
||||
$price->setDateTo(new \DateTimeImmutable('2026-06-02'));
|
||||
$price->setMinNights(1);
|
||||
|
||||
$enriched = $this->buildEnrichedDayData(null, [$price], '2026-06-01', '2026-06-03');
|
||||
|
||||
self::assertSame('blocked-to-ok', $enriched['2026-06-01']['status']);
|
||||
self::assertSame('ok', $enriched['2026-06-02']['status']);
|
||||
self::assertSame('checkout-only', $enriched['2026-06-03']['status']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, ContingentStatus> $statuses
|
||||
*/
|
||||
private function calendarResponse(array $statuses): ContingentCalendarResponse
|
||||
{
|
||||
$entries = [];
|
||||
foreach ($statuses as $date => $status) {
|
||||
$entries[] = new ContingentCalendarEntry(date: $date, status: $status);
|
||||
}
|
||||
|
||||
return new ContingentCalendarResponse(
|
||||
new ContingentCalendarMeta('', '', 'days', 'HOTEL', 1, count($entries)),
|
||||
$entries,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccommodationPrice[] $prices
|
||||
*
|
||||
* @return array<string, array{status: string, minNights: int}>
|
||||
*/
|
||||
private function buildEnrichedDayData(
|
||||
?ContingentCalendarResponse $calendar,
|
||||
array $prices,
|
||||
string $dateFrom,
|
||||
string $dateTo,
|
||||
): array {
|
||||
$cache = $this->createMock(CacheInterface::class);
|
||||
if (null === $calendar) {
|
||||
$cache->method('get')->willThrowException(new \App\BpnConnect\Exception\BpnConnectException('down'));
|
||||
} else {
|
||||
$cache->method('get')->willReturn($calendar);
|
||||
}
|
||||
|
||||
$priceRepository = $this->createMock(AccommodationPriceRepository::class);
|
||||
$priceRepository->method('findByHotelCodeAndDateRange')->willReturn($prices);
|
||||
|
||||
$controller = new Step1Controller(
|
||||
$this->createMock(AccommodationBookingService::class),
|
||||
$this->createMock(AccommodationSessionManager::class),
|
||||
$this->createMock(ContingentsClient::class),
|
||||
$priceRepository,
|
||||
new PriceTimelineBuilder(),
|
||||
$cache,
|
||||
$this->createMock(CalendarGridBuilder::class),
|
||||
$this->createMock(GroupsPriceCalculator::class),
|
||||
new AccommodationPriceCoverage($priceRepository),
|
||||
);
|
||||
|
||||
$method = new \ReflectionMethod($controller, 'buildEnrichedDayData');
|
||||
|
||||
return $method->invoke(
|
||||
$controller,
|
||||
'HOTEL',
|
||||
new \DateTimeImmutable($dateFrom),
|
||||
new \DateTimeImmutable($dateTo),
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Groups\Booking;
|
||||
|
||||
use App\BpnConnect\ContingentsClient;
|
||||
use App\Controller\Groups\Booking\Step1Controller;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Repository\Groups\AccommodationPriceRepository;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationPriceCoverage;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
use App\Service\CalendarGridBuilder;
|
||||
use App\Service\GroupsPriceCalculator;
|
||||
use App\Service\PriceTimelineBuilder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
class Step1ControllerTest extends TestCase
|
||||
{
|
||||
public function testPostWithValidDatesUpdatesSessionAndRedirects(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-1', 'POST', [
|
||||
'date_from' => '2026-08-03',
|
||||
'date_to' => '2026-08-07',
|
||||
]);
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService
|
||||
->method('applyDates')
|
||||
->willReturnCallback(static function (AccommodationBookingDto $dto): void {
|
||||
$dto->dateFrom = new \DateTimeImmutable('2026-08-03');
|
||||
$dto->dateTo = new \DateTimeImmutable('2026-08-07');
|
||||
});
|
||||
$bookingService
|
||||
->method('loadAccommodation')
|
||||
->with(1)
|
||||
->willReturn($accommodation);
|
||||
$bookingService
|
||||
->method('computeInitialPaxCount')
|
||||
->willReturn(4);
|
||||
|
||||
$controller = $this->makeController($bookingService, $sessionManager);
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_groups_booking_step_2', $response->headers->get('Location'));
|
||||
|
||||
$savedDto = $sessionManager->getOrFail($request);
|
||||
self::assertSame(2, $savedDto->currentStep);
|
||||
self::assertSame(4, $savedDto->paxCount);
|
||||
self::assertNull($savedDto->selectedBoardServiceId);
|
||||
self::assertSame([], $savedDto->selectedAdditionalServiceIds);
|
||||
}
|
||||
|
||||
public function testPostWithInvalidDatesRedirectsBackWithFlash(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-1', 'POST', [
|
||||
'date_from' => 'not-a-date',
|
||||
'date_to' => '2026-08-07',
|
||||
]);
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService
|
||||
->method('applyDates')
|
||||
->willThrowException(new \InvalidArgumentException('Ungültiges Datumsformat. Erwartet: YYYY-MM-DD.'));
|
||||
|
||||
$controller = $this->makeController($bookingService, $sessionManager);
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_groups_booking_step_1', $response->headers->get('Location'));
|
||||
}
|
||||
|
||||
private function makeController(
|
||||
AccommodationBookingService $bookingService,
|
||||
AccommodationSessionManager $sessionManager,
|
||||
): TestableAccommodationStep1Controller {
|
||||
$priceRepository = $this->createMock(AccommodationPriceRepository::class);
|
||||
|
||||
return new TestableAccommodationStep1Controller(
|
||||
$bookingService,
|
||||
$sessionManager,
|
||||
$this->createMock(ContingentsClient::class),
|
||||
$priceRepository,
|
||||
new PriceTimelineBuilder(),
|
||||
$this->createMock(CacheInterface::class),
|
||||
new CalendarGridBuilder(),
|
||||
new GroupsPriceCalculator(new PriceTimelineBuilder(), ['runningCostsEur' => 0, 'runningCostsChf' => 0, 'undersubscription30Eur' => 0, 'undersubscription30Chf' => 0, 'undersubscription40Eur' => 0, 'undersubscription40Chf' => 0]),
|
||||
new AccommodationPriceCoverage($priceRepository),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableAccommodationStep1Controller extends Step1Controller
|
||||
{
|
||||
public function __construct(
|
||||
AccommodationBookingService $bookingService,
|
||||
AccommodationSessionManager $sessionManager,
|
||||
ContingentsClient $contingentsClient,
|
||||
AccommodationPriceRepository $priceRepository,
|
||||
PriceTimelineBuilder $priceTimelineBuilder,
|
||||
CacheInterface $cache,
|
||||
CalendarGridBuilder $calendarGridBuilder,
|
||||
GroupsPriceCalculator $priceCalculator,
|
||||
AccommodationPriceCoverage $priceCoverage,
|
||||
) {
|
||||
parent::__construct(
|
||||
$bookingService,
|
||||
$sessionManager,
|
||||
$contingentsClient,
|
||||
$priceRepository,
|
||||
$priceTimelineBuilder,
|
||||
$cache,
|
||||
$calendarGridBuilder,
|
||||
$priceCalculator,
|
||||
$priceCoverage,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
|
||||
{
|
||||
return new RedirectResponse('/'.$route, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
throw new \LogicException('Render should not be called in this test.');
|
||||
}
|
||||
|
||||
protected function addFlash(string $type, mixed $message): void
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Groups\Booking;
|
||||
|
||||
use App\Controller\Groups\Booking\Step2Controller;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Model\InquiryStatus;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
use App\Service\GroupsPriceCalculator;
|
||||
use App\Service\PriceTimelineBuilder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class Step2ControllerTest extends TestCase
|
||||
{
|
||||
public function testSubmitRecomputesBookingModeAfterFormBinding(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 2;
|
||||
$dto->accommodationId = 1;
|
||||
$dto->dateFrom = new \DateTimeImmutable('2026-03-01');
|
||||
$dto->dateTo = new \DateTimeImmutable('2026-03-05');
|
||||
$dto->paxCount = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-2', 'POST');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form
|
||||
->method('handleRequest')
|
||||
->willReturnCallback(function () use ($dto, $form): FormInterface {
|
||||
$dto->paxCount = 3;
|
||||
|
||||
return $form;
|
||||
});
|
||||
$form
|
||||
->method('isSubmitted')
|
||||
->willReturn(true);
|
||||
$form
|
||||
->method('isValid')
|
||||
->willReturn(true);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService
|
||||
->method('loadAccommodation')
|
||||
->with(1)
|
||||
->willReturn($accommodation);
|
||||
$bookingService
|
||||
->method('loadPrices')
|
||||
->with($dto, $accommodation)
|
||||
->willReturn([]);
|
||||
$bookingService
|
||||
->method('loadAvailableServices')
|
||||
->with($dto, $accommodation)
|
||||
->willReturn([
|
||||
'boardServices' => [],
|
||||
'additionalServices' => [],
|
||||
'groupedAdditionalServices' => [],
|
||||
'ungroupedAdditionalServices' => [],
|
||||
]);
|
||||
$bookingService
|
||||
->expects(self::once())
|
||||
->method('computeInquiryStatus')
|
||||
->with(self::callback(static fn (AccommodationBookingDto $submittedDto): bool => 3 === $submittedDto->paxCount), [])
|
||||
->willReturn(new InquiryStatus(true, ['Mindestaufenthalt: 5 Nächte (gebucht: 4)']));
|
||||
|
||||
$controller = new TestableAccommodationStep2Controller(
|
||||
$bookingService,
|
||||
$sessionManager,
|
||||
new GroupsPriceCalculator(new PriceTimelineBuilder(), ['runningCostsEur' => 0, 'runningCostsChf' => 0, 'undersubscription30Eur' => 0, 'undersubscription30Chf' => 0, 'undersubscription40Eur' => 0, 'undersubscription40Chf' => 0]),
|
||||
$form,
|
||||
);
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/groups/booking/step-3', $response->headers->get('Location'));
|
||||
self::assertTrue($sessionManager->getOrFail($request)->isInquiry);
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableAccommodationStep2Controller extends Step2Controller
|
||||
{
|
||||
/**
|
||||
* @param FormInterface<mixed> $form
|
||||
*/
|
||||
public function __construct(
|
||||
AccommodationBookingService $bookingService,
|
||||
AccommodationSessionManager $sessionManager,
|
||||
GroupsPriceCalculator $priceCalculator,
|
||||
private readonly FormInterface $form,
|
||||
) {
|
||||
parent::__construct($bookingService, $sessionManager, $priceCalculator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FormInterface<mixed>
|
||||
*/
|
||||
protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface
|
||||
{
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
|
||||
{
|
||||
return new RedirectResponse('/groups/booking/step-3', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
throw new \LogicException('Render should not be called in this test.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Groups\Booking;
|
||||
|
||||
use App\Controller\Groups\Booking\Step3Controller;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class Step3ControllerTest extends TestCase
|
||||
{
|
||||
public function testSummaryReceivesSelectedServiceCatalogs(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 3;
|
||||
$dto->accommodationId = 1;
|
||||
$dto->dateFrom = new \DateTimeImmutable('2026-03-01');
|
||||
$dto->dateTo = new \DateTimeImmutable('2026-03-05');
|
||||
$dto->selectedBoardServiceId = 10;
|
||||
$dto->selectedAdditionalServiceIds = [20];
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-3', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$form = $this->createFormMock(submitted: false, valid: false);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$boardService = (new BoardService())->setLabel('Halbpension')->setPrice(1000);
|
||||
$additionalService = (new AdditionalService())->setLabel('Skipass')->setPrice(2000);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService
|
||||
->method('loadAccommodation')
|
||||
->with(1)
|
||||
->willReturn($accommodation);
|
||||
$bookingService
|
||||
->expects(self::once())
|
||||
->method('loadAvailableServices')
|
||||
->with($dto, $accommodation)
|
||||
->willReturn([
|
||||
'boardServices' => [$boardService],
|
||||
'additionalServices' => [$additionalService],
|
||||
'groupedAdditionalServices' => [],
|
||||
'ungroupedAdditionalServices' => [$additionalService],
|
||||
]);
|
||||
|
||||
$controller = new TestableAccommodationStep3Controller($bookingService, $sessionManager, $form);
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('groups/booking/step_3.html.twig', $controller->renderedView);
|
||||
self::assertSame([$boardService], $controller->renderedParameters['ctx']->boardServices);
|
||||
self::assertSame([$additionalService], $controller->renderedParameters['ctx']->additionalServices);
|
||||
}
|
||||
|
||||
public function testValidSubmitRedirectsToStep4WithoutPersisting(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 3;
|
||||
$dto->accommodationId = 1;
|
||||
$dto->isInquiry = false;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-3', 'POST');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$form = $this->createFormMock(submitted: true, valid: true);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
$bookingService->method('loadAvailableServices')->willReturn([
|
||||
'boardServices' => [],
|
||||
'additionalServices' => [],
|
||||
'groupedAdditionalServices' => [],
|
||||
'ungroupedAdditionalServices' => [],
|
||||
]);
|
||||
$bookingService->expects(self::never())->method('finalizeBooking');
|
||||
|
||||
$controller = new TestableAccommodationStep3Controller($bookingService, $sessionManager, $form);
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_groups_booking_step_4', $response->getTargetUrl());
|
||||
self::assertSame(4, $dto->currentStep);
|
||||
self::assertSame($dto, $sessionManager->getDto($request));
|
||||
}
|
||||
|
||||
public function testInvalidSubmitReRendersFormWithErrors(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 3;
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-3', 'POST');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$form = $this->createFormMock(submitted: true, valid: false);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
$bookingService->method('loadAvailableServices')->willReturn([
|
||||
'boardServices' => [],
|
||||
'additionalServices' => [],
|
||||
'groupedAdditionalServices' => [],
|
||||
'ungroupedAdditionalServices' => [],
|
||||
]);
|
||||
|
||||
$controller = new TestableAccommodationStep3Controller($bookingService, $sessionManager, $form);
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('groups/booking/step_3.html.twig', $controller->renderedView);
|
||||
self::assertSame(3, $dto->currentStep);
|
||||
self::assertSame($dto, $sessionManager->getDto($request));
|
||||
}
|
||||
|
||||
private function createFormMock(bool $submitted, bool $valid): FormInterface
|
||||
{
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('handleRequest')->willReturnSelf();
|
||||
$form->method('isSubmitted')->willReturn($submitted);
|
||||
$form->method('isValid')->willReturn($valid);
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableAccommodationStep3Controller extends Step3Controller
|
||||
{
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $renderedParameters = [];
|
||||
|
||||
public string $renderedView = '';
|
||||
|
||||
public function __construct(
|
||||
AccommodationBookingService $bookingService,
|
||||
AccommodationSessionManager $sessionManager,
|
||||
private readonly FormInterface $form,
|
||||
) {
|
||||
parent::__construct($bookingService, $sessionManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FormInterface<mixed>
|
||||
*/
|
||||
protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface
|
||||
{
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
|
||||
{
|
||||
return new RedirectResponse('/'.$route, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function generateUrl(string $route, array $parameters = [], int $referenceType = 1): string
|
||||
{
|
||||
return '/'.$route;
|
||||
}
|
||||
|
||||
protected function addFlash(string $type, mixed $message): void
|
||||
{
|
||||
// no-op: avoids requiring a full service container in these unit tests
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
$this->renderedView = $view;
|
||||
$this->renderedParameters = $parameters;
|
||||
|
||||
return new Response('ok');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,408 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Groups\Booking;
|
||||
|
||||
use App\Controller\Groups\Booking\Step4Controller;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
use App\Service\AccommodationTermsUrlProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class Step4ControllerTest extends TestCase
|
||||
{
|
||||
public function testIndexRendersRecapWhenStepFourReached(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 4;
|
||||
$dto->accommodationId = 1;
|
||||
$dto->isInquiry = false;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-4', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
$bookingService->method('loadAvailableServices')->willReturn([
|
||||
'boardServices' => [],
|
||||
'additionalServices' => [],
|
||||
'groupedAdditionalServices' => [],
|
||||
'ungroupedAdditionalServices' => [],
|
||||
]);
|
||||
|
||||
$controller = new TestableStep4Controller($bookingService, $sessionManager, $this->createMock(FormInterface::class));
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('groups/booking/step_4.html.twig', $controller->renderedView);
|
||||
self::assertSame($dto, $controller->renderedParameters['dto']);
|
||||
}
|
||||
|
||||
public function testIndexRedirectsToStep3WhenNotYetReached(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 3;
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-4', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$controller = new TestableStep4Controller(
|
||||
$this->createMock(AccommodationBookingService::class),
|
||||
$sessionManager,
|
||||
$this->createMock(FormInterface::class),
|
||||
);
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_groups_booking_step_3', $response->getTargetUrl());
|
||||
}
|
||||
|
||||
public function testIndexPostWithValidCsrfPersistsAsInquiryAndRedirects(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 4;
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-4', 'POST');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$booking = (new AccommodationBooking())->setOrigin(AccommodationBookingOrigin::Offer);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
$bookingService->method('loadAvailableServices')->willReturn([
|
||||
'boardServices' => [],
|
||||
'additionalServices' => [],
|
||||
'groupedAdditionalServices' => [],
|
||||
'ungroupedAdditionalServices' => [],
|
||||
]);
|
||||
$bookingService->method('loadPrices')->willReturn([]);
|
||||
$bookingService->expects(self::once())->method('finalizeBooking')->willReturn($booking);
|
||||
|
||||
$inquiryForm = $this->createMock(FormInterface::class);
|
||||
$inquiryForm->method('handleRequest')->willReturnSelf();
|
||||
$inquiryForm->method('isSubmitted')->willReturn(true);
|
||||
$inquiryForm->method('isValid')->willReturn(true);
|
||||
|
||||
$controller = new TestableStep4Controller($bookingService, $sessionManager, $inquiryForm);
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_groups_booking_success', $response->getTargetUrl());
|
||||
self::assertTrue($dto->forceInquiry);
|
||||
self::assertNull($sessionManager->getDto($request));
|
||||
}
|
||||
|
||||
public function testIndexPostWithInvalidFormThrowsAccessDenied(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 4;
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-4', 'POST');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
$bookingService->method('loadAvailableServices')->willReturn([
|
||||
'boardServices' => [],
|
||||
'additionalServices' => [],
|
||||
'groupedAdditionalServices' => [],
|
||||
'ungroupedAdditionalServices' => [],
|
||||
]);
|
||||
$bookingService->expects(self::never())->method('finalizeBooking');
|
||||
|
||||
$inquiryForm = $this->createMock(FormInterface::class);
|
||||
$inquiryForm->method('handleRequest')->willReturnSelf();
|
||||
$inquiryForm->method('isSubmitted')->willReturn(true);
|
||||
$inquiryForm->method('isValid')->willReturn(false);
|
||||
|
||||
$controller = new TestableStep4Controller($bookingService, $sessionManager, $inquiryForm);
|
||||
|
||||
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
|
||||
|
||||
$controller->index($request);
|
||||
}
|
||||
|
||||
public function testConfirmInquiryGetRendersModal(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 4;
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-4/confirm-inquiry', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$controller = new TestableStep4Controller(
|
||||
$this->createMock(AccommodationBookingService::class),
|
||||
$sessionManager,
|
||||
$this->createMock(FormInterface::class),
|
||||
);
|
||||
|
||||
$response = $controller->confirmInquiry($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('groups/booking/modal_inquiry_confirmation.html.twig', $controller->renderedView);
|
||||
}
|
||||
|
||||
public function testConfirmInquiryRedirectsToStep3WhenNotYetReached(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 3;
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-4/confirm-inquiry', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$controller = new TestableStep4Controller(
|
||||
$this->createMock(AccommodationBookingService::class),
|
||||
$sessionManager,
|
||||
$this->createMock(FormInterface::class),
|
||||
);
|
||||
|
||||
$response = $controller->confirmInquiry($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_groups_booking_step_3', $response->getTargetUrl());
|
||||
}
|
||||
|
||||
public function testConfirmGetRendersModalWithFreshForm(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 4;
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-4/confirm', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
$bookingService->expects(self::never())->method('finalizeBooking');
|
||||
|
||||
$confirmationForm = $this->createMock(FormInterface::class);
|
||||
$confirmationForm->method('handleRequest')->willReturnSelf();
|
||||
$confirmationForm->method('isSubmitted')->willReturn(false);
|
||||
|
||||
$controller = new TestableStep4Controller($bookingService, $sessionManager, $confirmationForm);
|
||||
|
||||
$response = $controller->confirm($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('groups/booking/modal_booking_confirmation.html.twig', $controller->renderedView);
|
||||
self::assertSame($confirmationForm, $controller->renderedParameters['confirmationForm']);
|
||||
self::assertSame($dto, $sessionManager->getDto($request));
|
||||
}
|
||||
|
||||
public function testConfirmPostValidPersistsAndRedirects(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 4;
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-4/confirm', 'POST');
|
||||
$request->setSession($session);
|
||||
$request->headers->set('HX-Request', 'true');
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$booking = (new AccommodationBooking())->setOrigin(AccommodationBookingOrigin::Direct);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
$bookingService->method('loadAvailableServices')->willReturn([
|
||||
'boardServices' => [],
|
||||
'additionalServices' => [],
|
||||
'groupedAdditionalServices' => [],
|
||||
'ungroupedAdditionalServices' => [],
|
||||
]);
|
||||
$bookingService->method('loadPrices')->willReturn([]);
|
||||
$bookingService->expects(self::once())->method('finalizeBooking')->willReturn($booking);
|
||||
|
||||
$confirmationForm = $this->createMock(FormInterface::class);
|
||||
$confirmationForm->method('handleRequest')->willReturnSelf();
|
||||
$confirmationForm->method('isSubmitted')->willReturn(true);
|
||||
$confirmationForm->method('isValid')->willReturn(true);
|
||||
|
||||
$controller = new TestableStep4Controller($bookingService, $sessionManager, $confirmationForm);
|
||||
|
||||
$response = $controller->confirm($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertTrue($response->headers->has('HX-Redirect'));
|
||||
self::assertNull($sessionManager->getDto($request));
|
||||
}
|
||||
|
||||
public function testConfirmPostInvalidReRendersModalWithoutPersisting(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->currentStep = 4;
|
||||
$dto->accommodationId = 1;
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/groups/booking/step-4/confirm', 'POST');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
$bookingService->expects(self::never())->method('finalizeBooking');
|
||||
|
||||
$confirmationForm = $this->createMock(FormInterface::class);
|
||||
$confirmationForm->method('handleRequest')->willReturnSelf();
|
||||
$confirmationForm->method('isSubmitted')->willReturn(true);
|
||||
$confirmationForm->method('isValid')->willReturn(false);
|
||||
|
||||
$controller = new TestableStep4Controller($bookingService, $sessionManager, $confirmationForm);
|
||||
|
||||
$response = $controller->confirm($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertFalse($response->headers->has('HX-Redirect'));
|
||||
self::assertSame('groups/booking/modal_booking_confirmation.html.twig', $controller->renderedView);
|
||||
self::assertNotNull($sessionManager->getDto($request));
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableStep4Controller extends Step4Controller
|
||||
{
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $renderedParameters = [];
|
||||
|
||||
public string $renderedView = '';
|
||||
|
||||
public function __construct(
|
||||
AccommodationBookingService $bookingService,
|
||||
AccommodationSessionManager $sessionManager,
|
||||
private readonly FormInterface $form,
|
||||
) {
|
||||
parent::__construct(
|
||||
$bookingService,
|
||||
$sessionManager,
|
||||
new AccommodationTermsUrlProvider(['AT' => '', 'CH' => '', 'IT' => ''], 'https://example.test/agb/'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FormInterface<mixed>
|
||||
*/
|
||||
protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface
|
||||
{
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
protected function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null
|
||||
{
|
||||
return 'https://example.test/agb/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
|
||||
{
|
||||
return new RedirectResponse('/'.$route, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function generateUrl(string $route, array $parameters = [], int $referenceType = 1): string
|
||||
{
|
||||
return '/'.$route;
|
||||
}
|
||||
|
||||
protected function addFlash(string $type, mixed $message): void
|
||||
{
|
||||
// no-op: avoids requiring a full service container in these unit tests
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
$this->renderedView = $view;
|
||||
$this->renderedParameters = $parameters;
|
||||
|
||||
return new Response('ok');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user