Completed
Push — develop ( ae060f...1a4eee )
by Alejandro
08:12 queued 08:08
created

VisitsPaginatorAdapterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 20
dl 0
loc 41
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A repoIsCalledEveryTimeItemsAreFetched() 0 12 2
A repoIsCalledOnlyOnceForCount() 0 10 2
A setUp() 0 7 1
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