chore: adjust tests to recent changes
This commit is contained in:
1 parent
3c9caeaad0
commit
18a890e50e
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\Controller\Groups\Step2Controller;
|
||||||
use App\Entity\Groups\Accommodation;
|
use App\Entity\Groups\Accommodation;
|
||||||
use App\Form\Model\AccommodationBookingDto;
|
use App\Form\Model\AccommodationBookingDto;
|
||||||
|
use App\Model\InquiryStatus;
|
||||||
use App\Service\AccommodationBookingService;
|
use App\Service\AccommodationBookingService;
|
||||||
use App\Service\AccommodationSessionManager;
|
use App\Service\AccommodationSessionManager;
|
||||||
use App\Service\GroupsPriceCalculator;
|
use App\Service\GroupsPriceCalculator;
|
||||||
@@ -79,7 +80,7 @@ class Step2ControllerTest extends TestCase
|
|||||||
->expects(self::once())
|
->expects(self::once())
|
||||||
->method('computeInquiryStatus')
|
->method('computeInquiryStatus')
|
||||||
->with(self::callback(static fn(AccommodationBookingDto $submittedDto): bool => 3 === $submittedDto->paxCount), [])
|
->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(
|
$controller = new TestableAccommodationStep2Controller(
|
||||||
$bookingService,
|
$bookingService,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use Symfony\Contracts\Cache\CacheInterface;
|
|||||||
|
|
||||||
class ContingentControllerTest extends TestCase
|
class ContingentControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testEnrichEntryKeepsMinPaxAsIncludedPaxCompatibilityAlias(): void
|
public function testEnrichEntryIncludesPricingMetadata(): void
|
||||||
{
|
{
|
||||||
$controller = new ContingentController(
|
$controller = new ContingentController(
|
||||||
$this->createMock(ContingentsClient::class),
|
$this->createMock(ContingentsClient::class),
|
||||||
@@ -38,6 +38,8 @@ class ContingentControllerTest extends TestCase
|
|||||||
$result = $method->invoke($controller, '2026-07-06', 'available', [$price], 'EUR');
|
$result = $method->invoke($controller, '2026-07-06', 'available', [$price], 'EUR');
|
||||||
|
|
||||||
self::assertSame(4, $result['includedPax']);
|
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 PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Twig\Environment;
|
|
||||||
|
|
||||||
class OfferControllerTest extends TestCase
|
class OfferControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -34,19 +33,14 @@ class OfferControllerTest extends TestCase
|
|||||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||||
$bookingService->expects(self::never())->method('acceptBooking');
|
$bookingService->expects(self::never())->method('acceptBooking');
|
||||||
|
|
||||||
$twig = $this->createMock(Environment::class);
|
$controller = new TestableOfferController($bookingRepository, $linkSigner, $breakdownCalculator, $bookingService);
|
||||||
$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()));
|
$response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid()));
|
||||||
|
|
||||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||||
self::assertSame('<html>offer</html>', $response->getContent());
|
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
|
public function testPostAcceptsInquiryAndRedirectsToSameUrl(): void
|
||||||
@@ -68,7 +62,6 @@ class OfferControllerTest extends TestCase
|
|||||||
$linkSigner,
|
$linkSigner,
|
||||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||||
$bookingService,
|
$bookingService,
|
||||||
$this->createMock(Environment::class),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = Request::create('/groups/booking/offer/'.$booking->getUuid().'?t=123&_hash=abc', 'POST');
|
$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 = $this->createMock(AccommodationBookingService::class);
|
||||||
$bookingService->expects(self::never())->method('acceptBooking');
|
$bookingService->expects(self::never())->method('acceptBooking');
|
||||||
|
|
||||||
$twig = $this->createMock(Environment::class);
|
$controller = new TestableOfferController(
|
||||||
$twig->method('render')->with('groups/booking/offer.html.twig', self::anything())->willReturn('<html>confirmed</html>');
|
|
||||||
|
|
||||||
$controller = new OfferController(
|
|
||||||
$bookingRepository,
|
$bookingRepository,
|
||||||
$linkSigner,
|
$linkSigner,
|
||||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||||
$bookingService,
|
$bookingService,
|
||||||
$twig,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// A POST on an already-accepted booking should not trigger acceptBooking again — falls through to render.
|
// 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'));
|
$response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid(), 'POST'));
|
||||||
|
|
||||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||||
|
self::assertSame('groups/booking/offer.html.twig', $controller->renderedView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidLinkReturnsUnavailableResponse(): void
|
public function testInvalidLinkReturnsUnavailableResponse(): void
|
||||||
@@ -119,20 +109,17 @@ class OfferControllerTest extends TestCase
|
|||||||
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
||||||
$linkSigner->method('isValidLinkRequest')->willReturn(false);
|
$linkSigner->method('isValidLinkRequest')->willReturn(false);
|
||||||
|
|
||||||
$twig = $this->createMock(Environment::class);
|
$controller = new TestableOfferController(
|
||||||
$twig->method('render')->with('groups/booking/offer_unavailable.html.twig')->willReturn('<html>unavailable</html>');
|
|
||||||
|
|
||||||
$controller = new OfferController(
|
|
||||||
$bookingRepository,
|
$bookingRepository,
|
||||||
$linkSigner,
|
$linkSigner,
|
||||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||||
$this->createMock(AccommodationBookingService::class),
|
$this->createMock(AccommodationBookingService::class),
|
||||||
$twig,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid()));
|
$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
|
public function testUnknownUuidReturnsUnavailableResponse(): void
|
||||||
@@ -143,19 +130,41 @@ class OfferControllerTest extends TestCase
|
|||||||
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
||||||
$linkSigner->expects(self::never())->method('isValidLinkRequest');
|
$linkSigner->expects(self::never())->method('isValidLinkRequest');
|
||||||
|
|
||||||
$twig = $this->createMock(Environment::class);
|
$controller = new TestableOfferController(
|
||||||
$twig->method('render')->willReturn('<html>unavailable</html>');
|
|
||||||
|
|
||||||
$controller = new OfferController(
|
|
||||||
$bookingRepository,
|
$bookingRepository,
|
||||||
$linkSigner,
|
$linkSigner,
|
||||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||||
$this->createMock(AccommodationBookingService::class),
|
$this->createMock(AccommodationBookingService::class),
|
||||||
$twig,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = $controller->index('unknown-uuid', Request::create('/groups/booking/offer/unknown-uuid'));
|
$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