Updated VisitRepository::findUnlocatedVisits methods so that it paginates the amount of elements loaded in memory

This commit is contained in:
Alejandro Celaya
2019-02-22 19:31:03 +01:00
parent 08bd4f131c
commit 292937b962
7 changed files with 115 additions and 11 deletions

View File

@@ -12,6 +12,8 @@ use Shlinkio\Shlink\Core\Entity\VisitLocation;
use Shlinkio\Shlink\Core\Model\Visitor;
use Shlinkio\Shlink\Core\Repository\VisitRepository;
use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase;
use function Functional\map;
use function range;
use function sprintf;
class VisitRepositoryTest extends DatabaseTestCase
@@ -30,8 +32,11 @@ class VisitRepositoryTest extends DatabaseTestCase
$this->repo = $this->getEntityManager()->getRepository(Visit::class);
}
/** @test */
public function findUnlocatedVisitsReturnsProperVisits(): void
/**
* @test
* @dataProvider provideBlockSize
*/
public function findUnlocatedVisitsReturnsProperVisits(int $blockSize): void
{
$shortUrl = new ShortUrl('');
$this->getEntityManager()->persist($shortUrl);
@@ -50,7 +55,7 @@ class VisitRepositoryTest extends DatabaseTestCase
$this->getEntityManager()->flush();
$resultsCount = 0;
$results = $this->repo->findUnlocatedVisits();
$results = $this->repo->findUnlocatedVisits($blockSize);
foreach ($results as $value) {
$resultsCount++;
}
@@ -58,6 +63,13 @@ class VisitRepositoryTest extends DatabaseTestCase
$this->assertEquals(3, $resultsCount);
}
public function provideBlockSize(): iterable
{
return map(range(1, 5), function (int $value) {
return [$value];
});
}
/** @test */
public function findVisitsByShortCodeReturnsProperData(): void
{