From 18a890e50e850750fa9ecd8d6e7cd880bc69919a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 10 Jul 2026 13:07:48 +0200 Subject: [PATCH] chore: adjust tests to recent changes --- .../Accommodation/Step2ControllerTest.php | 3 +- .../Api/ContingentControllerTest.php | 6 +- .../Controller/Groups/OfferControllerTest.php | 63 +++++++++++-------- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/tests/Controller/Accommodation/Step2ControllerTest.php b/tests/Controller/Accommodation/Step2ControllerTest.php index 27a010b9..c82f2d03 100644 --- a/tests/Controller/Accommodation/Step2ControllerTest.php +++ b/tests/Controller/Accommodation/Step2ControllerTest.php @@ -7,6 +7,7 @@ namespace App\Tests\Controller\Accommodation; use App\Controller\Groups\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; @@ -79,7 +80,7 @@ class Step2ControllerTest extends TestCase ->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)']]); + ->willReturn(new InquiryStatus(true, ['Mindestaufenthalt: 5 Nächte (gebucht: 4)'])); $controller = new TestableAccommodationStep2Controller( $bookingService, diff --git a/tests/Controller/Api/ContingentControllerTest.php b/tests/Controller/Api/ContingentControllerTest.php index 17c6a471..42ebe1b9 100644 --- a/tests/Controller/Api/ContingentControllerTest.php +++ b/tests/Controller/Api/ContingentControllerTest.php @@ -15,7 +15,7 @@ use Symfony\Contracts\Cache\CacheInterface; class ContingentControllerTest extends TestCase { - public function testEnrichEntryKeepsMinPaxAsIncludedPaxCompatibilityAlias(): void + public function testEnrichEntryIncludesPricingMetadata(): void { $controller = new ContingentController( $this->createMock(ContingentsClient::class), @@ -38,6 +38,8 @@ class ContingentControllerTest extends TestCase $result = $method->invoke($controller, '2026-07-06', 'available', [$price], 'EUR'); self::assertSame(4, $result['includedPax']); - self::assertSame(4, $result['minPax']); + self::assertSame(3, $result['minNights']); + self::assertSame(123.45, $result['pricePerNight']); + self::assertSame('EUR', $result['currency']); } } diff --git a/tests/Controller/Groups/OfferControllerTest.php b/tests/Controller/Groups/OfferControllerTest.php index dd00b8a5..69b6e79a 100644 --- a/tests/Controller/Groups/OfferControllerTest.php +++ b/tests/Controller/Groups/OfferControllerTest.php @@ -13,7 +13,6 @@ 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 { @@ -34,19 +33,14 @@ class OfferControllerTest extends TestCase $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('offer'); - - $controller = new OfferController($bookingRepository, $linkSigner, $breakdownCalculator, $bookingService, $twig); + $controller = new TestableOfferController($bookingRepository, $linkSigner, $breakdownCalculator, $bookingService); $response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid())); self::assertSame(Response::HTTP_OK, $response->getStatusCode()); self::assertSame('offer', $response->getContent()); + self::assertSame('groups/booking/offer.html.twig', $controller->renderedView); + self::assertSame(['booking' => $booking, 'priceBreakdown' => ['total' => 1000]], $controller->renderedParameters); } public function testPostAcceptsInquiryAndRedirectsToSameUrl(): void @@ -68,7 +62,6 @@ class OfferControllerTest extends TestCase $linkSigner, $this->createMock(AccommodationBookingBreakdownCalculator::class), $bookingService, - $this->createMock(Environment::class), ); $request = Request::create('/groups/booking/offer/'.$booking->getUuid().'?t=123&_hash=abc', 'POST'); @@ -92,21 +85,18 @@ class OfferControllerTest extends TestCase $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('confirmed'); - - $controller = new OfferController( + $controller = new TestableOfferController( $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()); + self::assertSame('groups/booking/offer.html.twig', $controller->renderedView); } public function testInvalidLinkReturnsUnavailableResponse(): void @@ -119,20 +109,17 @@ class OfferControllerTest extends TestCase $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('unavailable'); - - $controller = new OfferController( + $controller = new TestableOfferController( $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()); + self::assertSame(Response::HTTP_OK, $response->getStatusCode()); + self::assertSame('groups/booking/offer_unavailable.html.twig', $controller->renderedView); } public function testUnknownUuidReturnsUnavailableResponse(): void @@ -143,19 +130,41 @@ class OfferControllerTest extends TestCase $linkSigner = $this->createMock(AccommodationBookingLinkSigner::class); $linkSigner->expects(self::never())->method('isValidLinkRequest'); - $twig = $this->createMock(Environment::class); - $twig->method('render')->willReturn('unavailable'); - - $controller = new OfferController( + $controller = new TestableOfferController( $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()); + self::assertSame(Response::HTTP_OK, $response->getStatusCode()); + self::assertSame('groups/booking/offer_unavailable.html.twig', $controller->renderedView); + } +} + +final class TestableOfferController extends OfferController +{ + public ?string $renderedView = null; + + /** @var array */ + public array $renderedParameters = []; + + protected function render(string $view, array $parameters = [], ?Response $response = null): Response + { + $this->renderedView = $view; + $this->renderedParameters = $parameters; + + if ('groups/booking/offer.html.twig' === $view) { + $content = $parameters['booking']->isInquiry() ? 'offer' : 'confirmed'; + } else { + $content = 'unavailable'; + } + + $response ??= new Response(); + $response->setContent($content); + + return $response; } }