wip: group inquiries and bookings
This commit is contained in:
1 parent
6a6051e92b
commit
505bda46cf
115 files changed
+8107
-424
No files matched your search
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Accommodation;
|
||||
|
||||
use App\Controller\Groups\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,164 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Accommodation;
|
||||
|
||||
use App\BpnConnect\ContingentsClient;
|
||||
use App\Controller\Groups\Step1Controller;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Repository\Groups\AccommodationPriceRepository;
|
||||
use App\Service\AccommodationBookingService;
|
||||
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 {
|
||||
return new TestableAccommodationStep1Controller(
|
||||
$bookingService,
|
||||
$sessionManager,
|
||||
$this->createMock(ContingentsClient::class),
|
||||
$this->createMock(AccommodationPriceRepository::class),
|
||||
new PriceTimelineBuilder(),
|
||||
$this->createMock(CacheInterface::class),
|
||||
new CalendarGridBuilder(),
|
||||
new GroupsPriceCalculator(new PriceTimelineBuilder(), ['runningCostsEur' => 0, 'runningCostsChf' => 0, 'undersubscription30Eur' => 0, 'undersubscription30Chf' => 0, 'undersubscription40Eur' => 0, 'undersubscription40Chf' => 0]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableAccommodationStep1Controller extends Step1Controller
|
||||
{
|
||||
public function __construct(
|
||||
AccommodationBookingService $bookingService,
|
||||
AccommodationSessionManager $sessionManager,
|
||||
ContingentsClient $contingentsClient,
|
||||
AccommodationPriceRepository $priceRepository,
|
||||
PriceTimelineBuilder $priceTimelineBuilder,
|
||||
CacheInterface $cache,
|
||||
CalendarGridBuilder $calendarGridBuilder,
|
||||
GroupsPriceCalculator $priceCalculator,
|
||||
) {
|
||||
parent::__construct(
|
||||
$bookingService,
|
||||
$sessionManager,
|
||||
$contingentsClient,
|
||||
$priceRepository,
|
||||
$priceTimelineBuilder,
|
||||
$cache,
|
||||
$calendarGridBuilder,
|
||||
$priceCalculator,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,136 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Accommodation;
|
||||
|
||||
use App\Controller\Groups\Step2Controller;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
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(['isInquiry' => true, 'reasons' => ['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,304 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Accommodation;
|
||||
|
||||
use App\Controller\Groups\Step3Controller;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Form\AccommodationStep3ConfirmationType;
|
||||
use App\Form\AccommodationStep3Type;
|
||||
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\Form\SubmitButton;
|
||||
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->createMock(FormInterface::class);
|
||||
$form
|
||||
->method('handleRequest')
|
||||
->willReturnSelf();
|
||||
$form
|
||||
->method('isSubmitted')
|
||||
->willReturn(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 testClickingBuchenOpensConfirmationModalWithoutPersisting(): 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);
|
||||
|
||||
$submitBookingButton = $this->getMockBuilder(SubmitButton::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['isClicked'])
|
||||
->getMock();
|
||||
$submitBookingButton->method('isClicked')->willReturn(true);
|
||||
|
||||
$mainForm = $this->createMock(FormInterface::class);
|
||||
$mainForm->method('handleRequest')->willReturnSelf();
|
||||
$mainForm->method('isSubmitted')->willReturn(true);
|
||||
$mainForm->method('isValid')->willReturn(true);
|
||||
$mainForm->method('has')->with('submitBooking')->willReturn(true);
|
||||
$mainForm->method('get')->with('submitBooking')->willReturn($submitBookingButton);
|
||||
|
||||
$confirmationForm = $this->createMock(FormInterface::class);
|
||||
|
||||
$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('persist');
|
||||
|
||||
$controller = new TestableAccommodationStep3Controller(
|
||||
$bookingService,
|
||||
$sessionManager,
|
||||
[AccommodationStep3Type::class => $mainForm, AccommodationStep3ConfirmationType::class => $confirmationForm],
|
||||
);
|
||||
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('groups/booking/step_3.html.twig', $controller->renderedView);
|
||||
self::assertSame($confirmationForm, $controller->renderedParameters['confirmationForm']);
|
||||
self::assertFalse($dto->forceInquiry);
|
||||
self::assertSame($dto, $sessionManager->getDto($request));
|
||||
}
|
||||
|
||||
public function testConfirmPersistsBookingOnValidConfirmationForm(): 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/confirm', 'POST');
|
||||
$request->setSession($session);
|
||||
$request->headers->set('HX-Request', 'true');
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$confirmationForm = $this->createMock(FormInterface::class);
|
||||
$confirmationForm->method('handleRequest')->willReturnSelf();
|
||||
$confirmationForm->method('isSubmitted')->willReturn(true);
|
||||
$confirmationForm->method('isValid')->willReturn(true);
|
||||
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$booking = (new AccommodationBooking())->setIsInquiry(false);
|
||||
|
||||
$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('persist')->willReturn($booking);
|
||||
$bookingService->expects(self::once())->method('sendNotificationEmail');
|
||||
|
||||
$controller = new TestableAccommodationStep3Controller(
|
||||
$bookingService,
|
||||
$sessionManager,
|
||||
[AccommodationStep3ConfirmationType::class => $confirmationForm],
|
||||
);
|
||||
|
||||
$response = $controller->confirm($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertTrue($response->headers->has('HX-Redirect'));
|
||||
self::assertNull($sessionManager->getDto($request));
|
||||
}
|
||||
|
||||
public function testConfirmRerendersModalWhenTermsNotAccepted(): 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/confirm', 'POST');
|
||||
$request->setSession($session);
|
||||
|
||||
$sessionManager = new AccommodationSessionManager();
|
||||
$sessionManager->save($request, $dto);
|
||||
|
||||
$confirmationForm = $this->createMock(FormInterface::class);
|
||||
$confirmationForm->method('handleRequest')->willReturnSelf();
|
||||
$confirmationForm->method('isSubmitted')->willReturn(true);
|
||||
$confirmationForm->method('isValid')->willReturn(false);
|
||||
|
||||
$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('persist');
|
||||
|
||||
$controller = new TestableAccommodationStep3Controller(
|
||||
$bookingService,
|
||||
$sessionManager,
|
||||
[AccommodationStep3ConfirmationType::class => $confirmationForm],
|
||||
);
|
||||
|
||||
$response = $controller->confirm($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertFalse($response->headers->has('HX-Redirect'));
|
||||
self::assertSame('groups/booking/_step3_confirmation_modal.html.twig', $controller->renderedView);
|
||||
self::assertNotNull($sessionManager->getDto($request));
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableAccommodationStep3Controller extends Step3Controller
|
||||
{
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $renderedParameters = [];
|
||||
|
||||
public string $renderedView = '';
|
||||
|
||||
/**
|
||||
* @param FormInterface<mixed>|array<class-string, FormInterface<mixed>> $form
|
||||
*/
|
||||
public function __construct(
|
||||
AccommodationBookingService $bookingService,
|
||||
AccommodationSessionManager $sessionManager,
|
||||
private readonly FormInterface|array $form,
|
||||
) {
|
||||
parent::__construct($bookingService, $sessionManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FormInterface<mixed>
|
||||
*/
|
||||
protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface
|
||||
{
|
||||
if (is_array($this->form)) {
|
||||
return $this->form[$type];
|
||||
}
|
||||
|
||||
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,296 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Api;
|
||||
|
||||
use App\Controller\Api\AccommodationBookingController;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use App\Service\AccommodationBookingBreakdownCalculator;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
|
||||
class AccommodationBookingControllerTest extends TestCase
|
||||
{
|
||||
public function testSingleReturnsBookingDataForKnownUuid(): void
|
||||
{
|
||||
$accommodation = new Accommodation();
|
||||
$accommodation->setName('Berghotel');
|
||||
$accommodation->setCalendarCode('CAL123');
|
||||
$accommodation->setCmsCode('CMS456');
|
||||
$accommodation->setMaxAdolescentAge(15);
|
||||
$accommodation->setCurrency('EUR');
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setAccommodation($accommodation);
|
||||
$booking->setDateFrom(new \DateTimeImmutable('2026-07-20'));
|
||||
$booking->setDateTo(new \DateTimeImmutable('2026-07-25'));
|
||||
$booking->setPaxCount(40);
|
||||
$booking->setMinorsCount(2);
|
||||
$booking->setChildrenCount(1);
|
||||
$booking->setGroupName('Schulklasse 7b');
|
||||
$booking->setSalutation('Frau');
|
||||
$booking->setFirstName('Mia');
|
||||
$booking->setLastName('Muster');
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setPhone('+49123456789');
|
||||
$booking->setStreet('Musterstr. 1');
|
||||
$booking->setZip('12345');
|
||||
$booking->setCity('Musterstadt');
|
||||
$booking->setRemarks('Bitte am Bahnhof abholen');
|
||||
$booking->setBoardServiceLabel('Halbpension');
|
||||
$booking->setBoardServicePrice(1500);
|
||||
$booking->addAdditionalServiceSnapshot('Bettwäsche', 500, 'flat', 3);
|
||||
$booking->setDiscount(1000);
|
||||
$booking->setIsInquiry(false);
|
||||
$booking->setAcceptedAt(new \DateTimeImmutable('2026-07-15T10:00:00+00:00'));
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository
|
||||
->expects(self::once())
|
||||
->method('findOneBy')
|
||||
->with(['uuid' => $booking->getUuid()])
|
||||
->willReturn($booking);
|
||||
|
||||
$breakdown = ['total' => 12345, 'currency' => 'EUR'];
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator
|
||||
->expects(self::once())
|
||||
->method('compute')
|
||||
->with($booking)
|
||||
->willReturn($breakdown);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('acceptBooking');
|
||||
|
||||
$controller = new AccommodationBookingController($bookingRepository, $breakdownCalculator, $this->serializer(), $bookingService);
|
||||
|
||||
$response = $controller->single($booking->getUuid());
|
||||
$payload = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
self::assertSame([
|
||||
'uuid' => $booking->getUuid(),
|
||||
'status' => 'booking',
|
||||
'dateFrom' => '2026-07-20',
|
||||
'dateTo' => '2026-07-25',
|
||||
'nights' => 5,
|
||||
'paxCount' => 40,
|
||||
'minorsCount' => 2,
|
||||
'childrenCount' => 1,
|
||||
'groupName' => 'Schulklasse 7b',
|
||||
'acceptedAt' => '2026-07-15T10:00:00+00:00',
|
||||
'personalData' => [
|
||||
'salutation' => 'Frau',
|
||||
'firstName' => 'Mia',
|
||||
'lastName' => 'Muster',
|
||||
'email' => '[email protected]',
|
||||
'phone' => '+49123456789',
|
||||
'street' => 'Musterstr. 1',
|
||||
'zip' => '12345',
|
||||
'city' => 'Musterstadt',
|
||||
'remarks' => 'Bitte am Bahnhof abholen',
|
||||
],
|
||||
'accommodation' => [
|
||||
'calendarCode' => 'CAL123',
|
||||
'cmsCode' => 'CMS456',
|
||||
],
|
||||
'boardService' => [
|
||||
'label' => 'Halbpension',
|
||||
'price' => 1500,
|
||||
],
|
||||
'additionalServices' => [
|
||||
[
|
||||
'label' => 'Bettwäsche',
|
||||
'price' => 500,
|
||||
'type' => 'flat',
|
||||
],
|
||||
],
|
||||
'discount' => 1000,
|
||||
'priceBreakdown' => $breakdown,
|
||||
], $payload);
|
||||
|
||||
// CMS-only accommodation fields must not leak into the response.
|
||||
self::assertArrayNotHasKey('name', $payload['accommodation']);
|
||||
self::assertArrayNotHasKey('maxAdolescentAge', $payload['accommodation']);
|
||||
self::assertArrayNotHasKey('currency', $payload['accommodation']);
|
||||
}
|
||||
|
||||
public function testSingleReturnsInquiryStatusWhenBookingIsInquiry(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setDateFrom(new \DateTimeImmutable('2026-08-01'));
|
||||
$booking->setDateTo(new \DateTimeImmutable('2026-08-02'));
|
||||
$booking->setGroupName('Verein e.V.');
|
||||
$booking->setFirstName('Tom');
|
||||
$booking->setLastName('Beispiel');
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setIsInquiry(true);
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository
|
||||
->method('findOneBy')
|
||||
->with(['uuid' => $booking->getUuid()])
|
||||
->willReturn($booking);
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->method('compute')->willReturn(null);
|
||||
|
||||
$controller = new AccommodationBookingController($bookingRepository, $breakdownCalculator, $this->serializer(), $this->createMock(AccommodationBookingService::class));
|
||||
|
||||
$response = $controller->single($booking->getUuid());
|
||||
$payload = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertSame('inquiry', $payload['status']);
|
||||
self::assertNull($payload['priceBreakdown']);
|
||||
self::assertNull($payload['acceptedAt']);
|
||||
}
|
||||
|
||||
public function testSingleReturnsNotFoundForUnknownUuid(): void
|
||||
{
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository
|
||||
->expects(self::once())
|
||||
->method('findOneBy')
|
||||
->with(['uuid' => 'unknown-uuid'])
|
||||
->willReturn(null);
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->expects(self::never())->method('compute');
|
||||
|
||||
$controller = new AccommodationBookingController($bookingRepository, $breakdownCalculator, $this->serializer(), $this->createMock(AccommodationBookingService::class));
|
||||
|
||||
$response = $controller->single('unknown-uuid');
|
||||
$payload = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
self::assertSame(['message' => 'Not found'], $payload);
|
||||
}
|
||||
|
||||
public function testAcceptTransitionsInquiryToBookingAndSetsAcceptedAt(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setDateFrom(new \DateTimeImmutable('2026-08-01'));
|
||||
$booking->setDateTo(new \DateTimeImmutable('2026-08-02'));
|
||||
$booking->setGroupName('Verein e.V.');
|
||||
$booking->setFirstName('Tom');
|
||||
$booking->setLastName('Beispiel');
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setIsInquiry(true);
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository
|
||||
->expects(self::once())
|
||||
->method('findOneBy')
|
||||
->with(['uuid' => $booking->getUuid()])
|
||||
->willReturn($booking);
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->method('compute')->willReturn(null);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService
|
||||
->expects(self::once())
|
||||
->method('acceptBooking')
|
||||
->with($booking)
|
||||
->willReturnCallback(static function (AccommodationBooking $b): void {
|
||||
$b->setIsInquiry(false);
|
||||
$b->setAcceptedAt(new \DateTimeImmutable());
|
||||
});
|
||||
|
||||
$controller = new AccommodationBookingController($bookingRepository, $breakdownCalculator, $this->serializer(), $bookingService);
|
||||
|
||||
$response = $controller->accept($booking->getUuid());
|
||||
$payload = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
self::assertSame('booking', $payload['status']);
|
||||
self::assertFalse($booking->isInquiry());
|
||||
self::assertNotNull($booking->getAcceptedAt());
|
||||
self::assertSame($booking->getAcceptedAt()->format(\DATE_ATOM), $payload['acceptedAt']);
|
||||
}
|
||||
|
||||
public function testAcceptIsIdempotentWhenBookingAlreadyAccepted(): void
|
||||
{
|
||||
$acceptedAt = new \DateTimeImmutable('2026-07-15T10:00:00+00:00');
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setDateFrom(new \DateTimeImmutable('2026-08-01'));
|
||||
$booking->setDateTo(new \DateTimeImmutable('2026-08-02'));
|
||||
$booking->setGroupName('Verein e.V.');
|
||||
$booking->setFirstName('Tom');
|
||||
$booking->setLastName('Beispiel');
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setIsInquiry(false);
|
||||
$booking->setAcceptedAt($acceptedAt);
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository
|
||||
->method('findOneBy')
|
||||
->with(['uuid' => $booking->getUuid()])
|
||||
->willReturn($booking);
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->method('compute')->willReturn(null);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::once())->method('acceptBooking')->with($booking);
|
||||
|
||||
$controller = new AccommodationBookingController($bookingRepository, $breakdownCalculator, $this->serializer(), $bookingService);
|
||||
|
||||
$response = $controller->accept($booking->getUuid());
|
||||
$payload = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
self::assertSame('booking', $payload['status']);
|
||||
self::assertSame($acceptedAt, $booking->getAcceptedAt());
|
||||
self::assertSame($acceptedAt->format(\DATE_ATOM), $payload['acceptedAt']);
|
||||
}
|
||||
|
||||
public function testAcceptReturnsNotFoundForUnknownUuid(): void
|
||||
{
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository
|
||||
->expects(self::once())
|
||||
->method('findOneBy')
|
||||
->with(['uuid' => 'unknown-uuid'])
|
||||
->willReturn(null);
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->expects(self::never())->method('compute');
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('acceptBooking');
|
||||
|
||||
$controller = new AccommodationBookingController($bookingRepository, $breakdownCalculator, $this->serializer(), $bookingService);
|
||||
|
||||
$response = $controller->accept('unknown-uuid');
|
||||
$payload = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
self::assertSame(['message' => 'Not found'], $payload);
|
||||
}
|
||||
|
||||
private function serializer(): Serializer
|
||||
{
|
||||
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
|
||||
|
||||
return new Serializer(
|
||||
[
|
||||
new DateTimeNormalizer(),
|
||||
new ObjectNormalizer($classMetadataFactory, propertyTypeExtractor: new ReflectionExtractor()),
|
||||
],
|
||||
[new JsonEncoder()],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Api;
|
||||
|
||||
use App\BpnConnect\ContingentsClient;
|
||||
use App\Controller\Api\ContingentController;
|
||||
use App\Entity\Groups\AccommodationPrice;
|
||||
use App\Repository\Groups\AccommodationPriceRepository;
|
||||
use App\Repository\Groups\AccommodationRepository;
|
||||
use App\Service\PriceTimelineBuilder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
class ContingentControllerTest extends TestCase
|
||||
{
|
||||
public function testEnrichEntryKeepsMinPaxAsIncludedPaxCompatibilityAlias(): void
|
||||
{
|
||||
$controller = new ContingentController(
|
||||
$this->createMock(ContingentsClient::class),
|
||||
$this->createMock(AccommodationRepository::class),
|
||||
$this->createMock(AccommodationPriceRepository::class),
|
||||
$this->createMock(CacheInterface::class),
|
||||
new PriceTimelineBuilder(),
|
||||
);
|
||||
|
||||
$price = new AccommodationPrice();
|
||||
$price->setDateFrom(new \DateTimeImmutable('2026-07-01'));
|
||||
$price->setDateTo(new \DateTimeImmutable('2026-07-31'));
|
||||
$price->setIncludedPax(4);
|
||||
$price->setPricePerNight(12345);
|
||||
$price->setPriceAdditionalPerson(1500);
|
||||
$price->setMinNights(3);
|
||||
|
||||
$method = new \ReflectionMethod($controller, 'enrichEntry');
|
||||
|
||||
$result = $method->invoke($controller, '2026-07-06', 'available', [$price], 'EUR');
|
||||
|
||||
self::assertSame(4, $result['includedPax']);
|
||||
self::assertSame(4, $result['minPax']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Groups;
|
||||
|
||||
use App\Controller\Groups\OfferController;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use App\Service\AccommodationBookingBreakdownCalculator;
|
||||
use App\Service\AccommodationBookingLinkSigner;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Twig\Environment;
|
||||
|
||||
class OfferControllerTest extends TestCase
|
||||
{
|
||||
public function testGetRendersOfferWithAcceptFormForInquiry(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setIsInquiry(true);
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository->method('findOneBy')->with(['uuid' => $booking->getUuid()])->willReturn($booking);
|
||||
|
||||
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
||||
$linkSigner->method('isValidLinkRequest')->willReturn(true);
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->method('compute')->with($booking)->willReturn(['total' => 1000]);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('acceptBooking');
|
||||
|
||||
$twig = $this->createMock(Environment::class);
|
||||
$twig
|
||||
->expects(self::once())
|
||||
->method('render')
|
||||
->with('groups/booking/offer.html.twig', ['booking' => $booking, 'priceBreakdown' => ['total' => 1000]])
|
||||
->willReturn('<html>offer</html>');
|
||||
|
||||
$controller = new OfferController($bookingRepository, $linkSigner, $breakdownCalculator, $bookingService, $twig);
|
||||
|
||||
$response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid()));
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
self::assertSame('<html>offer</html>', $response->getContent());
|
||||
}
|
||||
|
||||
public function testPostAcceptsInquiryAndRedirectsToSameUrl(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setIsInquiry(true);
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository->method('findOneBy')->willReturn($booking);
|
||||
|
||||
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
||||
$linkSigner->method('isValidLinkRequest')->willReturn(true);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::once())->method('acceptBooking')->with($booking);
|
||||
|
||||
$controller = new OfferController(
|
||||
$bookingRepository,
|
||||
$linkSigner,
|
||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||
$bookingService,
|
||||
$this->createMock(Environment::class),
|
||||
);
|
||||
|
||||
$request = Request::create('/groups/booking/offer/'.$booking->getUuid().'?t=123&_hash=abc', 'POST');
|
||||
$response = $controller->index($booking->getUuid(), $request);
|
||||
|
||||
self::assertSame(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
self::assertSame($request->getUri(), $response->headers->get('Location'));
|
||||
}
|
||||
|
||||
public function testGetRendersConfirmationWithoutAcceptFormForBooking(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setIsInquiry(false);
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository->method('findOneBy')->willReturn($booking);
|
||||
|
||||
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
||||
$linkSigner->method('isValidLinkRequest')->willReturn(true);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('acceptBooking');
|
||||
|
||||
$twig = $this->createMock(Environment::class);
|
||||
$twig->method('render')->with('groups/booking/offer.html.twig', self::anything())->willReturn('<html>confirmed</html>');
|
||||
|
||||
$controller = new OfferController(
|
||||
$bookingRepository,
|
||||
$linkSigner,
|
||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||
$bookingService,
|
||||
$twig,
|
||||
);
|
||||
|
||||
// A POST on an already-accepted booking should not trigger acceptBooking again — falls through to render.
|
||||
$response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid(), 'POST'));
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testInvalidLinkReturnsUnavailableResponse(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository->method('findOneBy')->willReturn($booking);
|
||||
|
||||
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
||||
$linkSigner->method('isValidLinkRequest')->willReturn(false);
|
||||
|
||||
$twig = $this->createMock(Environment::class);
|
||||
$twig->method('render')->with('groups/booking/offer_unavailable.html.twig')->willReturn('<html>unavailable</html>');
|
||||
|
||||
$controller = new OfferController(
|
||||
$bookingRepository,
|
||||
$linkSigner,
|
||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||
$this->createMock(AccommodationBookingService::class),
|
||||
$twig,
|
||||
);
|
||||
|
||||
$response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid()));
|
||||
|
||||
self::assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testUnknownUuidReturnsUnavailableResponse(): void
|
||||
{
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository->method('findOneBy')->willReturn(null);
|
||||
|
||||
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
||||
$linkSigner->expects(self::never())->method('isValidLinkRequest');
|
||||
|
||||
$twig = $this->createMock(Environment::class);
|
||||
$twig->method('render')->willReturn('<html>unavailable</html>');
|
||||
|
||||
$controller = new OfferController(
|
||||
$bookingRepository,
|
||||
$linkSigner,
|
||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||
$this->createMock(AccommodationBookingService::class),
|
||||
$twig,
|
||||
);
|
||||
|
||||
$response = $controller->index('unknown-uuid', Request::create('/groups/booking/offer/unknown-uuid'));
|
||||
|
||||
self::assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form;
|
||||
|
||||
use App\Form\AccommodationStep2Type;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Form\Forms;
|
||||
|
||||
class AccommodationStep2TypeTest extends TestCase
|
||||
{
|
||||
public function testChildrenLabelIsBuiltFromMaxAdolescentAgeOption(): void
|
||||
{
|
||||
$form = Forms::createFormFactoryBuilder()
|
||||
->getFormFactory()
|
||||
->create(AccommodationStep2Type::class, new AccommodationBookingDto(), [
|
||||
'max_adolescent_age' => 15,
|
||||
]);
|
||||
|
||||
self::assertSame(
|
||||
'davon Kinder (4–15 Jahre)',
|
||||
$form->get('childrenCount')->getConfig()->getOption('label'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testBlankOptionalChildCountersAreNormalizedToZero(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$form = Forms::createFormFactoryBuilder()
|
||||
->getFormFactory()
|
||||
->create(AccommodationStep2Type::class, $dto);
|
||||
|
||||
$form->submit([
|
||||
'paxCount' => '2',
|
||||
'minorsCount' => '',
|
||||
'childrenCount' => '',
|
||||
'selectedBoardServiceId' => '',
|
||||
'selectedAdditionalServiceIds' => [],
|
||||
]);
|
||||
|
||||
self::assertTrue($form->isSynchronized());
|
||||
self::assertSame(0, $dto->minorsCount);
|
||||
self::assertSame(0, $dto->childrenCount);
|
||||
}
|
||||
|
||||
public function testGroupedAdditionalServiceValuesCanSubmitUnderSelectionGroupKeys(): void
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$form = Forms::createFormFactoryBuilder()
|
||||
->getFormFactory()
|
||||
->create(AccommodationStep2Type::class, $dto, [
|
||||
'additional_service_choices' => [
|
||||
'Ski service' => 101,
|
||||
'Board service' => 202,
|
||||
],
|
||||
]);
|
||||
|
||||
$form->submit([
|
||||
'paxCount' => '2',
|
||||
'minorsCount' => '0',
|
||||
'childrenCount' => '0',
|
||||
'selectedBoardServiceId' => '',
|
||||
'selectedAdditionalServiceIds' => [
|
||||
'Ski extras' => '101',
|
||||
'Board extras' => '202',
|
||||
],
|
||||
]);
|
||||
|
||||
self::assertTrue($form->isSynchronized());
|
||||
self::assertSame([101, 202], array_values($dto->selectedAdditionalServiceIds));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Service\AccommodationBookingLinkSigner;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
class AccommodationBookingLinkSignerTest extends TestCase
|
||||
{
|
||||
public function testSignThenIsValidLinkRequestSucceeds(): void
|
||||
{
|
||||
$booking = $this->bookingWithAccessLink();
|
||||
$signer = $this->createSigner();
|
||||
|
||||
$signedUrl = $signer->sign($booking);
|
||||
$request = Request::create($signedUrl);
|
||||
|
||||
self::assertTrue($signer->isValidLinkRequest($request, $booking));
|
||||
}
|
||||
|
||||
public function testTamperedQueryParamFails(): void
|
||||
{
|
||||
$booking = $this->bookingWithAccessLink();
|
||||
$signer = $this->createSigner();
|
||||
|
||||
$signedUrl = $signer->sign($booking);
|
||||
self::assertTrue($signer->isValidLinkRequest(Request::create($signedUrl), $booking));
|
||||
|
||||
// Flip the `t` value while keeping the original _hash — signature no longer matches.
|
||||
$tamperedUrl = preg_replace('/(?<=[?&]t=)\d+/', '999999999', $signedUrl);
|
||||
self::assertNotNull($tamperedUrl);
|
||||
|
||||
self::assertFalse($signer->isValidLinkRequest(Request::create($tamperedUrl), $booking));
|
||||
}
|
||||
|
||||
public function testRegeneratedLinkInvalidatesThePreviousOne(): void
|
||||
{
|
||||
$booking = $this->bookingWithAccessLink();
|
||||
$signer = $this->createSigner();
|
||||
|
||||
$signedUrl = $signer->sign($booking);
|
||||
$request = Request::create($signedUrl);
|
||||
|
||||
// Regenerating overwrites accessLinkIssuedAt — the old signed `t` no longer matches.
|
||||
$booking->setAccessLinkIssuedAt(new \DateTimeImmutable('+1 minute'));
|
||||
|
||||
self::assertFalse($signer->isValidLinkRequest($request, $booking));
|
||||
}
|
||||
|
||||
public function testExpiredLinkFails(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setAccessLinkIssuedAt(new \DateTimeImmutable('-91 days'));
|
||||
$signer = $this->createSigner();
|
||||
|
||||
$signedUrl = $signer->sign($booking);
|
||||
$request = Request::create($signedUrl);
|
||||
|
||||
self::assertFalse($signer->isValidLinkRequest($request, $booking));
|
||||
}
|
||||
|
||||
public function testMissingAccessLinkIssuedAtFails(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$signer = $this->createSigner();
|
||||
|
||||
$request = Request::create('https://example.com/groups/booking/offer/'.$booking->getUuid().'?t=123');
|
||||
|
||||
self::assertFalse($signer->isValidLinkRequest($request, $booking));
|
||||
}
|
||||
|
||||
public function testSignThrowsWithoutAccessLinkIssuedAt(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$signer = $this->createSigner();
|
||||
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$signer->sign($booking);
|
||||
}
|
||||
|
||||
public function testExpiresAtIsNinetyDaysAfterIssuedAt(): void
|
||||
{
|
||||
$issuedAt = new \DateTimeImmutable('2026-01-01T00:00:00+00:00');
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setAccessLinkIssuedAt($issuedAt);
|
||||
$signer = $this->createSigner();
|
||||
|
||||
self::assertSame('2026-04-01T00:00:00+00:00', $signer->expiresAt($booking)?->format(\DATE_ATOM));
|
||||
}
|
||||
|
||||
private function bookingWithAccessLink(): AccommodationBooking
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setPaxCount(10);
|
||||
$booking->setAccessLinkIssuedAt(new \DateTimeImmutable());
|
||||
|
||||
return $booking;
|
||||
}
|
||||
|
||||
private function createSigner(): AccommodationBookingLinkSigner
|
||||
{
|
||||
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
|
||||
$urlGenerator
|
||||
->method('generate')
|
||||
->willReturnCallback(static fn (string $name, array $parameters) => sprintf(
|
||||
'https://example.com/groups/booking/offer/%s?t=%s',
|
||||
$parameters['uuid'],
|
||||
$parameters['t'],
|
||||
));
|
||||
|
||||
return new AccommodationBookingLinkSigner($urlGenerator, 'test-secret');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\Email\Mailer;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\Groups\AccommodationPrice;
|
||||
use App\Model\AccommodationBookingQueryParams;
|
||||
use App\Repository\Groups\AccommodationPriceRepository;
|
||||
use App\Repository\Groups\AccommodationRepository;
|
||||
use App\Repository\Groups\AdditionalServiceRepository;
|
||||
use App\Repository\Groups\BoardServiceRepository;
|
||||
use App\Service\AccommodationBookingBreakdownCalculator;
|
||||
use App\Service\AccommodationBookingLinkSigner;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\CmsDataProvider;
|
||||
use App\Service\PriceTimelineBuilder;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class AccommodationBookingServiceTest extends TestCase
|
||||
{
|
||||
public function testInitFromParamsAcceptsStrictCalendarDates(): void
|
||||
{
|
||||
$service = $this->createServiceWithAccommodation();
|
||||
|
||||
$dto = $service->initFromParams(new AccommodationBookingQueryParams('HOTEL', '2026-02-28', '2026-03-01'));
|
||||
|
||||
self::assertSame('2026-02-28', $dto->dateFrom?->format('Y-m-d'));
|
||||
self::assertSame('2026-03-01', $dto->dateTo?->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testInitFromParamsPrefillsPaxCountFromEffectiveMinPax(): void
|
||||
{
|
||||
$price = (new AccommodationPrice())
|
||||
->setDateFrom(new \DateTimeImmutable('2026-02-01'))
|
||||
->setDateTo(new \DateTimeImmutable('2026-03-31'))
|
||||
->setIncludedPax(4);
|
||||
$service = $this->createServiceWithAccommodation([$price]);
|
||||
|
||||
$dto = $service->initFromParams(new AccommodationBookingQueryParams('HOTEL', '2026-02-28', '2026-03-01'));
|
||||
|
||||
self::assertSame(4, $dto->paxCount);
|
||||
}
|
||||
|
||||
public function testInitFromParamsRejectsNormalizedInvalidCalendarDates(): void
|
||||
{
|
||||
$service = $this->createServiceWithAccommodation();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Ungültiges Datumsformat. Erwartet: YYYY-MM-DD.');
|
||||
|
||||
$service->initFromParams(new AccommodationBookingQueryParams('HOTEL', '2026-02-31', '2026-03-05'));
|
||||
}
|
||||
|
||||
public function testIssueAccessLinkForDirectBookingSetsTimestampForDirectBooking(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::once())->method('flush');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setIsInquiry(false);
|
||||
|
||||
$service->issueAccessLinkForDirectBooking($booking);
|
||||
|
||||
self::assertNotNull($booking->getAccessLinkIssuedAt());
|
||||
}
|
||||
|
||||
public function testIssueAccessLinkForDirectBookingNoOpsForInquiry(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::never())->method('flush');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setIsInquiry(true);
|
||||
|
||||
$service->issueAccessLinkForDirectBooking($booking);
|
||||
|
||||
self::assertNull($booking->getAccessLinkIssuedAt());
|
||||
}
|
||||
|
||||
public function testIssueAccessLinkForDirectBookingNoOpsWhenAlreadySet(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::never())->method('flush');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setIsInquiry(false);
|
||||
$issuedAt = new \DateTimeImmutable('2026-01-01');
|
||||
$booking->setAccessLinkIssuedAt($issuedAt);
|
||||
|
||||
$service->issueAccessLinkForDirectBooking($booking);
|
||||
|
||||
self::assertSame($issuedAt, $booking->getAccessLinkIssuedAt());
|
||||
}
|
||||
|
||||
public function testSendCustomerConfirmationEmailAlwaysSendsWithLinkWhenIssued(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setIsInquiry(false);
|
||||
$booking->setAccessLinkIssuedAt(new \DateTimeImmutable());
|
||||
|
||||
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
||||
$linkSigner->method('sign')->with($booking)->willReturn('https://example.com/offer/signed-link');
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->method('compute')->willReturn(['total' => 1000, 'currency' => 'EUR']);
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer
|
||||
->expects(self::once())
|
||||
->method('createAndSendEmail')
|
||||
->with(
|
||||
self::callback(static fn (array $context) => 'https://example.com/offer/signed-link' === $context['accessLink']),
|
||||
self::callback(static fn (array $options) => '[email protected]' === $options['to']
|
||||
&& 'email/accommodation_booking_customer.html.twig' === $options['template']),
|
||||
);
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $mailer, linkSigner: $linkSigner, breakdownCalculator: $breakdownCalculator);
|
||||
|
||||
$service->sendCustomerConfirmationEmail($booking);
|
||||
}
|
||||
|
||||
public function testSendCustomerConfirmationEmailSendsWithoutLinkForInquiry(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setIsInquiry(true);
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->method('compute')->willReturn(null);
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer
|
||||
->expects(self::once())
|
||||
->method('createAndSendEmail')
|
||||
->with(
|
||||
self::callback(static fn (array $context) => null === $context['accessLink']),
|
||||
self::anything(),
|
||||
);
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $mailer, breakdownCalculator: $breakdownCalculator);
|
||||
|
||||
$service->sendCustomerConfirmationEmail($booking);
|
||||
}
|
||||
|
||||
public function testSendCustomerConfirmationEmailLogsAndSwallowsMailerFailures(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setIsInquiry(true);
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->method('compute')->willReturn(null);
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer->method('createAndSendEmail')->willThrowException(new \RuntimeException('SMTP down'));
|
||||
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$logger->expects(self::once())->method('error');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $mailer, breakdownCalculator: $breakdownCalculator, logger: $logger);
|
||||
|
||||
$service->sendCustomerConfirmationEmail($booking);
|
||||
}
|
||||
|
||||
public function testRegenerateAccessLinkAndNotifyCustomerAlwaysOverwritesAndSends(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setIsInquiry(true);
|
||||
$previousIssuedAt = new \DateTimeImmutable('2026-01-01');
|
||||
$booking->setAccessLinkIssuedAt($previousIssuedAt);
|
||||
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::once())->method('flush');
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->method('compute')->willReturn(null);
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer->expects(self::once())->method('createAndSendEmail');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(
|
||||
entityManager: $entityManager,
|
||||
mailer: $mailer,
|
||||
breakdownCalculator: $breakdownCalculator,
|
||||
);
|
||||
|
||||
$service->regenerateAccessLinkAndNotifyCustomer($booking);
|
||||
|
||||
self::assertNotSame($previousIssuedAt, $booking->getAccessLinkIssuedAt());
|
||||
}
|
||||
|
||||
public function testAcceptBookingTransitionsInquiryToBooking(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::once())->method('flush');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setIsInquiry(true);
|
||||
|
||||
$service->acceptBooking($booking);
|
||||
|
||||
self::assertFalse($booking->isInquiry());
|
||||
self::assertNotNull($booking->getAcceptedAt());
|
||||
}
|
||||
|
||||
public function testAcceptBookingIsIdempotent(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::never())->method('flush');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setIsInquiry(false);
|
||||
|
||||
$service->acceptBooking($booking);
|
||||
|
||||
self::assertNull($booking->getAcceptedAt());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccommodationPrice[] $prices
|
||||
*/
|
||||
private function createServiceWithAccommodation(
|
||||
array $prices = [],
|
||||
?EntityManagerInterface $entityManager = null,
|
||||
?Mailer $mailer = null,
|
||||
?LoggerInterface $logger = null,
|
||||
?AccommodationBookingLinkSigner $linkSigner = null,
|
||||
?AccommodationBookingBreakdownCalculator $breakdownCalculator = null,
|
||||
): AccommodationBookingService {
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$accommodationRepo = $this->createMock(AccommodationRepository::class);
|
||||
$accommodationRepo
|
||||
->method('findOneBy')
|
||||
->with(['calendarCode' => 'HOTEL'])
|
||||
->willReturn($accommodation);
|
||||
|
||||
$priceRepo = $this->createMock(AccommodationPriceRepository::class);
|
||||
$priceRepo
|
||||
->method('findByHotelCodeAndDateRange')
|
||||
->willReturn($prices);
|
||||
|
||||
return new AccommodationBookingService(
|
||||
$accommodationRepo,
|
||||
$priceRepo,
|
||||
$this->createMock(AdditionalServiceRepository::class),
|
||||
$this->createMock(BoardServiceRepository::class),
|
||||
new PriceTimelineBuilder(),
|
||||
$entityManager ?? $this->createMock(EntityManagerInterface::class),
|
||||
$mailer ?? $this->createMock(Mailer::class),
|
||||
$logger ?? $this->createMock(LoggerInterface::class),
|
||||
$this->createMock(CmsDataProvider::class),
|
||||
$linkSigner ?? $this->createMock(AccommodationBookingLinkSigner::class),
|
||||
$breakdownCalculator ?? $this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||
'[email protected]',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user