SolariumAdapterTest   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 235
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 5
dl 0
loc 235
rs 10
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
getSolariumName() 0 1 ?
getClientClass() 0 1 ?
getQueryClass() 0 1 ?
getResultClass() 0 1 ?
A setUp() 0 6 2
A isSolariumNotAvailable() 0 4 1
A testConstructorShouldThrowAnInvalidArgumentExceptionWhenInvalidClient() 0 4 1
A testConstructorShouldThrowAnInvalidArgumentExceptionWhenInvalidQuery() 0 4 1
A testGetNbResults() 0 22 1
A testGetNbResultsCanUseACachedTheResultSet() 0 15 1
A testGetSlice() 0 28 1
A testGetSliceCannotUseACachedResultSet() 0 15 1
A testGetNbResultCanUseAGetSliceCachedResultSet() 0 15 1
A testSameGetSliceUseACachedResultSet() 0 15 1
A testDifferentGetSliceCannotUseACachedResultSet() 0 15 1
A testGetResultSet() 0 7 1
A testGetResultSetCanUseAnEndPoint() 0 7 1
A doTestGetResultSet() 0 16 2
A createClientMock() 0 6 1
A createQueryMock() 0 4 1
A createQueryStub() 0 14 1
A createResultMock() 0 6 1
1
<?php
2
3
namespace Pagerfanta\Tests\Adapter;
4
5
use Pagerfanta\Adapter\SolariumAdapter;
6
use PHPUnit\Framework\TestCase;
7
8
abstract class SolariumAdapterTest extends TestCase
9
{
10
    abstract protected function getSolariumName();
11
12
    abstract protected function getClientClass();
13
    abstract protected function getQueryClass();
14
    abstract protected function getResultClass();
15
16
    public function setUp()
17
    {
18
        if ($this->isSolariumNotAvailable()) {
19
            $this->markTestSkipped($this->getSolariumName().' is not available.');
20
        }
21
    }
22
23
    private function isSolariumNotAvailable()
24
    {
25
        return !class_exists($this->getClientClass());
26
    }
27
28
    /**
29
     * @expectedException \Pagerfanta\Exception\InvalidArgumentException
30
     */
31
    public function testConstructorShouldThrowAnInvalidArgumentExceptionWhenInvalidClient()
32
    {
33
        new SolariumAdapter(new \ArrayObject(), $this->createQueryMock());
0 ignored issues
show
Documentation introduced by
new \ArrayObject() is of type object<ArrayObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->createQueryMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Query_Se...ype\Select\Query\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
34
    }
35
36
    /**
37
     * @expectedException \Pagerfanta\Exception\InvalidArgumentException
38
     */
39
    public function testConstructorShouldThrowAnInvalidArgumentExceptionWhenInvalidQuery()
40
    {
41
        new SolariumAdapter($this->createClientMock(), new \ArrayObject());
0 ignored issues
show
Documentation introduced by
new \ArrayObject() is of type object<ArrayObject>, but the function expects a object<Solarium_Query_Se...ype\Select\Query\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->createClientMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
    }
43
44
    public function testGetNbResults()
45
    {
46
        $query = $this->createQueryMock();
47
        $endPoint = null;
48
49
        $result = $this->createResultMock();
50
        $result
51
            ->expects($this->once())
52
            ->method('getNumFound')
53
            ->will($this->returnValue(100));
54
55
        $client = $this->createClientMock();
56
        $client
57
            ->expects($this->once())
58
            ->method('select')
59
            ->with($query, $endPoint)
60
            ->will($this->returnValue($result));
61
62
        $adapter = new SolariumAdapter($client, $query);
0 ignored issues
show
Documentation introduced by
$client is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Query_Se...ype\Select\Query\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
64
        $this->assertSame(100, $adapter->getNbResults());
65
    }
66
67
    public function testGetNbResultsCanUseACachedTheResultSet()
68
    {
69
        $query = $this->createQueryStub();
70
71
        $client = $this->createClientMock();
72
        $client
73
            ->expects($this->once())
74
            ->method('select')
75
            ->will($this->returnValue($this->createResultMock()));
76
77
        $adapter = new SolariumAdapter($client, $query);
0 ignored issues
show
Documentation introduced by
$client is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Query_Se...ype\Select\Query\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
78
79
        $adapter->getSlice(1, 1);
80
        $adapter->getNbResults();
81
    }
82
83
    public function testGetSlice()
84
    {
85
        $query = $this->createQueryMock();
86
        $query
87
            ->expects($this->any())
88
            ->method('setStart')
89
            ->with(1)
90
            ->will($this->returnValue($query));
91
        $query
92
            ->expects($this->any())
93
            ->method('setRows')
94
            ->with(200)
95
            ->will($this->returnValue($query));
96
97
        $endPoint = null;
98
        $result = $this->createResultMock();
99
100
        $client = $this->createClientMock();
101
        $client
102
            ->expects($this->once())
103
            ->method('select')
104
            ->with($query, $endPoint)
105
            ->will($this->returnValue($result));
106
107
        $adapter = new SolariumAdapter($client, $query);
0 ignored issues
show
Documentation introduced by
$client is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Query_Se...ype\Select\Query\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
108
109
        $this->assertSame($result, $adapter->getSlice(1, 200));
110
    }
111
112
    public function testGetSliceCannotUseACachedResultSet()
113
    {
114
        $query = $this->createQueryStub();
115
116
        $client = $this->createClientMock();
117
        $client
118
            ->expects($this->exactly(2))
119
            ->method('select')
120
            ->will($this->returnValue($this->createResultMock()));
121
122
        $adapter = new SolariumAdapter($client, $query);
0 ignored issues
show
Documentation introduced by
$client is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Query_Se...ype\Select\Query\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
124
        $adapter->getNbResults();
125
        $adapter->getSlice(1, 200);
126
    }
127
128
    public function testGetNbResultCanUseAGetSliceCachedResultSet()
129
    {
130
        $query = $this->createQueryStub();
131
132
        $client = $this->createClientMock();
133
        $client
134
            ->expects($this->exactly(1))
135
            ->method('select')
136
            ->will($this->returnValue($this->createResultMock()));
137
138
        $adapter = new SolariumAdapter($client, $query);
0 ignored issues
show
Documentation introduced by
$client is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Query_Se...ype\Select\Query\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
139
140
        $adapter->getSlice(1, 200);
141
        $adapter->getNbResults();
142
    }
143
144
    public function testSameGetSliceUseACachedResultSet()
145
    {
146
        $query = $this->createQueryStub();
147
148
        $client = $this->createClientMock();
149
        $client
150
            ->expects($this->exactly(1))
151
            ->method('select')
152
            ->will($this->returnValue($this->createResultMock()));
153
154
        $adapter = new SolariumAdapter($client, $query);
0 ignored issues
show
Documentation introduced by
$client is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Query_Se...ype\Select\Query\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
155
156
        $adapter->getSlice(1, 200);
157
        $adapter->getSlice(1, 200);
158
    }
159
160
    public function testDifferentGetSliceCannotUseACachedResultSet()
161
    {
162
        $query = $this->createQueryStub();
163
164
        $client = $this->createClientMock();
165
        $client
166
            ->expects($this->exactly(2))
167
            ->method('select')
168
            ->will($this->returnValue($this->createResultMock()));
169
170
        $adapter = new SolariumAdapter($client, $query);
0 ignored issues
show
Documentation introduced by
$client is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Query_Se...ype\Select\Query\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
171
172
        $adapter->getSlice(1, 200);
173
        $adapter->getSlice(2, 200);
174
    }
175
176
    public function testGetResultSet()
177
    {
178
        $query = $this->createQueryMock();
179
        $endPoint = null;
180
181
        $this->doTestGetResultSet($query, $endPoint);
182
    }
183
184
    public function testGetResultSetCanUseAnEndPoint()
185
    {
186
        $query = $this->createQueryMock();
187
        $endPoint = 'ups';
188
189
        $this->doTestGetResultSet($query, $endPoint);
190
    }
191
192
    private function doTestGetResultSet($query, $endPoint)
193
    {
194
        $client = $this->createClientMock();
195
        $client
196
            ->expects($this->atLeastOnce())
197
            ->method('select')
198
            ->with($query, $endPoint)
199
            ->will($this->returnValue($this->createResultMock()));
200
201
        $adapter = new SolariumAdapter($client, $query);
0 ignored issues
show
Documentation introduced by
$client is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Solarium_Client>|...ium\Core\Client\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
202
        if ($endPoint !== null) {
203
            $adapter->setEndPoint($endPoint);
204
        }
205
206
        $this->assertInstanceOf($this->getResultClass(), $adapter->getResultSet());
207
    }
208
209
    private function createClientMock()
210
    {
211
        return $this->getMockBuilder($this->getClientClass())
212
            ->disableOriginalConstructor()
213
            ->getMock();
214
    }
215
216
    private function createQueryMock()
217
    {
218
        return $this->getMockBuilder($this->getQueryClass())->getMock();
219
    }
220
221
    private function createQueryStub()
222
    {
223
        $query = $this->createQueryMock();
224
        $query
225
            ->expects($this->any())
226
            ->method('setStart')
227
            ->will($this->returnSelf());
228
        $query
229
            ->expects($this->any())
230
            ->method('setRows')
231
            ->will($this->returnSelf());
232
233
        return $query;
234
    }
235
236
    private function createResultMock()
237
    {
238
        return $this->getMockBuilder($this->getResultClass())
239
            ->disableOriginalConstructor()
240
            ->getMock();
241
    }
242
}
243