@@ -48,7 +48,7 @@ public static function setUpBeforeClass()
48
48
public function testBigQueryClient ()
49
49
{
50
50
$ projectId = self ::$ projectId ;
51
- $ bigQuery = require __DIR__ . '/../snippets /bigquery_client.php ' ;
51
+ $ bigQuery = require __DIR__ . '/../src /bigquery_client.php ' ;
52
52
53
53
$ this ->assertInstanceOf (
54
54
\Google \Cloud \BigQuery \BigQueryClient::class,
@@ -78,8 +78,9 @@ public function testCopyTable()
78
78
$ destinationTableId ,
79
79
]);
80
80
81
+ $ destinationTable = self ::$ dataset ->table ($ destinationTableId );
81
82
$ this ->assertContains ('Table copied successfully ' , $ output );
82
- $ this ->verifyTempTable ( $ destinationTableId );
83
+ $ this ->verifyTable ( $ destinationTable , ' Brent Shaffer ' , 3 );
83
84
}
84
85
85
86
public function testCreateAndDeleteDataset ()
@@ -157,7 +158,7 @@ public function testGetTable()
157
158
$ projectId = self ::$ projectId ;
158
159
$ datasetId = self ::$ datasetId ;
159
160
$ tableId = $ this ->createTempEmptyTable ();
160
- $ table = require __DIR__ . '/../snippets /get_table.php ' ;
161
+ $ table = require __DIR__ . '/../src /get_table.php ' ;
161
162
162
163
$ this ->assertInstanceOf (
163
164
\Google \Cloud \BigQuery \Table::class,
@@ -179,8 +180,9 @@ public function testImportFromFile()
179
180
$ source ,
180
181
]);
181
182
183
+ $ tempTable = self ::$ dataset ->table ($ tempTableId );
182
184
$ this ->assertContains ('Data imported successfully ' , $ output );
183
- $ this ->verifyTempTable ( $ tempTableId );
185
+ $ this ->verifyTable ( $ tempTable , ' Brent Shaffer ' , 3 );
184
186
}
185
187
186
188
/**
@@ -199,7 +201,7 @@ public function testImportFromStorage($snippet, $runTruncateSnippet = false)
199
201
// verify table contents
200
202
$ table = self ::$ dataset ->table ($ tableId );
201
203
self ::$ tempTables [] = $ table ;
202
- $ this ->verifyStatesTable ($ table );
204
+ $ this ->verifyTable ($ table, ' Washington ' , 50 );
203
205
204
206
if ($ runTruncateSnippet ) {
205
207
$ truncateSnippet = sprintf ('%s_truncate ' , $ snippet );
@@ -208,7 +210,7 @@ public function testImportFromStorage($snippet, $runTruncateSnippet = false)
208
210
$ tableId ,
209
211
]);
210
212
$ this ->assertContains ('Data imported successfully ' , $ output );
211
- $ this ->verifyStatesTable ($ table );
213
+ $ this ->verifyTable ($ table, ' Washington ' , 50 );
212
214
}
213
215
}
214
216
@@ -244,8 +246,9 @@ public function testInsertSql()
244
246
$ tmpFile ,
245
247
]);
246
248
249
+ $ tempTable = self ::$ dataset ->table ($ tempTableId );
247
250
$ this ->assertContains ('Data imported successfully ' , $ output );
248
- $ this ->verifyTempTable ( $ tempTableId );
251
+ $ this ->verifyTable ( $ tempTable , ' Brent Shaffer ' , 3 );
249
252
}
250
253
251
254
public function testListDatasets ()
@@ -272,8 +275,9 @@ public function testStreamRow()
272
275
json_encode (['name ' => 'Brent Shaffer ' , 'title ' => 'Developer ' ])
273
276
]);
274
277
278
+ $ tempTable = self ::$ dataset ->table ($ tempTableId );
275
279
$ this ->assertcontains ('Data streamed into BigQuery successfully ' , $ output );
276
- $ this ->verifyTempTable ( $ tempTableId );
280
+ $ this ->verifyTable ( $ tempTable , ' Brent Shaffer ' , 1 );
277
281
}
278
282
279
283
public function testPaginateTable ()
@@ -315,7 +319,7 @@ private function runSnippet($sampleName, $params = [])
315
319
{
316
320
$ argv = array_merge ([0 , self ::$ projectId ], $ params );
317
321
ob_start ();
318
- require __DIR__ . "/../snippets / $ sampleName.php " ;
322
+ require __DIR__ . "/../src / $ sampleName.php " ;
319
323
return ob_get_clean ();
320
324
}
321
325
@@ -345,31 +349,23 @@ private function createTempTable()
345
349
return $ tempTableId ;
346
350
}
347
351
348
- private function verifyTempTable ( $ tempTableId )
352
+ private function verifyTable ( $ table , $ expectedValue , $ expectedRowCount )
349
353
{
350
- $ query = sprintf ('SELECT * FROM `%s.%s` ' , self ::$ datasetId , $ tempTableId );
351
- $ testFunction = function () use ($ query ) {
352
- $ output = $ this ->runSnippet ('run_query ' , [$ query ]);
353
- $ this ->assertContains ('Brent Shaffer ' , $ output );
354
- };
355
-
356
- $ this ->runEventuallyConsistentTest ($ testFunction );
357
- }
358
-
359
- private function verifyStatesTable ($ table )
360
- {
361
- $ numRows = 0 ;
362
- $ foundValue = false ;
363
- foreach ($ table ->rows ([]) as $ row ) {
364
- foreach ($ row as $ column => $ value ) {
365
- if ($ value == 'Washington ' ) {
366
- $ foundValue = true ;
354
+ $ testFunction = function () use ($ table , $ expectedValue , $ expectedRowCount ) {
355
+ $ numRows = 0 ;
356
+ $ foundValue = false ;
357
+ foreach ($ table ->rows ([]) as $ row ) {
358
+ foreach ($ row as $ column => $ value ) {
359
+ if ($ value == $ expectedValue ) {
360
+ $ foundValue = true ;
361
+ }
367
362
}
363
+ $ numRows ++;
368
364
}
369
- $ numRows ++ ;
370
- }
371
- $ this -> assertTrue ( $ foundValue ) ;
372
- $ this ->assertEquals ( $ numRows , 50 );
365
+ $ this -> assertTrue ( $ foundValue ) ;
366
+ $ this -> assertEquals ( $ numRows , $ expectedRowCount );
367
+ } ;
368
+ $ this ->runEventuallyConsistentTest ( $ testFunction );
373
369
}
374
370
375
371
public function tearDown ()
0 commit comments