@@ -182,6 +182,56 @@ public function testRunQueryStateless()
182182 $ this ->assertTrue ($ queryResults ->isComplete ());
183183 }
184184
185+ public function testRunQueryStatelessWithPagination ()
186+ {
187+ $ client = $ this ->getClient ();
188+ $ query = $ client ->query (self ::QUERY_STRING );
189+
190+ $ this ->connection ->query (Argument::allOf (
191+ Argument::withEntry ('projectId ' , self ::PROJECT_ID ),
192+ Argument::withEntry ('query ' , self ::QUERY_STRING ),
193+ Argument::withEntry ('jobCreationMode ' , 'JOB_CREATION_OPTIONAL ' )
194+ ))
195+ ->willReturn ([
196+ 'jobComplete ' => true ,
197+ 'jobReference ' => [
198+ 'jobId ' => self ::JOB_ID ,
199+ 'projectId ' => self ::PROJECT_ID
200+ ],
201+ 'schema ' => [
202+ 'fields ' => [
203+ ['name ' => 'col1 ' , 'type ' => 'STRING ' ]
204+ ]
205+ ],
206+ 'rows ' => [
207+ ['f ' => [['v ' => 'val1 ' ]]]
208+ ],
209+ 'pageToken ' => 'next-page-token '
210+ ])
211+ ->shouldBeCalledTimes (1 );
212+
213+ $ this ->connection ->getQueryResults (Argument::allOf (
214+ Argument::withEntry ('projectId ' , self ::PROJECT_ID ),
215+ Argument::withEntry ('jobId ' , self ::JOB_ID ),
216+ Argument::withEntry ('pageToken ' , 'next-page-token ' )
217+ ))
218+ ->willReturn ([
219+ 'jobComplete ' => true ,
220+ 'rows ' => [
221+ ['f ' => [['v ' => 'val2 ' ]]]
222+ ]
223+ ])
224+ ->shouldBeCalledTimes (1 );
225+
226+ $ client ->___setProperty ('connection ' , $ this ->connection ->reveal ());
227+ $ results = $ client ->runQuery ($ query );
228+ $ rows = iterator_to_array ($ results );
229+
230+ $ this ->assertCount (2 , $ rows );
231+ $ this ->assertEquals ('val1 ' , $ rows [0 ]['col1 ' ]);
232+ $ this ->assertEquals ('val2 ' , $ rows [1 ]['col1 ' ]);
233+ }
234+
185235 public function testRunQueryJobQueryEndpointReturnsAJob ()
186236 {
187237 $ client = $ this ->getClient ();
0 commit comments