urlGenerator = $this->createMock(UrlGeneratorInterface::class); $this->entityManager = $this->createMock(EntityManagerInterface::class); $this->authenticator = new FlowAuthenticator($this->urlGenerator, $this->entityManager); } public function testSupports() { $request = Request::create('/reservation/flow', 'POST'); $request->attributes->set('_route', 'reservation_flow'); $this->assertTrue($this->authenticator->supports($request)); } public function testAuthenticate() { $request = Request::create('/reservation/flow', 'POST', [ '_username' => 'test@test.com', '_password' => 'password', '_csrf_token' => 'token' ]); $session = $this->createMock(SessionInterface::class); $request->setSession($session); $repository = $this->createMock(EntityRepository::class); $this->entityManager->method('getRepository')->with(Customer::class)->willReturn($repository); $repository->method('findOneBy')->with(['email' => 'test@test.com'])->willReturn(new Customer()); $passport = $this->authenticator->authenticate($request); $this->assertInstanceOf(Passport::class, $passport); $this->assertTrue($passport->hasBadge(UserBadge::class)); } public function testOnAuthenticationSuccess() { $request = Request::create('/reservation/flow'); $request->attributes->set('sessionId', 'session-123'); $token = $this->createMock(TokenInterface::class); $customer = new Customer(); $token->method('getUser')->willReturn($customer); $sessionRepo = $this->createMock(EntityRepository::class); $orderSession = $this->createMock(OrderSession::class); $this->entityManager->method('getRepository')->with(OrderSession::class)->willReturn($sessionRepo); $sessionRepo->method('findOneBy')->with(['uuid' => 'session-123'])->willReturn($orderSession); $orderSession->expects($this->once())->method('setCustomer')->with($customer); $this->entityManager->expects($this->once())->method('flush'); $this->urlGenerator->expects($this->once()) ->method('generate') ->with('reservation_flow', ['sessionId' => 'session-123']) ->willReturn('/reservation/flow/session-123'); $response = $this->authenticator->onAuthenticationSuccess($request, $token, 'main'); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals('/reservation/flow/session-123', $response->getTargetUrl()); } }