/**
  * @dataProvider dataForPrepareExceptionViewModel
  */
 public function testPrepareExceptionViewModel($error, $result, $exception, $hasIdentity, $isActive, $expectedSetResultCalled)
 {
     $this->event->expects($this->any())->method('getError')->willReturn($error);
     $this->event->expects($this->any())->method('getResult')->willReturn($result);
     $this->event->expects($this->any())->method('getParam')->with($this->equalTo('exception'))->willReturn($exception);
     $this->auth->expects($this->any())->method('hasIdentity')->willReturn($hasIdentity);
     $this->user->expects($this->any())->method('isActive')->willReturn($isActive);
     $this->event->expects($this->exactly($expectedSetResultCalled))->method('setResult');
     $this->listener->prepareExceptionViewModel($this->event);
 }
 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);
 }