Passed
Pull Request — master (#7)
by Chito
01:31
created

PaginatorTest::testSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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