Completed
Push — develop ( 449838...84b38c )
by Alejandro
16s queued 12s
created

VisitsStatsHelperTest::provideCounts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
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\Visit;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use PHPUnit\Framework\TestCase;
9
use Prophecy\Prophecy\ObjectProphecy;
10
use Shlinkio\Shlink\Core\Entity\Visit;
11
use Shlinkio\Shlink\Core\Repository\VisitRepository;
12
use Shlinkio\Shlink\Core\Visit\Model\VisitsStats;
13
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelper;
14
15
use function Functional\map;
16
use function range;
17
18
class VisitsStatsHelperTest extends TestCase
19
{
20
    private VisitsStatsHelper $helper;
21
    private ObjectProphecy $em;
22
23
    public function setUp(): void
24
    {
25
        $this->em = $this->prophesize(EntityManagerInterface::class);
26
        $this->helper = new VisitsStatsHelper($this->em->reveal());
27
    }
28
29
    /**
30
     * @test
31
     * @dataProvider provideCounts
32
     */
33
    public function returnsExpectedVisitsStats(int $expectedCount): void
34
    {
35
        $repo = $this->prophesize(VisitRepository::class);
36
        $count = $repo->count([])->willReturn($expectedCount);
37
        $getRepo = $this->em->getRepository(Visit::class)->willReturn($repo->reveal());
38
39
        $stats = $this->helper->getVisitsStats();
40
41
        $this->assertEquals(new VisitsStats($expectedCount), $stats);
42
        $count->shouldHaveBeenCalledOnce();
43
        $getRepo->shouldHaveBeenCalledOnce();
44
    }
45
46
    public function provideCounts(): iterable
47
    {
48
        return map(range(0, 50, 5), fn (int $value) => [$value]);
49
    }
50
}
51