1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagerfanta\Tests\Adapter; |
4
|
|
|
|
5
|
|
|
use Pagerfanta\Adapter\MandangoAdapter; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class MandangoAdapterTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
private $query; |
11
|
|
|
/** |
12
|
|
|
* @var MandangoAdapter |
13
|
|
|
*/ |
14
|
|
|
private $adapter; |
15
|
|
|
|
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
if ($this->isMandangoNotAvailable()) { |
19
|
|
|
$this->markTestSkipped('Mandango is not available'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
$this->query = $this->createQueryMock(); |
23
|
|
|
$this->adapter = new MandangoAdapter($this->query); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
private function isMandangoNotAvailable() |
27
|
|
|
{ |
28
|
|
|
return !class_exists('Mandango\Query'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
private function createQueryMock() |
32
|
|
|
{ |
33
|
|
|
return $this |
34
|
|
|
->getMockBuilder('Mandango\Query') |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMock(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetQuery() |
40
|
|
|
{ |
41
|
|
|
$this->assertSame($this->query, $this->adapter->getQuery()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGetNbResults() |
45
|
|
|
{ |
46
|
|
|
$this->query |
47
|
|
|
->expects($this->once()) |
48
|
|
|
->method('count') |
49
|
|
|
->will($this->returnValue(100)) |
50
|
|
|
; |
51
|
|
|
|
52
|
|
|
$this->assertSame(100, $this->adapter->getNbResults()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testGetResults() |
56
|
|
|
{ |
57
|
|
|
$offset = 14; |
58
|
|
|
$length = 30; |
59
|
|
|
$slice = new \ArrayObject(); |
60
|
|
|
|
61
|
|
|
$this->prepareQuerySkip($offset); |
62
|
|
|
$this->prepareQueryLimit($length); |
63
|
|
|
$this->prepareQueryAll($slice); |
64
|
|
|
|
65
|
|
|
$this->assertSame($slice, $this->adapter->getSlice($offset, $length)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function prepareQueryLimit($limit) |
69
|
|
|
{ |
70
|
|
|
$this->query |
71
|
|
|
->expects($this->once()) |
72
|
|
|
->method('limit') |
73
|
|
|
->with($limit) |
74
|
|
|
->will($this->returnValue($this->query)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function prepareQuerySkip($skip) |
78
|
|
|
{ |
79
|
|
|
$this->query |
80
|
|
|
->expects($this->once()) |
81
|
|
|
->method('skip') |
82
|
|
|
->with($skip) |
83
|
|
|
->will($this->returnValue($this->query)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private function prepareQueryAll($all) |
87
|
|
|
{ |
88
|
|
|
$this->query |
89
|
|
|
->expects($this->once()) |
90
|
|
|
->method('all') |
91
|
|
|
->will($this->returnValue($all)); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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: