Пример #1
0
 private function checkAllTokens(UserInterface $user, $tokenHash)
 {
     $now = new \DateTime();
     $tokensToRemove = array();
     $throwExpirationDateException = false;
     /** @var Token $token */
     foreach ($user->getTokens() as $key => $token) {
         if ($token->getExpirationDate() < $now) {
             $tokensToRemove[$key] = $token;
         }
         if ($token->getHash() == $tokenHash) {
             if ($token->getExpirationDate() < $now) {
                 $throwExpirationDateException = true;
             }
         }
     }
     if (!empty($tokensToRemove)) {
         foreach ($tokensToRemove as $key => $token) {
             $user->getTokens()->remove($key);
             $this->repositoryService->remove($token);
         }
     }
     if ($throwExpirationDateException) {
         throw new TokenExpirationDateExpiredException();
     }
 }
 public function testRemove()
 {
     $user = new User();
     $this->dm->expects($this->once())->method('remove')->with($user);
     $this->eventManager->expects($this->once())->method('hasListeners')->with('postRemoveEntity')->willReturn(true);
     $this->eventManager->expects($this->once())->method('dispatchEvent')->with('postRemoveEntity');
     $this->dm->expects($this->once())->method('flush');
     $this->assertInstanceOf('\\Core\\Repository\\RepositoryService', $this->rs->remove($user), '::remove() method should returns $this');
 }