VisitsPaginatorAdapterTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 7
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
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\PhpUnit\ProphecyTrait;
9
use Prophecy\Prophecy\ObjectProphecy;
10
use Shlinkio\Shlink\Common\Util\DateRange;
11
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
12
use Shlinkio\Shlink\Core\Model\VisitsParams;
13
use Shlinkio\Shlink\Core\Paginator\Adapter\VisitsPaginatorAdapter;
14
use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface;
15
16
class VisitsPaginatorAdapterTest extends TestCase
17
{
18
    use ProphecyTrait;
19
20
    private VisitsPaginatorAdapter $adapter;
21
    private ObjectProphecy $repo;
22
23
    protected function setUp(): void
24
    {
25
        $this->repo = $this->prophesize(VisitRepositoryInterface::class);
26
        $this->adapter = new VisitsPaginatorAdapter(
27
            $this->repo->reveal(),
28
            new ShortUrlIdentifier(''),
29
            VisitsParams::fromRawData([]),
30
        );
31
    }
32
33
    /** @test */
34
    public function repoIsCalledEveryTimeItemsAreFetched(): void
35
    {
36
        $count = 3;
37
        $limit = 1;
38
        $offset = 5;
39
        $findVisits = $this->repo->findVisitsByShortCode('', null, new DateRange(), $limit, $offset)->willReturn([]);
40
41
        for ($i = 0; $i < $count; $i++) {
42
            $this->adapter->getItems($offset, $limit);
43
        }
44
45
        $findVisits->shouldHaveBeenCalledTimes($count);
46
    }
47
48
    /** @test */
49
    public function repoIsCalledOnlyOnceForCount(): void
50
    {
51
        $count = 3;
52
        $countVisits = $this->repo->countVisitsByShortCode('', null, new DateRange())->willReturn(3);
53
54
        for ($i = 0; $i < $count; $i++) {
55
            $this->adapter->count();
56
        }
57
58
        $countVisits->shouldHaveBeenCalledOnce();
59
    }
60
}
61