chore: adjust tests to recent changes
This commit is contained in:
1 parent
1a653726b4
commit
225ed518e3
3 files changed
+42
-30
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user