diff --git a/module/Core/test-func/Repository/VisitRepositoryTest.php b/module/Core/test-func/Repository/VisitRepositoryTest.php new file mode 100644 index 00000000..b13e4053 --- /dev/null +++ b/module/Core/test-func/Repository/VisitRepositoryTest.php @@ -0,0 +1,80 @@ +repo = $this->getEntityManager()->getRepository(Visit::class); + } + + /** + * @test + */ + public function findUnlocatedVisitsReturnsProperVisits() + { + for ($i = 0; $i < 6; $i++) { + $visit = new Visit(); + + if ($i % 2 === 0) { + $location = new VisitLocation(); + $this->getEntityManager()->persist($location); + $visit->setVisitLocation($location); + } + + $this->getEntityManager()->persist($visit); + } + $this->getEntityManager()->flush(); + + $this->assertCount(3, $this->repo->findUnlocatedVisits()); + } + + /** + * @test + */ + public function findVisitsByShortUrlReturnsProperData() + { + $shortUrl = new ShortUrl(); + $shortUrl->setOriginalUrl(''); + $this->getEntityManager()->persist($shortUrl); + + for ($i = 0; $i < 6; $i++) { + $visit = new Visit(); + $visit->setShortUrl($shortUrl) + ->setDate(new \DateTime('2016-01-0' . ($i + 1))); + + $this->getEntityManager()->persist($visit); + } + $this->getEntityManager()->flush(); + + $this->assertCount(0, $this->repo->findVisitsByShortUrl('invalid')); + $this->assertCount(6, $this->repo->findVisitsByShortUrl($shortUrl->getId())); + $this->assertCount(2, $this->repo->findVisitsByShortUrl($shortUrl->getId(), new DateRange( + new \DateTime('2016-01-02'), + new \DateTime('2016-01-03') + ))); + $this->assertCount(4, $this->repo->findVisitsByShortUrl($shortUrl->getId(), new DateRange( + new \DateTime('2016-01-03') + ))); + } +}