Failed Conditions
Push — issue#774 ( 057f04...ee9377 )
by Guilherme
05:15
created

StatsHandlerTest::getRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\StatsBundle\Tests\Handler;
12
13
14
use LoginCidadao\StatsBundle\Entity\Statistics;
15
use LoginCidadao\StatsBundle\Entity\StatisticsRepository;
16
use LoginCidadao\StatsBundle\Handler\StatsHandler;
17
18
class StatsHandlerTest extends \PHPUnit_Framework_TestCase
19
{
20
    public function testHandler()
21
    {
22
        $index = 'index.name';
23
        $key = 'key';
24
        $afterDate = new \DateTime();
25
        $stats = [new Statistics()];
26
27
        /** @var \PHPUnit_Framework_MockObject_MockObject|StatisticsRepository $repo */
28
        $repo = $this->getRepository();
29
        /** @scrutinizer ignore-call */
30
        $repo->expects($this->once())->method('findStatsByIndexKeyDate')->with($index, $key, $afterDate)
31
            ->willReturn($stats);
32
33
        $handler = new StatsHandler($repo);
34
        $this->assertSame($stats, $handler->get($index, $key, $afterDate));
35
    }
36
37
    public function testGetIndexed()
38
    {
39
        $index = 'index.name';
40
        $key = 'key';
41
        $days = 5;
42
        $response = [new Statistics()];
43
44
        /** @var \PHPUnit_Framework_MockObject_MockObject|StatisticsRepository $repo */
45
        $repo = $this->getRepository();
46
        /** @scrutinizer ignore-call */
47
        $repo->expects($this->once())->method('findIndexedStatsByIndexKeyDays')->with($index, $key, $days)
48
            ->willReturn($response);
49
50
        $handler = new StatsHandler($repo);
51
        $this->assertSame($response, $handler->getIndexed($index, $key, $days));
52
    }
53
54
    public function testGetIndexedUniqueDate()
55
    {
56
        $index = 'index.name';
57
        $key = 'key';
58
        $afterDate = new \DateTime();
59
        $response = [new Statistics()];
60
61
        /** @var \PHPUnit_Framework_MockObject_MockObject|StatisticsRepository $repo */
62
        $repo = $this->getRepository();
63
        /** @scrutinizer ignore-call */
64
        $repo->expects($this->once())->method('findIndexedUniqueStatsByIndexKeyDate')->with($index, $key, $afterDate)
65
            ->willReturn($response);
66
67
        $handler = new StatsHandler($repo);
68
        $this->assertSame($response, $handler->getIndexedUniqueDate($index, $key, $afterDate));
69
    }
70
71
    public function testGetIndexedUniqueLastDays()
72
    {
73
        $index = 'index.name';
74
        $key = 'key';
75
        $days = 5;
76
        $response = [new Statistics()];
77
78
        /** @var \PHPUnit_Framework_MockObject_MockObject|StatisticsRepository $repo */
79
        $repo = $this->getRepository();
80
        /** @scrutinizer ignore-call */
81
        $repo->expects($this->once())->method('findIndexedUniqueStatsByIndexKeyDays')->with($index, $key, $days)
82
            ->willReturn($response);
83
84
        $handler = new StatsHandler($repo);
85
        $this->assertSame($response, $handler->getIndexedUniqueLastDays($index, $key, $days));
86
    }
87
88
    public function testGetOneByDate()
89
    {
90
        $index = 'index.name';
91
        $key = 'key';
92
        $date = new \DateTime();
93
        $response = new Statistics();
94
95
        /** @var \PHPUnit_Framework_MockObject_MockObject|StatisticsRepository $repo */
96
        $repo = $this->getRepository();
97
        /** @scrutinizer ignore-call */
98
        $repo->expects($this->once())->method('findOneBy')->with([
99
            'timestamp' => $date,
100
            'index' => $index,
101
            'key' => $key,
102
        ])->willReturn($response);
103
104
        $handler = new StatsHandler($repo);
105
        $this->assertSame($response, $handler->getOneByDate($date, $index, $key));
106
    }
107
108
    /**
109
     * @return \PHPUnit_Framework_MockObject_MockObject|StatisticsRepository
110
     */
111
    private function getRepository()
112
    {
113
        /** @var \PHPUnit_Framework_MockObject_MockObject|StatisticsRepository $repo */
114
        $repo = $this->getMockBuilder('LoginCidadao\StatsBundle\Entity\StatisticsRepository')
115
            ->disableOriginalConstructor()->getMock();
116
117
        return $repo;
118
    }
119
}
120