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