From 3497165ebd3d48f319c3ddb1cad7ad358bb29aa1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 9 Feb 2021 23:34:29 +0100 Subject: [PATCH] Created OrphanVisitsPaginatorAdapterTest --- .../OrphanVisitsPaginatorAdapterTest.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 module/Core/test/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php diff --git a/module/Core/test/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php b/module/Core/test/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php new file mode 100644 index 00000000..6b28aa68 --- /dev/null +++ b/module/Core/test/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php @@ -0,0 +1,65 @@ +repo = $this->prophesize(VisitRepositoryInterface::class); + $this->params = VisitsParams::fromRawData([]); + $this->adapter = new OrphanVisitsPaginatorAdapter($this->repo->reveal(), $this->params); + } + + /** @test */ + public function countDelegatesToRepository(): void + { + $expectedCount = 5; + $repoCount = $this->repo->countOrphanVisits($this->params->getDateRange())->willReturn($expectedCount); + + $result = $this->adapter->getNbResults(); + + self::assertEquals($expectedCount, $result); + $repoCount->shouldHaveBeenCalledOnce(); + } + + /** + * @test + * @dataProvider provideLimitAndOffset + */ + public function getSliceDelegatesToRepository(int $limit, int $offset): void + { + $visitor = Visitor::emptyInstance(); + $list = [Visit::forRegularNotFound($visitor), Visit::forInvalidShortUrl($visitor)]; + $repoFind = $this->repo->findOrphanVisits($this->params->getDateRange(), $limit, $offset)->willReturn($list); + + $result = $this->adapter->getSlice($offset, $limit); + + self::assertEquals($list, $result); + $repoFind->shouldHaveBeenCalledOnce(); + } + + public function provideLimitAndOffset(): iterable + { + yield [1, 5]; + yield [10, 4]; + yield [30, 18]; + } +}