Completed
Pull Request — master (#5)
by Chito
04:03
created

PaginatorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 1319
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 845
c 1
b 0
f 0
dl 0
loc 1319
rs 9.755

3 Methods

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