1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Lampager\Cake\Test\TestCase\Model\Behavior; |
6
|
|
|
|
7
|
|
|
use Cake\I18n\DateTime; |
8
|
|
|
use Cake\ORM\Entity; |
9
|
|
|
use Cake\ORM\Table; |
10
|
|
|
use Cake\ORM\TableRegistry; |
11
|
|
|
use Generator; |
12
|
|
|
use Lampager\Cake\Model\Behavior\LampagerBehavior; |
13
|
|
|
use Lampager\Cake\ORM\Query; |
14
|
|
|
use Lampager\Cake\Test\TestCase\TestCase; |
15
|
|
|
use Lampager\PaginationResult; |
16
|
|
|
use PHPUnit\Framework\Attributes\DataProvider; |
17
|
|
|
|
18
|
|
|
class LampagerBehaviorTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
public array $fixtures = [ |
21
|
|
|
'plugin.Lampager\\Cake.Posts', |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
#[DataProvider('valueProvider')] |
25
|
|
|
#[DataProvider('queryExpressionProvider')] |
26
|
|
|
public function testLampager(callable $factory, PaginationResult $expected): void |
27
|
|
|
{ |
28
|
|
|
/** @var LampagerBehavior&Table $posts */ |
29
|
|
|
$posts = TableRegistry::getTableLocator()->get('Posts'); |
30
|
|
|
$posts->addBehavior(LampagerBehavior::class); |
31
|
|
|
|
32
|
|
|
/** @var Query $query */ |
33
|
|
|
$query = $factory($posts); |
34
|
|
|
$this->assertJsonEquals($expected, $query->paginate()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function valueProvider(): Generator |
38
|
|
|
{ |
39
|
|
|
yield 'Ascending forward start inclusive' => [ |
40
|
|
|
function (Table $posts) { |
41
|
|
|
/** @var LampagerBehavior&Table $posts */ |
42
|
|
|
return $posts->lampager() |
43
|
|
|
->forward() |
44
|
|
|
->seekable() |
45
|
|
|
->limit(3) |
46
|
|
|
->orderByAsc('modified') |
47
|
|
|
->orderByAsc('id'); |
48
|
|
|
}, |
49
|
|
|
new PaginationResult( |
50
|
|
|
[ |
51
|
|
|
new Entity([ |
52
|
|
|
'id' => 1, |
53
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
54
|
|
|
]), |
55
|
|
|
new Entity([ |
56
|
|
|
'id' => 3, |
57
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
58
|
|
|
]), |
59
|
|
|
new Entity([ |
60
|
|
|
'id' => 5, |
61
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
62
|
|
|
]), |
63
|
|
|
], |
64
|
|
|
[ |
65
|
|
|
'hasPrevious' => null, |
66
|
|
|
'previousCursor' => null, |
67
|
|
|
'hasNext' => true, |
68
|
|
|
'nextCursor' => [ |
69
|
|
|
'id' => 2, |
70
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
71
|
|
|
], |
72
|
|
|
] |
73
|
|
|
), |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
yield 'Ascending forward start exclusive' => [ |
77
|
|
|
function (Table $posts) { |
78
|
|
|
/** @var LampagerBehavior&Table $posts */ |
79
|
|
|
return $posts->lampager() |
80
|
|
|
->forward() |
81
|
|
|
->seekable() |
82
|
|
|
->exclusive() |
83
|
|
|
->limit(3) |
84
|
|
|
->orderByAsc('modified') |
85
|
|
|
->orderByAsc('id'); |
86
|
|
|
}, |
87
|
|
|
new PaginationResult( |
88
|
|
|
[ |
89
|
|
|
new Entity([ |
90
|
|
|
'id' => 1, |
91
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
92
|
|
|
]), |
93
|
|
|
new Entity([ |
94
|
|
|
'id' => 3, |
95
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
96
|
|
|
]), |
97
|
|
|
new Entity([ |
98
|
|
|
'id' => 5, |
99
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
100
|
|
|
]), |
101
|
|
|
], |
102
|
|
|
[ |
103
|
|
|
'hasPrevious' => null, |
104
|
|
|
'previousCursor' => null, |
105
|
|
|
'hasNext' => true, |
106
|
|
|
'nextCursor' => [ |
107
|
|
|
'id' => 5, |
108
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
109
|
|
|
], |
110
|
|
|
] |
111
|
|
|
), |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
yield 'Ascending forward inclusive' => [ |
115
|
|
|
function (Table $posts) { |
116
|
|
|
/** @var LampagerBehavior&Table $posts */ |
117
|
|
|
return $posts->lampager() |
118
|
|
|
->forward() |
119
|
|
|
->seekable() |
120
|
|
|
->limit(3) |
121
|
|
|
->orderByAsc('modified') |
122
|
|
|
->orderByAsc('id') |
123
|
|
|
->cursor([ |
124
|
|
|
'id' => 3, |
125
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
126
|
|
|
]); |
127
|
|
|
}, |
128
|
|
|
new PaginationResult( |
129
|
|
|
[ |
130
|
|
|
new Entity([ |
131
|
|
|
'id' => 3, |
132
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
133
|
|
|
]), |
134
|
|
|
new Entity([ |
135
|
|
|
'id' => 5, |
136
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
137
|
|
|
]), |
138
|
|
|
new Entity([ |
139
|
|
|
'id' => 2, |
140
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
141
|
|
|
]), |
142
|
|
|
], |
143
|
|
|
[ |
144
|
|
|
'hasPrevious' => true, |
145
|
|
|
'previousCursor' => [ |
146
|
|
|
'id' => 1, |
147
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
148
|
|
|
], |
149
|
|
|
'hasNext' => true, |
150
|
|
|
'nextCursor' => [ |
151
|
|
|
'id' => 4, |
152
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
153
|
|
|
], |
154
|
|
|
] |
155
|
|
|
), |
156
|
|
|
]; |
157
|
|
|
|
158
|
|
|
yield 'Ascending forward exclusive' => [ |
159
|
|
|
function (Table $posts) { |
160
|
|
|
/** @var LampagerBehavior&Table $posts */ |
161
|
|
|
return $posts->lampager() |
162
|
|
|
->forward() |
163
|
|
|
->seekable() |
164
|
|
|
->exclusive() |
165
|
|
|
->limit(3) |
166
|
|
|
->orderByAsc('modified') |
167
|
|
|
->orderByAsc('id') |
168
|
|
|
->cursor([ |
169
|
|
|
'id' => 3, |
170
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
171
|
|
|
]); |
172
|
|
|
}, |
173
|
|
|
new PaginationResult( |
174
|
|
|
[ |
175
|
|
|
new Entity([ |
176
|
|
|
'id' => 5, |
177
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
178
|
|
|
]), |
179
|
|
|
new Entity([ |
180
|
|
|
'id' => 2, |
181
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
182
|
|
|
]), |
183
|
|
|
new Entity([ |
184
|
|
|
'id' => 4, |
185
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
186
|
|
|
]), |
187
|
|
|
], |
188
|
|
|
[ |
189
|
|
|
'hasPrevious' => true, |
190
|
|
|
'previousCursor' => [ |
191
|
|
|
'id' => 5, |
192
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
193
|
|
|
], |
194
|
|
|
'hasNext' => false, |
195
|
|
|
'nextCursor' => null, |
196
|
|
|
] |
197
|
|
|
), |
198
|
|
|
]; |
199
|
|
|
|
200
|
|
|
yield 'Ascending backward start inclusive' => [ |
201
|
|
|
function (Table $posts) { |
202
|
|
|
/** @var LampagerBehavior&Table $posts */ |
203
|
|
|
return $posts->lampager() |
204
|
|
|
->backward() |
205
|
|
|
->seekable() |
206
|
|
|
->limit(3) |
207
|
|
|
->orderByAsc('modified') |
208
|
|
|
->orderByAsc('id'); |
209
|
|
|
}, |
210
|
|
|
new PaginationResult( |
211
|
|
|
[ |
212
|
|
|
new Entity([ |
213
|
|
|
'id' => 5, |
214
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
215
|
|
|
]), |
216
|
|
|
new Entity([ |
217
|
|
|
'id' => 2, |
218
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
219
|
|
|
]), |
220
|
|
|
new Entity([ |
221
|
|
|
'id' => 4, |
222
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
223
|
|
|
]), |
224
|
|
|
], |
225
|
|
|
[ |
226
|
|
|
'hasPrevious' => true, |
227
|
|
|
'previousCursor' => [ |
228
|
|
|
'id' => 3, |
229
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
230
|
|
|
], |
231
|
|
|
'hasNext' => null, |
232
|
|
|
'nextCursor' => null, |
233
|
|
|
] |
234
|
|
|
), |
235
|
|
|
]; |
236
|
|
|
|
237
|
|
|
yield 'Ascending backward start exclusive' => [ |
238
|
|
|
function (Table $posts) { |
239
|
|
|
/** @var LampagerBehavior&Table $posts */ |
240
|
|
|
return $posts->lampager() |
241
|
|
|
->backward() |
242
|
|
|
->seekable() |
243
|
|
|
->exclusive() |
244
|
|
|
->limit(3) |
245
|
|
|
->orderByAsc('modified') |
246
|
|
|
->orderByAsc('id'); |
247
|
|
|
}, |
248
|
|
|
new PaginationResult( |
249
|
|
|
[ |
250
|
|
|
new Entity([ |
251
|
|
|
'id' => 5, |
252
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
253
|
|
|
]), |
254
|
|
|
new Entity([ |
255
|
|
|
'id' => 2, |
256
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
257
|
|
|
]), |
258
|
|
|
new Entity([ |
259
|
|
|
'id' => 4, |
260
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
261
|
|
|
]), |
262
|
|
|
], |
263
|
|
|
[ |
264
|
|
|
'hasPrevious' => true, |
265
|
|
|
'previousCursor' => [ |
266
|
|
|
'id' => 5, |
267
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
268
|
|
|
], |
269
|
|
|
'hasNext' => null, |
270
|
|
|
'nextCursor' => null, |
271
|
|
|
] |
272
|
|
|
), |
273
|
|
|
]; |
274
|
|
|
|
275
|
|
|
yield 'Ascending backward inclusive' => [ |
276
|
|
|
function (Table $posts) { |
277
|
|
|
/** @var LampagerBehavior&Table $posts */ |
278
|
|
|
return $posts->lampager() |
279
|
|
|
->backward() |
280
|
|
|
->seekable() |
281
|
|
|
->limit(3) |
282
|
|
|
->orderByAsc('modified') |
283
|
|
|
->orderByAsc('id') |
284
|
|
|
->cursor([ |
285
|
|
|
'id' => 3, |
286
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
287
|
|
|
]); |
288
|
|
|
}, |
289
|
|
|
new PaginationResult( |
290
|
|
|
[ |
291
|
|
|
new Entity([ |
292
|
|
|
'id' => 1, |
293
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
294
|
|
|
]), |
295
|
|
|
new Entity([ |
296
|
|
|
'id' => 3, |
297
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
298
|
|
|
]), |
299
|
|
|
], |
300
|
|
|
[ |
301
|
|
|
'hasPrevious' => false, |
302
|
|
|
'previousCursor' => null, |
303
|
|
|
'hasNext' => true, |
304
|
|
|
'nextCursor' => [ |
305
|
|
|
'id' => 5, |
306
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
307
|
|
|
], |
308
|
|
|
] |
309
|
|
|
), |
310
|
|
|
]; |
311
|
|
|
|
312
|
|
|
yield 'Ascending backward exclusive' => [ |
313
|
|
|
function (Table $posts) { |
314
|
|
|
/** @var LampagerBehavior&Table $posts */ |
315
|
|
|
return $posts->lampager() |
316
|
|
|
->backward() |
317
|
|
|
->seekable() |
318
|
|
|
->exclusive() |
319
|
|
|
->limit(3) |
320
|
|
|
->orderByAsc('modified') |
321
|
|
|
->orderByAsc('id') |
322
|
|
|
->cursor([ |
323
|
|
|
'id' => 3, |
324
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
325
|
|
|
]); |
326
|
|
|
}, |
327
|
|
|
new PaginationResult( |
328
|
|
|
[ |
329
|
|
|
new Entity([ |
330
|
|
|
'id' => 1, |
331
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
332
|
|
|
]), |
333
|
|
|
], |
334
|
|
|
[ |
335
|
|
|
'hasPrevious' => false, |
336
|
|
|
'previousCursor' => null, |
337
|
|
|
'hasNext' => true, |
338
|
|
|
'nextCursor' => [ |
339
|
|
|
'id' => 1, |
340
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
341
|
|
|
], |
342
|
|
|
] |
343
|
|
|
), |
344
|
|
|
]; |
345
|
|
|
|
346
|
|
|
yield 'Descending forward start inclusive' => [ |
347
|
|
|
function (Table $posts) { |
348
|
|
|
/** @var LampagerBehavior&Table $posts */ |
349
|
|
|
return $posts->lampager() |
350
|
|
|
->forward() |
351
|
|
|
->seekable() |
352
|
|
|
->limit(3) |
353
|
|
|
->orderByDesc('modified') |
354
|
|
|
->orderByDesc('id'); |
355
|
|
|
}, |
356
|
|
|
new PaginationResult( |
357
|
|
|
[ |
358
|
|
|
new Entity([ |
359
|
|
|
'id' => 4, |
360
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
361
|
|
|
]), |
362
|
|
|
new Entity([ |
363
|
|
|
'id' => 2, |
364
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
365
|
|
|
]), |
366
|
|
|
new Entity([ |
367
|
|
|
'id' => 5, |
368
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
369
|
|
|
]), |
370
|
|
|
], |
371
|
|
|
[ |
372
|
|
|
'hasPrevious' => null, |
373
|
|
|
'previousCursor' => null, |
374
|
|
|
'hasNext' => true, |
375
|
|
|
'nextCursor' => [ |
376
|
|
|
'id' => 3, |
377
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
378
|
|
|
], |
379
|
|
|
] |
380
|
|
|
), |
381
|
|
|
]; |
382
|
|
|
|
383
|
|
|
yield 'Descending forward start exclusive' => [ |
384
|
|
|
function (Table $posts) { |
385
|
|
|
/** @var LampagerBehavior&Table $posts */ |
386
|
|
|
return $posts->lampager() |
387
|
|
|
->forward() |
388
|
|
|
->seekable() |
389
|
|
|
->exclusive() |
390
|
|
|
->limit(3) |
391
|
|
|
->orderByDesc('modified') |
392
|
|
|
->orderByDesc('id'); |
393
|
|
|
}, |
394
|
|
|
new PaginationResult( |
395
|
|
|
[ |
396
|
|
|
new Entity([ |
397
|
|
|
'id' => 4, |
398
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
399
|
|
|
]), |
400
|
|
|
new Entity([ |
401
|
|
|
'id' => 2, |
402
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
403
|
|
|
]), |
404
|
|
|
new Entity([ |
405
|
|
|
'id' => 5, |
406
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
407
|
|
|
]), |
408
|
|
|
], |
409
|
|
|
[ |
410
|
|
|
'hasPrevious' => null, |
411
|
|
|
'previousCursor' => null, |
412
|
|
|
'hasNext' => true, |
413
|
|
|
'nextCursor' => [ |
414
|
|
|
'id' => 5, |
415
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
416
|
|
|
], |
417
|
|
|
] |
418
|
|
|
), |
419
|
|
|
]; |
420
|
|
|
|
421
|
|
|
yield 'Descending forward inclusive' => [ |
422
|
|
|
function (Table $posts) { |
423
|
|
|
/** @var LampagerBehavior&Table $posts */ |
424
|
|
|
return $posts->lampager() |
425
|
|
|
->forward() |
426
|
|
|
->seekable() |
427
|
|
|
->limit(3) |
428
|
|
|
->orderByDesc('modified') |
429
|
|
|
->orderByDesc('id') |
430
|
|
|
->cursor([ |
431
|
|
|
'id' => 3, |
432
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
433
|
|
|
]); |
434
|
|
|
}, |
435
|
|
|
new PaginationResult( |
436
|
|
|
[ |
437
|
|
|
new Entity([ |
438
|
|
|
'id' => 3, |
439
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
440
|
|
|
]), |
441
|
|
|
new Entity([ |
442
|
|
|
'id' => 1, |
443
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
444
|
|
|
]), |
445
|
|
|
], |
446
|
|
|
[ |
447
|
|
|
'hasPrevious' => true, |
448
|
|
|
'previousCursor' => [ |
449
|
|
|
'id' => 5, |
450
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
451
|
|
|
], |
452
|
|
|
'hasNext' => false, |
453
|
|
|
'nextCursor' => null, |
454
|
|
|
] |
455
|
|
|
), |
456
|
|
|
]; |
457
|
|
|
|
458
|
|
|
yield 'Descending forward exclusive' => [ |
459
|
|
|
function (Table $posts) { |
460
|
|
|
/** @var LampagerBehavior&Table $posts */ |
461
|
|
|
return $posts->lampager() |
462
|
|
|
->forward() |
463
|
|
|
->seekable() |
464
|
|
|
->exclusive() |
465
|
|
|
->limit(3) |
466
|
|
|
->orderByDesc('modified') |
467
|
|
|
->orderByDesc('id') |
468
|
|
|
->cursor([ |
469
|
|
|
'id' => 3, |
470
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
471
|
|
|
]); |
472
|
|
|
}, |
473
|
|
|
new PaginationResult( |
474
|
|
|
[ |
475
|
|
|
new Entity([ |
476
|
|
|
'id' => 1, |
477
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
478
|
|
|
]), |
479
|
|
|
], |
480
|
|
|
[ |
481
|
|
|
'hasPrevious' => true, |
482
|
|
|
'previousCursor' => [ |
483
|
|
|
'id' => 1, |
484
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
485
|
|
|
], |
486
|
|
|
'hasNext' => false, |
487
|
|
|
'nextCursor' => null, |
488
|
|
|
] |
489
|
|
|
), |
490
|
|
|
]; |
491
|
|
|
|
492
|
|
|
yield 'Descending backward start inclusive' => [ |
493
|
|
|
function (Table $posts) { |
494
|
|
|
/** @var LampagerBehavior&Table $posts */ |
495
|
|
|
return $posts->lampager() |
496
|
|
|
->backward() |
497
|
|
|
->seekable() |
498
|
|
|
->limit(3) |
499
|
|
|
->orderByDesc('modified') |
500
|
|
|
->orderByDesc('id'); |
501
|
|
|
}, |
502
|
|
|
new PaginationResult( |
503
|
|
|
[ |
504
|
|
|
new Entity([ |
505
|
|
|
'id' => 5, |
506
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
507
|
|
|
]), |
508
|
|
|
new Entity([ |
509
|
|
|
'id' => 3, |
510
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
511
|
|
|
]), |
512
|
|
|
new Entity([ |
513
|
|
|
'id' => 1, |
514
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
515
|
|
|
]), |
516
|
|
|
], |
517
|
|
|
[ |
518
|
|
|
'hasPrevious' => true, |
519
|
|
|
'previousCursor' => [ |
520
|
|
|
'id' => 2, |
521
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
522
|
|
|
], |
523
|
|
|
'hasNext' => null, |
524
|
|
|
'nextCursor' => null, |
525
|
|
|
] |
526
|
|
|
), |
527
|
|
|
]; |
528
|
|
|
|
529
|
|
|
yield 'Descending backward start exclusive' => [ |
530
|
|
|
function (Table $posts) { |
531
|
|
|
/** @var LampagerBehavior&Table $posts */ |
532
|
|
|
return $posts->lampager() |
533
|
|
|
->backward() |
534
|
|
|
->seekable() |
535
|
|
|
->exclusive() |
536
|
|
|
->limit(3) |
537
|
|
|
->orderByDesc('modified') |
538
|
|
|
->orderByDesc('id'); |
539
|
|
|
}, |
540
|
|
|
new PaginationResult( |
541
|
|
|
[ |
542
|
|
|
new Entity([ |
543
|
|
|
'id' => 5, |
544
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
545
|
|
|
]), |
546
|
|
|
new Entity([ |
547
|
|
|
'id' => 3, |
548
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
549
|
|
|
]), |
550
|
|
|
new Entity([ |
551
|
|
|
'id' => 1, |
552
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
553
|
|
|
]), |
554
|
|
|
], |
555
|
|
|
[ |
556
|
|
|
'hasPrevious' => true, |
557
|
|
|
'previousCursor' => [ |
558
|
|
|
'id' => 5, |
559
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
560
|
|
|
], |
561
|
|
|
'hasNext' => null, |
562
|
|
|
'nextCursor' => null, |
563
|
|
|
] |
564
|
|
|
), |
565
|
|
|
]; |
566
|
|
|
|
567
|
|
|
yield 'Descending backward inclusive' => [ |
568
|
|
|
function (Table $posts) { |
569
|
|
|
/** @var LampagerBehavior&Table $posts */ |
570
|
|
|
return $posts->lampager() |
571
|
|
|
->backward() |
572
|
|
|
->seekable() |
573
|
|
|
->limit(3) |
574
|
|
|
->orderByDesc('modified') |
575
|
|
|
->orderByDesc('id') |
576
|
|
|
->cursor([ |
577
|
|
|
'id' => 3, |
578
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
579
|
|
|
]); |
580
|
|
|
}, |
581
|
|
|
new PaginationResult( |
582
|
|
|
[ |
583
|
|
|
new Entity([ |
584
|
|
|
'id' => 2, |
585
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
586
|
|
|
]), |
587
|
|
|
new Entity([ |
588
|
|
|
'id' => 5, |
589
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
590
|
|
|
]), |
591
|
|
|
new Entity([ |
592
|
|
|
'id' => 3, |
593
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
594
|
|
|
]), |
595
|
|
|
], |
596
|
|
|
[ |
597
|
|
|
'hasPrevious' => true, |
598
|
|
|
'previousCursor' => [ |
599
|
|
|
'id' => 4, |
600
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
601
|
|
|
], |
602
|
|
|
'hasNext' => true, |
603
|
|
|
'nextCursor' => [ |
604
|
|
|
'id' => 1, |
605
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
606
|
|
|
], |
607
|
|
|
] |
608
|
|
|
), |
609
|
|
|
]; |
610
|
|
|
|
611
|
|
|
yield 'Descending backward exclusive' => [ |
612
|
|
|
function (Table $posts) { |
613
|
|
|
/** @var LampagerBehavior&Table $posts */ |
614
|
|
|
return $posts->lampager() |
615
|
|
|
->backward() |
616
|
|
|
->seekable() |
617
|
|
|
->exclusive() |
618
|
|
|
->limit(3) |
619
|
|
|
->orderByDesc('modified') |
620
|
|
|
->orderByDesc('id') |
621
|
|
|
->cursor([ |
622
|
|
|
'id' => 3, |
623
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
624
|
|
|
]); |
625
|
|
|
}, |
626
|
|
|
new PaginationResult( |
627
|
|
|
[ |
628
|
|
|
new Entity([ |
629
|
|
|
'id' => 4, |
630
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
631
|
|
|
]), |
632
|
|
|
new Entity([ |
633
|
|
|
'id' => 2, |
634
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
635
|
|
|
]), |
636
|
|
|
new Entity([ |
637
|
|
|
'id' => 5, |
638
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
639
|
|
|
]), |
640
|
|
|
], |
641
|
|
|
[ |
642
|
|
|
'hasPrevious' => false, |
643
|
|
|
'previousCursor' => null, |
644
|
|
|
'hasNext' => true, |
645
|
|
|
'nextCursor' => [ |
646
|
|
|
'id' => 5, |
647
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
648
|
|
|
], |
649
|
|
|
] |
650
|
|
|
), |
651
|
|
|
]; |
652
|
|
|
} |
653
|
|
|
|
654
|
|
|
public static function queryExpressionProvider(): Generator |
655
|
|
|
{ |
656
|
|
|
yield 'Ascending forward start inclusive with QueryExpression' => [ |
657
|
|
|
function (Table $posts) { |
658
|
|
|
/** @var LampagerBehavior&Table $posts */ |
659
|
|
|
return $posts->lampager() |
660
|
|
|
->forward() |
661
|
|
|
->seekable() |
662
|
|
|
->limit(3) |
663
|
|
|
->orderByAsc($posts->selectQuery()->expr('modified')) |
664
|
|
|
->orderByAsc($posts->selectQuery()->expr('id')); |
665
|
|
|
}, |
666
|
|
|
new PaginationResult( |
667
|
|
|
[ |
668
|
|
|
new Entity([ |
669
|
|
|
'id' => 1, |
670
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
671
|
|
|
]), |
672
|
|
|
new Entity([ |
673
|
|
|
'id' => 3, |
674
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
675
|
|
|
]), |
676
|
|
|
new Entity([ |
677
|
|
|
'id' => 5, |
678
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
679
|
|
|
]), |
680
|
|
|
], |
681
|
|
|
[ |
682
|
|
|
'hasPrevious' => null, |
683
|
|
|
'previousCursor' => null, |
684
|
|
|
'hasNext' => true, |
685
|
|
|
'nextCursor' => [ |
686
|
|
|
'id' => 2, |
687
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
688
|
|
|
], |
689
|
|
|
] |
690
|
|
|
), |
691
|
|
|
]; |
692
|
|
|
|
693
|
|
|
yield 'Ascending forward inclusive with QueryExpression' => [ |
694
|
|
|
function (Table $posts) { |
695
|
|
|
/** @var LampagerBehavior&Table $posts */ |
696
|
|
|
return $posts->lampager() |
697
|
|
|
->forward() |
698
|
|
|
->seekable() |
699
|
|
|
->limit(3) |
700
|
|
|
->orderByAsc($posts->selectQuery()->expr('modified')) |
701
|
|
|
->orderByAsc($posts->selectQuery()->expr('id')) |
702
|
|
|
->cursor([ |
703
|
|
|
'id' => 3, |
704
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
705
|
|
|
]); |
706
|
|
|
}, |
707
|
|
|
new PaginationResult( |
708
|
|
|
[ |
709
|
|
|
new Entity([ |
710
|
|
|
'id' => 3, |
711
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
712
|
|
|
]), |
713
|
|
|
new Entity([ |
714
|
|
|
'id' => 5, |
715
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
716
|
|
|
]), |
717
|
|
|
new Entity([ |
718
|
|
|
'id' => 2, |
719
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
720
|
|
|
]), |
721
|
|
|
], |
722
|
|
|
[ |
723
|
|
|
'hasPrevious' => true, |
724
|
|
|
'previousCursor' => [ |
725
|
|
|
'id' => 1, |
726
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
727
|
|
|
], |
728
|
|
|
'hasNext' => true, |
729
|
|
|
'nextCursor' => [ |
730
|
|
|
'id' => 4, |
731
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
732
|
|
|
], |
733
|
|
|
] |
734
|
|
|
), |
735
|
|
|
]; |
736
|
|
|
|
737
|
|
|
yield 'Ascending forward exclusive with QueryExpression' => [ |
738
|
|
|
function (Table $posts) { |
739
|
|
|
/** @var LampagerBehavior&Table $posts */ |
740
|
|
|
return $posts->lampager() |
741
|
|
|
->forward() |
742
|
|
|
->seekable() |
743
|
|
|
->exclusive() |
744
|
|
|
->limit(3) |
745
|
|
|
->orderByAsc($posts->selectQuery()->expr('modified')) |
746
|
|
|
->orderByAsc($posts->selectQuery()->expr('id')) |
747
|
|
|
->cursor([ |
748
|
|
|
'id' => 3, |
749
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
750
|
|
|
]); |
751
|
|
|
}, |
752
|
|
|
new PaginationResult( |
753
|
|
|
[ |
754
|
|
|
new Entity([ |
755
|
|
|
'id' => 5, |
756
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
757
|
|
|
]), |
758
|
|
|
new Entity([ |
759
|
|
|
'id' => 2, |
760
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
761
|
|
|
]), |
762
|
|
|
new Entity([ |
763
|
|
|
'id' => 4, |
764
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
765
|
|
|
]), |
766
|
|
|
], |
767
|
|
|
[ |
768
|
|
|
'hasPrevious' => true, |
769
|
|
|
'previousCursor' => [ |
770
|
|
|
'id' => 5, |
771
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
772
|
|
|
], |
773
|
|
|
'hasNext' => false, |
774
|
|
|
'nextCursor' => null, |
775
|
|
|
] |
776
|
|
|
), |
777
|
|
|
]; |
778
|
|
|
|
779
|
|
|
yield 'Ascending backward start inclusive with QueryExpression' => [ |
780
|
|
|
function (Table $posts) { |
781
|
|
|
/** @var LampagerBehavior&Table $posts */ |
782
|
|
|
return $posts->lampager() |
783
|
|
|
->backward() |
784
|
|
|
->seekable() |
785
|
|
|
->limit(3) |
786
|
|
|
->orderByAsc($posts->selectQuery()->expr('modified')) |
787
|
|
|
->orderByAsc($posts->selectQuery()->expr('id')); |
788
|
|
|
}, |
789
|
|
|
new PaginationResult( |
790
|
|
|
[ |
791
|
|
|
new Entity([ |
792
|
|
|
'id' => 5, |
793
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
794
|
|
|
]), |
795
|
|
|
new Entity([ |
796
|
|
|
'id' => 2, |
797
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
798
|
|
|
]), |
799
|
|
|
new Entity([ |
800
|
|
|
'id' => 4, |
801
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
802
|
|
|
]), |
803
|
|
|
], |
804
|
|
|
[ |
805
|
|
|
'hasPrevious' => true, |
806
|
|
|
'previousCursor' => [ |
807
|
|
|
'id' => 3, |
808
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
809
|
|
|
], |
810
|
|
|
'hasNext' => null, |
811
|
|
|
'nextCursor' => null, |
812
|
|
|
] |
813
|
|
|
), |
814
|
|
|
]; |
815
|
|
|
|
816
|
|
|
yield 'Ascending backward start exclusive with QueryExpression' => [ |
817
|
|
|
function (Table $posts) { |
818
|
|
|
/** @var LampagerBehavior&Table $posts */ |
819
|
|
|
return $posts->lampager() |
820
|
|
|
->backward() |
821
|
|
|
->seekable() |
822
|
|
|
->exclusive() |
823
|
|
|
->limit(3) |
824
|
|
|
->orderByAsc($posts->selectQuery()->expr('modified')) |
825
|
|
|
->orderByAsc($posts->selectQuery()->expr('id')); |
826
|
|
|
}, |
827
|
|
|
new PaginationResult( |
828
|
|
|
[ |
829
|
|
|
new Entity([ |
830
|
|
|
'id' => 5, |
831
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
832
|
|
|
]), |
833
|
|
|
new Entity([ |
834
|
|
|
'id' => 2, |
835
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
836
|
|
|
]), |
837
|
|
|
new Entity([ |
838
|
|
|
'id' => 4, |
839
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
840
|
|
|
]), |
841
|
|
|
], |
842
|
|
|
[ |
843
|
|
|
'hasPrevious' => true, |
844
|
|
|
'previousCursor' => [ |
845
|
|
|
'id' => 5, |
846
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
847
|
|
|
], |
848
|
|
|
'hasNext' => null, |
849
|
|
|
'nextCursor' => null, |
850
|
|
|
] |
851
|
|
|
), |
852
|
|
|
]; |
853
|
|
|
|
854
|
|
|
yield 'Ascending backward inclusive with QueryExpression' => [ |
855
|
|
|
function (Table $posts) { |
856
|
|
|
/** @var LampagerBehavior&Table $posts */ |
857
|
|
|
return $posts->lampager() |
858
|
|
|
->backward() |
859
|
|
|
->seekable() |
860
|
|
|
->limit(3) |
861
|
|
|
->orderByAsc($posts->selectQuery()->expr('modified')) |
862
|
|
|
->orderByAsc($posts->selectQuery()->expr('id')) |
863
|
|
|
->cursor([ |
864
|
|
|
'id' => 3, |
865
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
866
|
|
|
]); |
867
|
|
|
}, |
868
|
|
|
new PaginationResult( |
869
|
|
|
[ |
870
|
|
|
new Entity([ |
871
|
|
|
'id' => 1, |
872
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
873
|
|
|
]), |
874
|
|
|
new Entity([ |
875
|
|
|
'id' => 3, |
876
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
877
|
|
|
]), |
878
|
|
|
], |
879
|
|
|
[ |
880
|
|
|
'hasPrevious' => false, |
881
|
|
|
'previousCursor' => null, |
882
|
|
|
'hasNext' => true, |
883
|
|
|
'nextCursor' => [ |
884
|
|
|
'id' => 5, |
885
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
886
|
|
|
], |
887
|
|
|
] |
888
|
|
|
), |
889
|
|
|
]; |
890
|
|
|
|
891
|
|
|
yield 'Ascending backward exclusive with QueryExpression' => [ |
892
|
|
|
function (Table $posts) { |
893
|
|
|
/** @var LampagerBehavior&Table $posts */ |
894
|
|
|
return $posts->lampager() |
895
|
|
|
->backward() |
896
|
|
|
->seekable() |
897
|
|
|
->exclusive() |
898
|
|
|
->limit(3) |
899
|
|
|
->orderByAsc($posts->selectQuery()->expr('modified')) |
900
|
|
|
->orderByAsc($posts->selectQuery()->expr('id')) |
901
|
|
|
->cursor([ |
902
|
|
|
'id' => 3, |
903
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
904
|
|
|
]); |
905
|
|
|
}, |
906
|
|
|
new PaginationResult( |
907
|
|
|
[ |
908
|
|
|
new Entity([ |
909
|
|
|
'id' => 1, |
910
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
911
|
|
|
]), |
912
|
|
|
], |
913
|
|
|
[ |
914
|
|
|
'hasPrevious' => false, |
915
|
|
|
'previousCursor' => null, |
916
|
|
|
'hasNext' => true, |
917
|
|
|
'nextCursor' => [ |
918
|
|
|
'id' => 1, |
919
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
920
|
|
|
], |
921
|
|
|
] |
922
|
|
|
), |
923
|
|
|
]; |
924
|
|
|
|
925
|
|
|
yield 'Descending forward start inclusive with QueryExpression' => [ |
926
|
|
|
function (Table $posts) { |
927
|
|
|
/** @var LampagerBehavior&Table $posts */ |
928
|
|
|
return $posts->lampager() |
929
|
|
|
->forward() |
930
|
|
|
->seekable() |
931
|
|
|
->limit(3) |
932
|
|
|
->orderByDesc($posts->selectQuery()->expr('modified')) |
933
|
|
|
->orderByDesc($posts->selectQuery()->expr('id')); |
934
|
|
|
}, |
935
|
|
|
new PaginationResult( |
936
|
|
|
[ |
937
|
|
|
new Entity([ |
938
|
|
|
'id' => 4, |
939
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
940
|
|
|
]), |
941
|
|
|
new Entity([ |
942
|
|
|
'id' => 2, |
943
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
944
|
|
|
]), |
945
|
|
|
new Entity([ |
946
|
|
|
'id' => 5, |
947
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
948
|
|
|
]), |
949
|
|
|
], |
950
|
|
|
[ |
951
|
|
|
'hasPrevious' => null, |
952
|
|
|
'previousCursor' => null, |
953
|
|
|
'hasNext' => true, |
954
|
|
|
'nextCursor' => [ |
955
|
|
|
'id' => 3, |
956
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
957
|
|
|
], |
958
|
|
|
] |
959
|
|
|
), |
960
|
|
|
]; |
961
|
|
|
|
962
|
|
|
yield 'Descending forward start exclusive with QueryExpression' => [ |
963
|
|
|
function (Table $posts) { |
964
|
|
|
/** @var LampagerBehavior&Table $posts */ |
965
|
|
|
return $posts->lampager() |
966
|
|
|
->forward() |
967
|
|
|
->seekable() |
968
|
|
|
->exclusive() |
969
|
|
|
->limit(3) |
970
|
|
|
->orderByDesc($posts->selectQuery()->expr('modified')) |
971
|
|
|
->orderByDesc($posts->selectQuery()->expr('id')); |
972
|
|
|
}, |
973
|
|
|
new PaginationResult( |
974
|
|
|
[ |
975
|
|
|
new Entity([ |
976
|
|
|
'id' => 4, |
977
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
978
|
|
|
]), |
979
|
|
|
new Entity([ |
980
|
|
|
'id' => 2, |
981
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
982
|
|
|
]), |
983
|
|
|
new Entity([ |
984
|
|
|
'id' => 5, |
985
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
986
|
|
|
]), |
987
|
|
|
], |
988
|
|
|
[ |
989
|
|
|
'hasPrevious' => null, |
990
|
|
|
'previousCursor' => null, |
991
|
|
|
'hasNext' => true, |
992
|
|
|
'nextCursor' => [ |
993
|
|
|
'id' => 5, |
994
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
995
|
|
|
], |
996
|
|
|
] |
997
|
|
|
), |
998
|
|
|
]; |
999
|
|
|
|
1000
|
|
|
yield 'Descending forward inclusive with QueryExpression' => [ |
1001
|
|
|
function (Table $posts) { |
1002
|
|
|
/** @var LampagerBehavior&Table $posts */ |
1003
|
|
|
return $posts->lampager() |
1004
|
|
|
->forward() |
1005
|
|
|
->seekable() |
1006
|
|
|
->limit(3) |
1007
|
|
|
->orderByDesc($posts->selectQuery()->expr('modified')) |
1008
|
|
|
->orderByDesc($posts->selectQuery()->expr('id')) |
1009
|
|
|
->cursor([ |
1010
|
|
|
'id' => 3, |
1011
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1012
|
|
|
]); |
1013
|
|
|
}, |
1014
|
|
|
new PaginationResult( |
1015
|
|
|
[ |
1016
|
|
|
new Entity([ |
1017
|
|
|
'id' => 3, |
1018
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1019
|
|
|
]), |
1020
|
|
|
new Entity([ |
1021
|
|
|
'id' => 1, |
1022
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1023
|
|
|
]), |
1024
|
|
|
], |
1025
|
|
|
[ |
1026
|
|
|
'hasPrevious' => true, |
1027
|
|
|
'previousCursor' => [ |
1028
|
|
|
'id' => 5, |
1029
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1030
|
|
|
], |
1031
|
|
|
'hasNext' => false, |
1032
|
|
|
'nextCursor' => null, |
1033
|
|
|
] |
1034
|
|
|
), |
1035
|
|
|
]; |
1036
|
|
|
|
1037
|
|
|
yield 'Descending forward exclusive with QueryExpression' => [ |
1038
|
|
|
function (Table $posts) { |
1039
|
|
|
/** @var LampagerBehavior&Table $posts */ |
1040
|
|
|
return $posts->lampager() |
1041
|
|
|
->forward() |
1042
|
|
|
->seekable() |
1043
|
|
|
->exclusive() |
1044
|
|
|
->limit(3) |
1045
|
|
|
->orderByDesc($posts->selectQuery()->expr('modified')) |
1046
|
|
|
->orderByDesc($posts->selectQuery()->expr('id')) |
1047
|
|
|
->cursor([ |
1048
|
|
|
'id' => 3, |
1049
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1050
|
|
|
]); |
1051
|
|
|
}, |
1052
|
|
|
new PaginationResult( |
1053
|
|
|
[ |
1054
|
|
|
new Entity([ |
1055
|
|
|
'id' => 1, |
1056
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1057
|
|
|
]), |
1058
|
|
|
], |
1059
|
|
|
[ |
1060
|
|
|
'hasPrevious' => true, |
1061
|
|
|
'previousCursor' => [ |
1062
|
|
|
'id' => 1, |
1063
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1064
|
|
|
], |
1065
|
|
|
'hasNext' => false, |
1066
|
|
|
'nextCursor' => null, |
1067
|
|
|
] |
1068
|
|
|
), |
1069
|
|
|
]; |
1070
|
|
|
|
1071
|
|
|
yield 'Descending backward start inclusive with QueryExpression' => [ |
1072
|
|
|
function (Table $posts) { |
1073
|
|
|
/** @var LampagerBehavior&Table $posts */ |
1074
|
|
|
return $posts->lampager() |
1075
|
|
|
->backward() |
1076
|
|
|
->seekable() |
1077
|
|
|
->limit(3) |
1078
|
|
|
->orderByDesc($posts->selectQuery()->expr('modified')) |
1079
|
|
|
->orderByDesc($posts->selectQuery()->expr('id')); |
1080
|
|
|
}, |
1081
|
|
|
new PaginationResult( |
1082
|
|
|
[ |
1083
|
|
|
new Entity([ |
1084
|
|
|
'id' => 5, |
1085
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1086
|
|
|
]), |
1087
|
|
|
new Entity([ |
1088
|
|
|
'id' => 3, |
1089
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1090
|
|
|
]), |
1091
|
|
|
new Entity([ |
1092
|
|
|
'id' => 1, |
1093
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1094
|
|
|
]), |
1095
|
|
|
], |
1096
|
|
|
[ |
1097
|
|
|
'hasPrevious' => true, |
1098
|
|
|
'previousCursor' => [ |
1099
|
|
|
'id' => 2, |
1100
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
1101
|
|
|
], |
1102
|
|
|
'hasNext' => null, |
1103
|
|
|
'nextCursor' => null, |
1104
|
|
|
] |
1105
|
|
|
), |
1106
|
|
|
]; |
1107
|
|
|
|
1108
|
|
|
yield 'Descending backward start exclusive with QueryExpression' => [ |
1109
|
|
|
function (Table $posts) { |
1110
|
|
|
/** @var LampagerBehavior&Table $posts */ |
1111
|
|
|
return $posts->lampager() |
1112
|
|
|
->backward() |
1113
|
|
|
->seekable() |
1114
|
|
|
->exclusive() |
1115
|
|
|
->limit(3) |
1116
|
|
|
->orderByDesc($posts->selectQuery()->expr('modified')) |
1117
|
|
|
->orderByDesc($posts->selectQuery()->expr('id')); |
1118
|
|
|
}, |
1119
|
|
|
new PaginationResult( |
1120
|
|
|
[ |
1121
|
|
|
new Entity([ |
1122
|
|
|
'id' => 5, |
1123
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1124
|
|
|
]), |
1125
|
|
|
new Entity([ |
1126
|
|
|
'id' => 3, |
1127
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1128
|
|
|
]), |
1129
|
|
|
new Entity([ |
1130
|
|
|
'id' => 1, |
1131
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1132
|
|
|
]), |
1133
|
|
|
], |
1134
|
|
|
[ |
1135
|
|
|
'hasPrevious' => true, |
1136
|
|
|
'previousCursor' => [ |
1137
|
|
|
'id' => 5, |
1138
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1139
|
|
|
], |
1140
|
|
|
'hasNext' => null, |
1141
|
|
|
'nextCursor' => null, |
1142
|
|
|
] |
1143
|
|
|
), |
1144
|
|
|
]; |
1145
|
|
|
|
1146
|
|
|
yield 'Descending backward inclusive with QueryExpression' => [ |
1147
|
|
|
function (Table $posts) { |
1148
|
|
|
/** @var LampagerBehavior&Table $posts */ |
1149
|
|
|
return $posts->lampager() |
1150
|
|
|
->backward() |
1151
|
|
|
->seekable() |
1152
|
|
|
->limit(3) |
1153
|
|
|
->orderByDesc($posts->selectQuery()->expr('modified')) |
1154
|
|
|
->orderByDesc($posts->selectQuery()->expr('id')) |
1155
|
|
|
->cursor([ |
1156
|
|
|
'id' => 3, |
1157
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1158
|
|
|
]); |
1159
|
|
|
}, |
1160
|
|
|
new PaginationResult( |
1161
|
|
|
[ |
1162
|
|
|
new Entity([ |
1163
|
|
|
'id' => 2, |
1164
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
1165
|
|
|
]), |
1166
|
|
|
new Entity([ |
1167
|
|
|
'id' => 5, |
1168
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1169
|
|
|
]), |
1170
|
|
|
new Entity([ |
1171
|
|
|
'id' => 3, |
1172
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1173
|
|
|
]), |
1174
|
|
|
], |
1175
|
|
|
[ |
1176
|
|
|
'hasPrevious' => true, |
1177
|
|
|
'previousCursor' => [ |
1178
|
|
|
'id' => 4, |
1179
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
1180
|
|
|
], |
1181
|
|
|
'hasNext' => true, |
1182
|
|
|
'nextCursor' => [ |
1183
|
|
|
'id' => 1, |
1184
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1185
|
|
|
], |
1186
|
|
|
] |
1187
|
|
|
), |
1188
|
|
|
]; |
1189
|
|
|
|
1190
|
|
|
yield 'Descending backward exclusive with QueryExpression' => [ |
1191
|
|
|
function (Table $posts) { |
1192
|
|
|
/** @var LampagerBehavior&Table $posts */ |
1193
|
|
|
return $posts->lampager() |
1194
|
|
|
->backward() |
1195
|
|
|
->seekable() |
1196
|
|
|
->exclusive() |
1197
|
|
|
->limit(3) |
1198
|
|
|
->orderByDesc($posts->selectQuery()->expr('modified')) |
1199
|
|
|
->orderByDesc($posts->selectQuery()->expr('id')) |
1200
|
|
|
->cursor([ |
1201
|
|
|
'id' => 3, |
1202
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1203
|
|
|
]); |
1204
|
|
|
}, |
1205
|
|
|
new PaginationResult( |
1206
|
|
|
[ |
1207
|
|
|
new Entity([ |
1208
|
|
|
'id' => 4, |
1209
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
1210
|
|
|
]), |
1211
|
|
|
new Entity([ |
1212
|
|
|
'id' => 2, |
1213
|
|
|
'modified' => new DateTime('2017-01-01 11:00:00'), |
1214
|
|
|
]), |
1215
|
|
|
new Entity([ |
1216
|
|
|
'id' => 5, |
1217
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1218
|
|
|
]), |
1219
|
|
|
], |
1220
|
|
|
[ |
1221
|
|
|
'hasPrevious' => false, |
1222
|
|
|
'previousCursor' => null, |
1223
|
|
|
'hasNext' => true, |
1224
|
|
|
'nextCursor' => [ |
1225
|
|
|
'id' => 5, |
1226
|
|
|
'modified' => new DateTime('2017-01-01 10:00:00'), |
1227
|
|
|
], |
1228
|
|
|
] |
1229
|
|
|
), |
1230
|
|
|
]; |
1231
|
|
|
} |
1232
|
|
|
} |
1233
|
|
|
|