Failed Conditions
Push — issue#777 ( 19a7c1...ca812a )
by Guilherme
05:41
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
        $repo = $this->getRepository();
28
        $repo->expects($this->once())->method('findStatsByIndexKeyDate')->with($index, $key, $afterDate)
0 ignored issues
show
Bug introduced by
The method expects() does not exist on LoginCidadao\StatsBundle...ty\StatisticsRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $repo->/** @scrutinizer ignore-call */ 
29
               expects($this->once())->method('findStatsByIndexKeyDate')->with($index, $key, $afterDate)
Loading history...
29
            ->willReturn($stats);
30
31
        $handler = new StatsHandler($repo);
32
        $this->assertSame($stats, $handler->get($index, $key, $afterDate));
33
    }
34
35
    public function testGetIndexed()
36
    {
37
        $index = 'index.name';
38
        $key = 'key';
39
        $days = 5;
40
        $response = [new Statistics()];
41
42
        $repo = $this->getRepository();
43
        $repo->expects($this->once())->method('findIndexedStatsByIndexKeyDays')->with($index, $key, $days)
44
            ->willReturn($response);
45
46
        $handler = new StatsHandler($repo);
47
        $this->assertSame($response, $handler->getIndexed($index, $key, $days));
48
    }
49
50
    public function testGetIndexedUniqueDate()
51
    {
52
        $index = 'index.name';
53
        $key = 'key';
54
        $afterDate = new \DateTime();
55
        $response = [new Statistics()];
56
57
        $repo = $this->getRepository();
58
        $repo->expects($this->once())->method('findIndexedUniqueStatsByIndexKeyDate')->with($index, $key, $afterDate)
59
            ->willReturn($response);
60
61
        $handler = new StatsHandler($repo);
62
        $this->assertSame($response, $handler->getIndexedUniqueDate($index, $key, $afterDate));
63
    }
64
65
    public function testGetIndexedUniqueLastDays()
66
    {
67
        $index = 'index.name';
68
        $key = 'key';
69
        $days = 5;
70
        $response = [new Statistics()];
71
72
        $repo = $this->getRepository();
73
        $repo->expects($this->once())->method('findIndexedUniqueStatsByIndexKeyDays')->with($index, $key, $days)
74
            ->willReturn($response);
75
76
        $handler = new StatsHandler($repo);
77
        $this->assertSame($response, $handler->getIndexedUniqueLastDays($index, $key, $days));
78
    }
79
80
    public function testGetOneByDate()
81
    {
82
        $index = 'index.name';
83
        $key = 'key';
84
        $date = new \DateTime();
85
        $response = new Statistics();
86
87
        $repo = $this->getRepository();
88
        $repo->expects($this->once())->method('findOneBy')->with([
89
            'timestamp' => $date,
90
            'index' => $index,
91
            'key' => $key,
92
        ])->willReturn($response);
93
94
        $handler = new StatsHandler($repo);
95
        $this->assertSame($response, $handler->getOneByDate($date, $index, $key));
96
    }
97
98
    /**
99
     * @return StatisticsRepository|\PHPUnit_Framework_MockObject_MockObject
100
     */
101
    private function getRepository()
102
    {
103
        /** @var StatisticsRepository|\PHPUnit_Framework_MockObject_MockObject $repo */
104
        $repo = $this->getMockBuilder('LoginCidadao\StatsBundle\Entity\StatisticsRepository')
105
            ->disableOriginalConstructor()->getMock();
106
107
        return $repo;
108
    }
109
}
110