Completed
Push — master ( 29ce5c...015af1 )
by Maciej
03:02
created

FilterArrayTest::testGetFiltersAddedViaAdd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * File:FilterArrayTest.php
6
 *
7
 * @author Maciej Sławik <[email protected]>
8
 * @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
9
 */
10
11
namespace MSlwk\Otomoto\App\Test\Unit\Stats\Filter;
12
13
use MSlwk\Otomoto\App\Stats\Filter\FilterArray;
14
use MSlwk\Otomoto\App\Stats\Filter\FilterInterface;
15
use PHPUnit\Framework\MockObject\MockObject;
16
use PHPUnit\Framework\TestCase;
17
18
/**
19
 * Class FilterArrayTest
20
 * @package MSlwk\Otomoto\App\Test\Unit\Stats\Filter
21
 */
22
class FilterArrayTest extends TestCase
23
{
24
    /**
25
     * @test
26
     */
27
    public function testGetFiltersAddedViaConstructor()
28
    {
29
        /** @var MockObject|FilterInterface $firstFilter */
30
        $firstFilter = $this->getMockBuilder(FilterInterface::class)
31
            ->getMock();
32
        $firstFilter->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on MSlwk\Otomoto\App\Stats\Filter\FilterInterface. ( Ignorable by Annotation )

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

32
        $firstFilter->/** @scrutinizer ignore-call */ 
33
                      expects($this->once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
            ->method('getName')
34
            ->will($this->returnValue('from'));
35
        /** @var MockObject|FilterInterface $secondFilter */
36
        $secondFilter = $this->getMockBuilder(FilterInterface::class)
37
            ->getMock();
38
        $secondFilter->expects($this->once())
39
            ->method('getName')
40
            ->will($this->returnValue('to'));
41
42
        $filterArray = new FilterArray($firstFilter, $secondFilter);
43
44
        $this->assertEquals('from', $filterArray->get(0)->getName());
45
        $this->assertEquals('to', $filterArray->get(1)->getName());
46
    }
47
48
    /**
49
     * @test
50
     */
51
    public function testGetFiltersAddedViaAdd()
52
    {
53
        /** @var MockObject|FilterInterface $firstFilter */
54
        $firstFilter = $this->getMockBuilder(FilterInterface::class)
55
            ->getMock();
56
        $firstFilter->expects($this->once())
57
            ->method('getName')
58
            ->will($this->returnValue('from'));
59
        /** @var MockObject|FilterInterface $secondFilter */
60
        $secondFilter = $this->getMockBuilder(FilterInterface::class)
61
            ->getMock();
62
        $secondFilter->expects($this->once())
63
            ->method('getName')
64
            ->will($this->returnValue('to'));
65
66
        $filterArray = new FilterArray();
67
68
        $filterArray->add($firstFilter);
69
        $filterArray->add($secondFilter);
70
71
        $this->assertEquals('from', $filterArray->get(0)->getName());
72
        $this->assertEquals('to', $filterArray->get(1)->getName());
73
    }
74
75
    /**
76
     * @test
77
     */
78
    public function testGetFiltersAddedViaSet()
79
    {
80
        /** @var MockObject|FilterInterface $firstFilter */
81
        $firstFilter = $this->getMockBuilder(FilterInterface::class)
82
            ->getMock();
83
        $firstFilter->expects($this->once())
84
            ->method('getName')
85
            ->will($this->returnValue('from'));
86
        /** @var MockObject|FilterInterface $secondFilter */
87
        $secondFilter = $this->getMockBuilder(FilterInterface::class)
88
            ->getMock();
89
        $secondFilter->expects($this->once())
90
            ->method('getName')
91
            ->will($this->returnValue('to'));
92
93
        $filterArray = new FilterArray();
94
95
        $filterArray->set(2, $firstFilter);
96
        $filterArray->set(1, $secondFilter);
97
98
        $this->assertEquals('from', $filterArray->get(2)->getName());
99
        $this->assertEquals('to', $filterArray->get(1)->getName());
100
    }
101
102
    /**
103
     * @test
104
     */
105
    public function testCurrent()
106
    {
107
        /** @var MockObject|FilterInterface $firstFilter */
108
        $firstFilter = $this->getMockBuilder(FilterInterface::class)
109
            ->getMock();
110
        $firstFilter->expects($this->once())
111
            ->method('getName')
112
            ->will($this->returnValue('from'));
113
        /** @var MockObject|FilterInterface $secondFilter */
114
        $secondFilter = $this->getMockBuilder(FilterInterface::class)
115
            ->getMock();
116
        $secondFilter->expects($this->once())
117
            ->method('getName')
118
            ->will($this->returnValue('to'));
119
120
        $filterArray = new FilterArray($firstFilter, $secondFilter);
121
122
        $this->assertEquals('from', $filterArray->current()->getName());
123
        $filterArray->next();
124
        $this->assertEquals('to', $filterArray->current()->getName());
125
    }
126
127
    /**
128
     * @test
129
     */
130
    public function testCount()
131
    {
132
        /** @var MockObject|FilterInterface $firstFilter */
133
        $firstFilter = $this->getMockBuilder(FilterInterface::class)
134
            ->getMock();
135
        /** @var MockObject|FilterInterface $secondFilter */
136
        $secondFilter = $this->getMockBuilder(FilterInterface::class)
137
            ->getMock();
138
139
        $filterArray = new FilterArray($firstFilter, $secondFilter);
140
141
        $this->assertEquals(2, $filterArray->count());
142
    }
143
}
144