createBookingDto(); $bookingSessionService = $this->createMock(BookingSessionManager::class); $bookingSessionService->method('getBookingDto')->willReturn($bookingDto); $bookingSessionService->expects($this->never())->method('saveBookingDto'); $controller = $this->createController($bookingSessionService); $response = $controller->toggleApplicantTravels($request); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertSame('/app_booking_create_step_2', $response->getTargetUrl()); $this->assertSame(0, $controller->createdForms, 'The submitted choice is never bound'); $this->assertTrue($bookingDto->applicantTravels); } public function testApplicantFormIsNotServedWhereTheTravelDateDoesNotOfferTheChoice(): void { $request = Request::create('/bookings/create/applicant', 'GET'); $bookingDto = $this->createBookingDto(); $bookingDto->applicantTravels = false; $bookingDto->applicant = new ParticipantDto(); $bookingSessionService = $this->createMock(BookingSessionManager::class); $bookingSessionService->method('getBookingDto')->willReturn($bookingDto); $bookingSessionService->expects($this->never())->method('saveBookingDto'); $controller = $this->createController($bookingSessionService); $response = $controller->editApplicant($request); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertSame('/app_booking_create_step_2', $response->getTargetUrl()); $this->assertSame(0, $controller->createdForms); } private function createBookingDto(): BookingDto { $travel = new Travel(); $travel->id = 4711; $participant = new ParticipantDto(); $participant->index = 0; $bookingDto = new BookingDto($travel, 1); $bookingDto->participants = [$participant]; return $bookingDto; } private function createController(BookingSessionManager $bookingSessionService): TestableStep2ParticipantController { return new TestableStep2ParticipantController( $this->createStub(BookingConfigurator::class), $bookingSessionService, $this->createStub(BookingCreateContextFactory::class), $this->createStub(TravelDataProvider::class), $this->createStub(ParticipantDataPrefiller::class), $this->createStub(ParticipantFormSupport::class), $this->createStub(ApplicantInsuranceCascade::class), ); } } final class TestableStep2ParticipantController extends Step2ParticipantController { public int $createdForms = 0; /** * @return FormInterface */ protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface { ++$this->createdForms; throw new \LogicException('No form is expected to be built.'); } /** * @param array $parameters */ protected function generateUrl(string $route, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string { return '/'.$route; } protected function redirect(string $url, int $status = 302): RedirectResponse { return new RedirectResponse($url, $status); } /** * @param array $parameters */ protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse { return new RedirectResponse('/'.$route, $status); } }