Completed
Pull Request — develop (#745)
by Alejandro
05:29
created

VisitsStatsHelperTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
dl 0
loc 31
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A returnsExpectedVisitsStats() 0 11 1
A provideCounts() 0 3 1
A setUp() 0 4 1
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