Passed
Push — master ( 29c0d1...53e8a6 )
by Chito
01:38
created

PaginatorTest::testPaginateLampagerCakeQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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