9
9
10
10
use ArrayIterator ;
11
11
use Doctrine \ORM \AbstractQuery ;
12
- use Doctrine \ORM \QueryBuilder ;
13
12
use Doctrine \ORM \Tools \Pagination \Paginator ;
14
13
use PHPUnit \Framework \TestCase ;
15
14
use Prophecy \Argument ;
15
+ use Prophecy \Prophecy \ObjectProphecy ;
16
16
use Psr \Http \Message \ServerRequestInterface ;
17
17
use Zend \Expressive \Hal \HalResource ;
18
18
use Zend \Expressive \Hal \Link ;
24
24
25
25
class DoctrinePaginatorTest extends TestCase
26
26
{
27
+ /** @var ObjectProphecy&RouteBasedCollectionMetadata */
28
+ private $ metadata ;
29
+
30
+ /** @var ObjectProphecy&LinkGenerator */
31
+ private $ linkGenerator ;
32
+
33
+ /** @var ObjectProphecy&ResourceGenerator */
34
+ private $ generator ;
35
+
36
+ /** @var ObjectProphecy&ServerRequestInterface */
37
+ private $ request ;
38
+
39
+ /** @var ObjectProphecy&Paginator */
40
+ private $ paginator ;
41
+
42
+ /** @var RouteBasedCollectionStrategy */
43
+ private $ strategy ;
44
+
27
45
public function setUp ()
28
46
{
29
47
$ this ->metadata = $ this ->prophesize (RouteBasedCollectionMetadata::class);
@@ -35,15 +53,15 @@ public function setUp()
35
53
$ this ->strategy = new RouteBasedCollectionStrategy ();
36
54
}
37
55
38
- public function mockQuery ()
56
+ public function mockQuery (): \ PHPUnit \ Framework \ MockObject \ MockObject
39
57
{
40
58
return $ this ->getMockBuilder (AbstractQuery::class)
41
59
->disableOriginalConstructor ()
42
60
->setMethods (['getMaxResults ' , 'setFirstResult ' ])
43
61
->getMockForAbstractClass ();
44
62
}
45
63
46
- public function mockLinkGeneration (string $ relation , string $ route , array $ routeParams , array $ queryStringArgs )
64
+ public function mockLinkGeneration (string $ relation , string $ route , array $ routeParams , array $ queryStringArgs ): void
47
65
{
48
66
$ link = $ this ->prophesize (Link::class)->reveal ();
49
67
$ this ->linkGenerator
@@ -67,7 +85,7 @@ public function invalidPageCombinations() : iterable
67
85
/**
68
86
* @dataProvider invalidPageCombinations
69
87
*/
70
- public function testThrowsOutOfBoundsExceptionForInvalidPage (int $ page , int $ numPages )
88
+ public function testThrowsOutOfBoundsExceptionForInvalidPage (int $ page , int $ numPages ): void
71
89
{
72
90
$ query = $ this ->mockQuery ();
73
91
$ query ->expects ($ this ->once ())
@@ -90,7 +108,7 @@ public function testThrowsOutOfBoundsExceptionForInvalidPage(int $page, int $num
90
108
);
91
109
}
92
110
93
- public function testDoesNotCreateLinksForUnknownPaginationParamType ()
111
+ public function testDoesNotCreateLinksForUnknownPaginationParamType (): void
94
112
{
95
113
$ query = $ this ->mockQuery ();
96
114
$ query ->expects ($ this ->once ())
@@ -113,7 +131,7 @@ public function testDoesNotCreateLinksForUnknownPaginationParamType()
113
131
->shouldBeCalledTimes (1 );
114
132
$ this ->request ->getAttribute (Argument::any (), Argument::any ())->shouldNotBeCalled ();
115
133
116
- $ values = array_map (function ($ value ) {
134
+ $ values = array_map (static function ($ value ) {
117
135
return (object ) ['value ' => $ value ];
118
136
}, range (46 , 60 ));
119
137
$ this ->paginator ->getIterator ()->willReturn (new ArrayIterator ($ values ));
@@ -147,7 +165,7 @@ public function testDoesNotCreateLinksForUnknownPaginationParamType()
147
165
$ this ->assertInstanceOf (HalResource::class, $ resource );
148
166
}
149
167
150
- public function testCreatesLinksForQueryBasedPagination ()
168
+ public function testCreatesLinksForQueryBasedPagination (): void
151
169
{
152
170
$ query = $ this ->mockQuery ();
153
171
$ query ->expects ($ this ->once ())
@@ -173,7 +191,7 @@ public function testCreatesLinksForQueryBasedPagination()
173
191
->shouldBeCalledTimes (1 );
174
192
$ this ->request ->getAttribute (Argument::any (), Argument::any ())->shouldNotBeCalled ();
175
193
176
- $ values = array_map (function ($ value ) {
194
+ $ values = array_map (static function ($ value ) {
177
195
return (object ) ['value ' => $ value ];
178
196
}, range (46 , 60 ));
179
197
$ this ->paginator ->getIterator ()->willReturn (new ArrayIterator ($ values ));
@@ -216,7 +234,7 @@ public function testCreatesLinksForQueryBasedPagination()
216
234
$ this ->assertInstanceOf (HalResource::class, $ resource );
217
235
}
218
236
219
- public function testCreatesLinksForRouteBasedPagination ()
237
+ public function testCreatesLinksForRouteBasedPagination (): void
220
238
{
221
239
$ query = $ this ->mockQuery ();
222
240
$ query ->expects ($ this ->once ())
@@ -242,7 +260,7 @@ public function testCreatesLinksForRouteBasedPagination()
242
260
->willReturn (3 )
243
261
->shouldBeCalledTimes (1 );
244
262
245
- $ values = array_map (function ($ value ) {
263
+ $ values = array_map (static function ($ value ) {
246
264
return (object ) ['value ' => $ value ];
247
265
}, range (46 , 60 ));
248
266
$ this ->paginator ->getIterator ()->willReturn (new ArrayIterator ($ values ));
0 commit comments