buildController($user); $controller->index(Request::create('/admin/accommodation-booking/create')); self::assertSame($user, $controller->capturedBooking?->getManagedBy()); } private function buildController(?UserInterface $user): TestableCreateController { $form = $this->createStub(FormInterface::class); $form->method('handleRequest')->willReturn($form); $form->method('isSubmitted')->willReturn(false); return new TestableCreateController( $this->createStub(EntityManagerInterface::class), $this->createStub(LoggerInterface::class), $this->createStub(AccommodationBookingService::class), $form, $user, ); } } final class TestableCreateController extends CreateController { public ?AccommodationBooking $capturedBooking = null; public function __construct( EntityManagerInterface $entityManager, LoggerInterface $logger, AccommodationBookingService $bookingService, private readonly FormInterface $form, private readonly ?UserInterface $user, ) { parent::__construct($entityManager, $logger, $bookingService); } protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface { if ($data instanceof AccommodationBooking) { $this->capturedBooking = $data; } return $this->form; } protected function getUser(): ?UserInterface { return $this->user; } /** * @param array $parameters */ protected function render(string $view, array $parameters = [], ?Response $response = null): Response { return new Response(); } }