Passed
Push — master ( 383493...d29574 )
by Chito
02:01
created

PaginatorTest::valueProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 643
Code Lines 418

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 418
c 1
b 0
f 0
dl 0
loc 643
rs 8
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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