@@ -3619,13 +3619,24 @@ public function testCursorPaginate()
36193619 $ columns = ['test ' ];
36203620 $ cursorName = 'cursor-name ' ;
36213621 $ cursor = new Cursor (['test ' => 'bar ' ]);
3622- $ builder = $ this ->getMockQueryBuilder ()->orderBy ('test ' );
3622+ $ builder = $ this ->getMockQueryBuilder ();
3623+ $ builder ->from ('foobar ' )->orderBy ('test ' );
3624+ $ builder ->shouldReceive ('newQuery ' )->andReturnUsing (function () use ($ builder ) {
3625+ return new Builder ($ builder ->connection , $ builder ->grammar , $ builder ->processor );
3626+ });
3627+
36233628 $ path = 'http://foo.bar?cursor= ' .$ cursor ->encode ();
36243629
36253630 $ results = collect ([['test ' => 'foo ' ], ['test ' => 'bar ' ]]);
36263631
3627- $ builder ->shouldReceive ('where ' )->with ('test ' , '> ' , 'bar ' )->once ()->andReturnSelf ();
3628- $ builder ->shouldReceive ('get ' )->once ()->andReturn ($ results );
3632+ $ builder ->shouldReceive ('get ' )->once ()->andReturnUsing (function () use ($ builder , $ results ) {
3633+ $ this ->assertEquals (
3634+ 'select * from "foobar" where ("test" > ?) order by "test" asc limit 17 ' ,
3635+ $ builder ->toSql ());
3636+ $ this ->assertEquals (['bar ' ], $ builder ->bindings ['where ' ]);
3637+
3638+ return $ results ;
3639+ });
36293640
36303641 Paginator::currentPathResolver (function () use ($ path ) {
36313642 return $ path ;
@@ -3646,13 +3657,25 @@ public function testCursorPaginateMultipleOrderColumns()
36463657 $ columns = ['test ' ];
36473658 $ cursorName = 'cursor-name ' ;
36483659 $ cursor = new Cursor (['test ' => 'bar ' , 'another ' => 'foo ' ]);
3649- $ builder = $ this ->getMockQueryBuilder ()->orderBy ('test ' )->orderBy ('another ' );
3660+ $ builder = $ this ->getMockQueryBuilder ();
3661+ $ builder ->from ('foobar ' )->orderBy ('test ' )->orderBy ('another ' );
3662+ $ builder ->shouldReceive ('newQuery ' )->andReturnUsing (function () use ($ builder ) {
3663+ return new Builder ($ builder ->connection , $ builder ->grammar , $ builder ->processor );
3664+ });
3665+
36503666 $ path = 'http://foo.bar?cursor= ' .$ cursor ->encode ();
36513667
36523668 $ results = collect ([['test ' => 'foo ' ], ['test ' => 'bar ' ]]);
36533669
3654- $ builder ->shouldReceive ('whereRowValues ' )->with (['test ' , 'another ' ], '> ' , ['bar ' , 'foo ' ])->once ()->andReturnSelf ();
3655- $ builder ->shouldReceive ('get ' )->once ()->andReturn ($ results );
3670+ $ builder ->shouldReceive ('get ' )->once ()->andReturnUsing (function () use ($ builder , $ results ) {
3671+ $ this ->assertEquals (
3672+ 'select * from "foobar" where ("test" > ? or ("test" = ? and ("another" > ?))) order by "test" asc, "another" asc limit 17 ' ,
3673+ $ builder ->toSql ()
3674+ );
3675+ $ this ->assertEquals (['bar ' , 'bar ' , 'foo ' ], $ builder ->bindings ['where ' ]);
3676+
3677+ return $ results ;
3678+ });
36563679
36573680 Paginator::currentPathResolver (function () use ($ path ) {
36583681 return $ path ;
@@ -3672,12 +3695,24 @@ public function testCursorPaginateWithDefaultArguments()
36723695 $ perPage = 15 ;
36733696 $ cursorName = 'cursor ' ;
36743697 $ cursor = new Cursor (['test ' => 'bar ' ]);
3675- $ builder = $ this ->getMockQueryBuilder ()->orderBy ('test ' );
3698+ $ builder = $ this ->getMockQueryBuilder ();
3699+ $ builder ->from ('foobar ' )->orderBy ('test ' );
3700+ $ builder ->shouldReceive ('newQuery ' )->andReturnUsing (function () use ($ builder ) {
3701+ return new Builder ($ builder ->connection , $ builder ->grammar , $ builder ->processor );
3702+ });
3703+
36763704 $ path = 'http://foo.bar?cursor= ' .$ cursor ->encode ();
36773705
36783706 $ results = collect ([['test ' => 'foo ' ], ['test ' => 'bar ' ]]);
36793707
3680- $ builder ->shouldReceive ('get ' )->once ()->andReturn ($ results );
3708+ $ builder ->shouldReceive ('get ' )->once ()->andReturnUsing (function () use ($ builder , $ results ) {
3709+ $ this ->assertEquals (
3710+ 'select * from "foobar" where ("test" > ?) order by "test" asc limit 16 ' ,
3711+ $ builder ->toSql ());
3712+ $ this ->assertEquals (['bar ' ], $ builder ->bindings ['where ' ]);
3713+
3714+ return $ results ;
3715+ });
36813716
36823717 CursorPaginator::currentCursorResolver (function () use ($ cursor ) {
36833718 return $ cursor ;
@@ -3730,12 +3765,24 @@ public function testCursorPaginateWithSpecificColumns()
37303765 $ columns = ['id ' , 'name ' ];
37313766 $ cursorName = 'cursor-name ' ;
37323767 $ cursor = new Cursor (['id ' => 2 ]);
3733- $ builder = $ this ->getMockQueryBuilder ()->orderBy ('id ' );
3768+ $ builder = $ this ->getMockQueryBuilder ();
3769+ $ builder ->from ('foobar ' )->orderBy ('id ' );
3770+ $ builder ->shouldReceive ('newQuery ' )->andReturnUsing (function () use ($ builder ) {
3771+ return new Builder ($ builder ->connection , $ builder ->grammar , $ builder ->processor );
3772+ });
3773+
37343774 $ path = 'http://foo.bar?cursor=3 ' ;
37353775
37363776 $ results = collect ([['id ' => 3 , 'name ' => 'Taylor ' ], ['id ' => 5 , 'name ' => 'Mohamed ' ]]);
37373777
3738- $ builder ->shouldReceive ('get ' )->once ()->andReturn ($ results );
3778+ $ builder ->shouldReceive ('get ' )->once ()->andReturnUsing (function () use ($ builder , $ results ) {
3779+ $ this ->assertEquals (
3780+ 'select * from "foobar" where ("id" > ?) order by "id" asc limit 17 ' ,
3781+ $ builder ->toSql ());
3782+ $ this ->assertEquals ([2 ], $ builder ->bindings ['where ' ]);
3783+
3784+ return $ results ;
3785+ });
37393786
37403787 Paginator::currentPathResolver (function () use ($ path ) {
37413788 return $ path ;
@@ -4142,7 +4189,7 @@ protected function getMySqlBuilderWithProcessor()
41424189 }
41434190
41444191 /**
4145- * @return m\MockInterface
4192+ * @return m\MockInterface|Builder
41464193 */
41474194 protected function getMockQueryBuilder ()
41484195 {
0 commit comments