public function testLogout() { $this->cookieService->expects($this->once())->method('read')->with($this->request, $this->response)->will($this->returnValue(new SerieToken(1, 'abc', 'def'))); $this->rememberMeService->expects($this->once())->method('removeSerie')->with(1, 'abc'); $this->cookieService->expects($this->once())->method('writeNull')->with($this->response); $this->listener->logout(new AdapterChainEvent()); }
public function testSerieWithInvalidTokenResets() { $this->assumeSerie($correctSerie = new SerieToken(3, 'abc', 'def')); $correctSerie->setExpiresAt(new \DateTime('tomorrow')); $falseSerie = new SerieToken(3, 'abc', 'gdaf'); $this->mapper->expects($this->once())->method('remove')->with($correctSerie); $nextSerie = $this->service->getNextInSerie($falseSerie); $this->assertNull($nextSerie); }
public function testValidLogin() { $request = new Request(); $response = new Response(); $serieTokenInCookie = new SerieToken(1, 'abc', 'def'); $newSerie = new SerieToken(1, 'abc', 'ghi'); // Assume valid user $this->userMapper->expects($this->once())->method('findById')->will($this->returnValue($this->getMock('ZfcUser\\Entity\\UserInterface'))); // Request contains cookie $this->cookieService->expects($this->once())->method('read')->with($request, $response)->will($this->returnValue($serieTokenInCookie)); // Response contains updated cookie $this->cookieService->expects($this->once())->method('writeSerie')->with($response, $newSerie); $newSerie->setExpiresAt(new \DateTime('+3 days')); $this->rememberMeService->expects($this->once())->method('getNextInSerie')->with($serieTokenInCookie)->will($this->returnValue($newSerie)); $this->authService->expects($this->once())->method('authenticate'); $eventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface'); $this->service->setEventManager($eventManager); $eventManager->expects($this->once())->method('trigger')->with('login', $this->service, ['token' => $newSerie]); $this->service->loginFrom($request, $response); }
public function createService(ServiceLocatorInterface $serviceLocator) { $service = new RememberMeService(); $service->setIpService(new RemoteAddress()); $service->setRequest($serviceLocator->get('Request')); $service->setModuleOptions($serviceLocator->get('JwPersistentUser\\ModuleOptions')); $service->setMapper($serviceLocator->get('JwPersistentUser\\Mapper\\SerieToken')); return $service; }