/**
  * @covers Alchemy\Phrasea\Authentication\Authenticator::refreshAccount
  */
 public function testRefreshAccountWithWrongSessionShouldThrowException()
 {
     $app = $this->loadApp();
     $user = self::$DI['user'];
     $app['browser'] = $browser = $this->getBrowserMock();
     $app['session'] = $SFsession = $this->getSessionMock();
     $app['EM'] = $em = $this->getEntityManagerMock();
     $sessionId = 4224242;
     $session = new Session();
     $session->setUser($user);
     $ref = new \ReflectionObject($session);
     $prop = $ref->getProperty('id');
     $prop->setAccessible(true);
     $prop->setValue($session, $sessionId);
     $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $repo->expects($this->once())->method('findOneBy')->with($this->equalTo(['id' => $session->getId()]))->will($this->returnValue(null));
     $em->expects($this->once())->method('getRepository')->with($this->equalTo('Phraseanet:Session'))->will($this->returnValue($repo));
     $authenticator = new Authenticator($app, $browser, $SFsession, $em);
     try {
         $authenticator->refreshAccount($session);
         $this->fail('Should have raised an exception');
     } catch (RuntimeException $e) {
         $this->assertEquals('Unable to refresh the session, it does not exist anymore', $e->getMessage());
     }
 }