/** * @testdox Allows to use String or DateTime * @covers Auth\Entity\Token::getExpirationDate * @covers Auth\Entity\Token::setExpirationDate */ public function testGetSetExpirationDate() { $input = "01.01.2016"; $this->target->setExpirationDate($input); $this->assertEquals(new \DateTime($input), $this->target->getExpirationDate()); $input = new \DateTime(); $this->target->setExpirationDate($input); $this->assertEquals($input, $this->target->getExpirationDate()); }
public function generate(UserInterface $user, $daysToLive = 1, $storeUser = true) { $tokenHash = Rand::getString(64, $this->charList); $dateStr = sprintf('+ %d day', $daysToLive); $expirationDate = new \Datetime($dateStr); /* @todo We should consider using the Prototype Design Pattern here. */ $token = new Token(); $token->setHash($tokenHash)->setExpirationDate($expirationDate); $user->getTokens()->add($token); if ($storeUser) { $this->repositoryService->store($user); } return $tokenHash; }
public function testProceed() { $tokenHash = uniqid('tokenHash'); $expirationDate = new \DateTime(); $expirationDate->modify('+1 hour'); $token = new Token(); $token->setExpirationDate($expirationDate)->setHash($tokenHash); $expiredToken = new Token(); $expiredToken->setExpirationDate(new \DateTime('2014-01-01 00:00:00')); $expiredToken->setHash(uniqid('tokenHash')); $user = UserEntityProvider::createEntityWithRandomData(); $user->getTokens()->add($token); $user->getTokens()->add($expiredToken); $userId = $user->getId(); $this->userRepositoryMock->expects($this->once())->method('findOneBy')->with(array('id' => new \MongoId($userId), 'tokens.hash' => $tokenHash))->willReturn($user); $this->repositoryServiceMock->expects($this->once())->method('remove')->with($expiredToken); $this->authenticationServiceMock->expects($this->once())->method('getStorage')->willReturnSelf(); $this->authenticationServiceMock->expects($this->once())->method('write')->with($user->getId()); $this->testedObject->proceed($userId, $tokenHash); }