setDateFrom(new \DateTimeImmutable('2026-07-01')) ->setDateTo(new \DateTimeImmutable('2026-07-08')); $period = $booking->splitOffPeriod(AccommodationBookingPeriodPosition::Trailing, 1); $bookingService = $this->createMock(AccommodationBookingService::class); $bookingService->expects(self::once())->method('updatePeriod') ->with($booking, $period) ->willReturn(new ConstraintViolationList()); $form = $this->createStub(FormInterface::class); $form->method('handleRequest')->willReturn($form); $form->method('isSubmitted')->willReturn(true); $form->method('isValid')->willReturn(true); $controller = new TestableEditPeriodController($bookingService, $this->createStub(LoggerInterface::class), $form); $response = $controller->index($period, Request::create('/admin/accommodation-booking-period/1/edit', 'POST', server: ['HTTP_HX-Request' => 'true'])); self::assertStringStartsWith('/app_admin_accommodationbooking_edit', (string) $response->headers->get('HX-Redirect')); self::assertSame('success', $controller->flashes[0]['type']); } public function testAPeriodWithoutABookingIsNotFound(): void { $controller = new TestableEditPeriodController( $this->createStub(AccommodationBookingService::class), $this->createStub(LoggerInterface::class), $this->createStub(FormInterface::class), ); $this->expectException(NotFoundHttpException::class); $controller->index( new AccommodationBookingPeriod(AccommodationBookingPeriodPosition::Leading, new \DateTimeImmutable('2026-07-01'), new \DateTimeImmutable('2026-07-02')), Request::create('/admin/accommodation-booking-period/1/edit'), ); } } final class TestableEditPeriodController extends EditPeriodController { /** @var list */ public array $flashes = []; public function __construct( AccommodationBookingService $bookingService, LoggerInterface $logger, private readonly FormInterface $form, ) { parent::__construct($bookingService, $logger); } protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface { return $this->form; } /** * @param array $parameters */ protected function render(string $view, array $parameters = [], ?Response $response = null): Response { return new Response(); } protected function addFlash(string $type, mixed $message): void { $this->flashes[] = ['type' => $type, 'message' => $message]; } /** * @param array $parameters */ protected function generateUrl(string $route, array $parameters = [], int $referenceType = 1): string { return '/'.$route.'?'.http_build_query($parameters); } }