@@ -194,9 +194,20 @@ public function testReadObjectsWithPublicProperties(): void
194194 $ this ->assertTrue ($ paginator ->isOnFirstPage ());
195195 }
196196
197- public function testReadObjectsWithGetters (): void
197+ public function readObjectsWithGettersDataProvider (): array
198198 {
199- $ sort = Sort::only (['id ' , 'name ' ])->withOrderString ('id ' );
199+ return [
200+ 'order by id field ' => ['id ' , 'getId ' ],
201+ 'order by created_at field ' => ['created_at ' , 'getCreatedAt ' ],
202+ ];
203+ }
204+
205+ /**
206+ * @dataProvider readObjectsWithGettersDataProvider
207+ */
208+ public function testReadObjectsWithGetters (string $ orderByField , string $ getter ): void
209+ {
210+ $ sort = Sort::only (['id ' , 'name ' , 'created_at ' ])->withOrderString ($ orderByField );
200211 $ data = [
201212 $ this ->createObjectWithGetters (1 , 'Codename Boris 1 ' ),
202213 $ this ->createObjectWithGetters (2 , 'Codename Boris 2 ' ),
@@ -207,7 +218,7 @@ public function testReadObjectsWithGetters(): void
207218 $ paginator = (new KeysetPaginator ($ dataReader ))->withPageSize (2 );
208219
209220 $ this ->assertSame ([$ data [0 ], $ data [1 ]], $ this ->iterableToArray ($ paginator ->read ()));
210- $ this ->assertSame ((string ) $ data [1 ]->getId (), $ paginator ->getNextPageToken ());
221+ $ this ->assertSame ((string ) $ data [1 ]->$ getter (), $ paginator ->getNextPageToken ());
211222 $ this ->assertTrue ($ paginator ->isOnFirstPage ());
212223 }
213224
@@ -573,11 +584,13 @@ private function createObjectWithGetters(int $id, string $name): object
573584 return new class ($ id , $ name ) {
574585 private int $ id ;
575586 private string $ name ;
587+ private int $ createdAt ;
576588
577- public function __construct (int $ id , string $ name )
589+ public function __construct (int $ id , string $ name, int $ createdAt = null )
578590 {
579591 $ this ->id = $ id ;
580592 $ this ->name = $ name ;
593+ $ this ->createdAt = $ createdAt ?: time ();
581594 }
582595
583596 public function getId (): string
@@ -589,6 +602,11 @@ public function getName(): string
589602 {
590603 return $ this ->name ;
591604 }
605+
606+ public function getCreatedAt (): int
607+ {
608+ return $ this ->createdAt ;
609+ }
592610 };
593611 }
594612
0 commit comments