VisitsStatsHelperTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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