/** * @test */ public function checkReturnsFalseWhenKeyIsExpired() { $key = new ApiKey(); $key->setExpirationDate((new \DateTime())->sub(new \DateInterval('P1D'))); $repo = $this->prophesize(EntityRepository::class); $repo->findOneBy(['key' => '12345'])->willReturn($key)->shouldBeCalledTimes(1); $this->em->getRepository(ApiKey::class)->willReturn($repo->reveal()); $this->assertFalse($this->service->check('12345')); }
/** * Creates a new ApiKey with provided expiration date * * @param \DateTime $expirationDate * @return ApiKey */ public function create(\DateTime $expirationDate = null) { $key = new ApiKey(); if (isset($expirationDate)) { $key->setExpirationDate($expirationDate); } $this->em->persist($key); $this->em->flush(); return $key; }