1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ShlinkioTest\Shlink\Core\Paginator\Adapter; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
9
|
|
|
use Shlinkio\Shlink\Common\Util\DateRange; |
10
|
|
|
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; |
11
|
|
|
use Shlinkio\Shlink\Core\Model\VisitsParams; |
12
|
|
|
use Shlinkio\Shlink\Core\Paginator\Adapter\VisitsPaginatorAdapter; |
13
|
|
|
use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface; |
14
|
|
|
|
15
|
|
|
class VisitsPaginatorAdapterTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
private VisitsPaginatorAdapter $adapter; |
18
|
|
|
private ObjectProphecy $repo; |
19
|
|
|
|
20
|
|
|
protected function setUp(): void |
21
|
|
|
{ |
22
|
|
|
$this->repo = $this->prophesize(VisitRepositoryInterface::class); |
23
|
|
|
$this->adapter = new VisitsPaginatorAdapter( |
24
|
|
|
$this->repo->reveal(), |
25
|
|
|
new ShortUrlIdentifier(''), |
26
|
|
|
VisitsParams::fromRawData([]), |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** @test */ |
31
|
|
|
public function repoIsCalledEveryTimeItemsAreFetched(): void |
32
|
|
|
{ |
33
|
|
|
$count = 3; |
34
|
|
|
$limit = 1; |
35
|
|
|
$offset = 5; |
36
|
|
|
$findVisits = $this->repo->findVisitsByShortCode('', null, new DateRange(), $limit, $offset)->willReturn([]); |
37
|
|
|
|
38
|
|
|
for ($i = 0; $i < $count; $i++) { |
39
|
|
|
$this->adapter->getItems($offset, $limit); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$findVisits->shouldHaveBeenCalledTimes($count); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** @test */ |
46
|
|
|
public function repoIsCalledOnlyOnceForCount(): void |
47
|
|
|
{ |
48
|
|
|
$count = 3; |
49
|
|
|
$countVisits = $this->repo->countVisitsByShortCode('', null, new DateRange())->willReturn(3); |
50
|
|
|
|
51
|
|
|
for ($i = 0; $i < $count; $i++) { |
52
|
|
|
$this->adapter->count(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$countVisits->shouldHaveBeenCalledOnce(); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|