/** * @test */ public function getUnlocatedVisitsFallbacksToRepository() { $repo = $this->prophesize(VisitRepository::class); $repo->findUnlocatedVisits()->shouldBeCalledTimes(1); $this->em->getRepository(Visit::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1); $this->visitService->getUnlocatedVisits(); }
/** * @test */ public function infoReturnsVisistForCertainShortCode() { $shortCode = '123ABC'; $shortUrl = (new ShortUrl())->setOriginalUrl('http://domain.com/foo/bar'); $repo = $this->prophesize(EntityRepository::class); $repo->findOneBy(['shortCode' => $shortCode])->willReturn($shortUrl); $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1); $list = [new Visit(), new Visit()]; $repo2 = $this->prophesize(VisitRepository::class); $repo2->findVisitsByShortUrl($shortUrl, null)->willReturn($list); $this->em->getRepository(Visit::class)->willReturn($repo2->reveal())->shouldBeCalledTimes(1); $this->assertEquals($list, $this->visitsTracker->info($shortCode)); }
/** * @test */ public function providedTagsAreGetFromRepoAndSetToTheShortUrl() { $shortUrl = $this->prophesize(ShortUrl::class); $shortUrl->setTags(Argument::any())->shouldBeCalledTimes(1); $shortCode = 'abc123'; $repo = $this->prophesize(ShortUrlRepository::class); $repo->findOneBy(['shortCode' => $shortCode])->willReturn($shortUrl->reveal())->shouldBeCalledTimes(1); $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal()); $tagRepo = $this->prophesize(EntityRepository::class); $tagRepo->findOneBy(['name' => 'foo'])->willReturn(new Tag())->shouldbeCalledTimes(1); $tagRepo->findOneBy(['name' => 'bar'])->willReturn(null)->shouldbeCalledTimes(1); $this->em->getRepository(Tag::class)->willReturn($tagRepo->reveal()); $this->service->setTagsByShortCode($shortCode, ['foo', 'bar']); }
/** * @test */ public function listEnabledFindsOnlyEnabledApiKeys() { $repo = $this->prophesize(EntityRepository::class); $repo->findBy(['enabled' => true])->willReturn([])->shouldBeCalledTimes(1); $this->em->getRepository(ApiKey::class)->willReturn($repo->reveal()); $this->service->listKeys(true); }
/** * @test */ public function cachedShortCodeDoesNotHitDatabase() { $shortCode = '12C1c'; $expectedUrl = 'expected_url'; $this->cache->save($shortCode . '_longUrl', $expectedUrl); $this->em->getRepository(ShortUrl::class)->willReturn(null)->shouldBeCalledTimes(0); $url = $this->urlShortener->shortCodeToUrl($shortCode); $this->assertEquals($expectedUrl, $url); }