chore: adjust tests to recent changes

This commit is contained in:
Björn Fromme committed 2026-07-14 11:29:43 +02:00
1 parent 505bda46cf
commit 597b169b17
3 files changed
+42 -30

No files matched your search

+36 -27
View File
@@ -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('<html>offer</html>');
$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('<html>offer</html>', $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('<html>confirmed</html>');
$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('<html>unavailable</html>');
$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('<html>unavailable</html>');
$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<string, mixed> */
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() ? '<html>offer</html>' : '<html>confirmed</html>';
} else {
$content = '<html>unavailable</html>';
}
$response ??= new Response();
$response->setContent($content);
return $response;
}
}