@@ -68,8 +68,11 @@ public function testCreateDatabase()
68
68
{
69
69
$ output = $ this ->runFunctionSnippet ('pg_create_database ' );
70
70
self ::$ lastUpdateDataTimestamp = time ();
71
- $ expected = sprintf ('Created database %s with dialect POSTGRESQL on instance %s ' ,
72
- self ::$ databaseId , self ::$ instanceId );
71
+ $ expected = sprintf (
72
+ 'Created database %s with dialect POSTGRESQL on instance %s ' ,
73
+ self ::$ databaseId ,
74
+ self ::$ instanceId
75
+ );
73
76
74
77
$ this ->assertStringContainsString ($ expected , $ output );
75
78
}
@@ -111,8 +114,12 @@ public function testCreateTableCaseSensitivity()
111
114
self ::$ instanceId , self ::$ databaseId , $ tableName
112
115
]);
113
116
self ::$ lastUpdateDataTimestamp = time ();
114
- $ expected = sprintf ('Created %s table in database %s on instance %s ' ,
115
- $ tableName , self ::$ databaseId , self ::$ instanceId );
117
+ $ expected = sprintf (
118
+ 'Created %s table in database %s on instance %s ' ,
119
+ $ tableName ,
120
+ self ::$ databaseId ,
121
+ self ::$ instanceId
122
+ );
116
123
117
124
$ this ->assertStringContainsString ($ expected , $ output );
118
125
}
@@ -181,8 +188,9 @@ public function testPartitionedDml()
181
188
$ op ->pollUntilComplete ();
182
189
183
190
$ db ->runTransaction (function (Transaction $ t ) {
184
- $ t ->executeUpdate ('INSERT INTO users (id, name, active) '
185
- . ' VALUES ($1, $2, $3), ($4, $5, $6) ' ,
191
+ $ t ->executeUpdate (
192
+ 'INSERT INTO users (id, name, active) '
193
+ . ' VALUES ($1, $2, $3), ($4, $5, $6) ' ,
186
194
[
187
195
'parameters ' => [
188
196
'p1 ' => 1 ,
@@ -192,7 +200,8 @@ public function testPartitionedDml()
192
200
'p5 ' => 'Bruce ' ,
193
201
'p6 ' => false ,
194
202
]
195
- ]);
203
+ ]
204
+ );
196
205
$ t ->commit ();
197
206
});
198
207
@@ -370,40 +379,71 @@ public function testDmlReturningInsert()
370
379
{
371
380
$ output = $ this ->runFunctionSnippet ('pg_insert_dml_returning ' );
372
381
373
- $ expectedOutput = sprintf ('Row (16, Melissa, Garcia) inserted ' );
382
+ $ expectedOutput = sprintf ('Melissa Garcia inserted ' );
374
383
$ this ->assertStringContainsString ($ expectedOutput , $ output );
375
384
376
- $ expectedOutput = sprintf ('Row (17, Russell, Morales) inserted ' );
377
- $ this ->assertStringContainsString (' Russell ' , $ output );
385
+ $ expectedOutput = sprintf ('Russell Morales inserted ' );
386
+ $ this ->assertStringContainsString ($ expectedOutput , $ output );
378
387
379
- $ expectedOutput = sprintf ('Row (18, Jacqueline, Long) inserted ' );
380
- $ this ->assertStringContainsString ('Jacqueline ' , $ output );
388
+ $ expectedOutput = sprintf ('Jacqueline Long inserted ' );
389
+ $ this ->assertStringContainsString ($ expectedOutput , $ output );
390
+
391
+ $ expectedOutput = sprintf ('Dylan Shaw inserted ' );
392
+ $ this ->assertStringContainsString ($ expectedOutput , $ output );
381
393
382
- $ expectedOutput = sprintf ('Row (19, Dylan, Shaw) inserted ' );
383
- $ this ->assertStringContainsString (' Dylan ' , $ output );
394
+ $ expectedOutput = sprintf ('Inserted row(s) count: 4 ' );
395
+ $ this ->assertStringContainsString ($ expectedOutput , $ output );
384
396
}
385
397
386
398
/**
387
- * @depends testDmlReturningInsert
399
+ * @depends testDmlWithParams
388
400
*/
389
401
public function testDmlReturningUpdate ()
390
402
{
403
+ $ db = self ::$ instance ->database (self ::$ databaseId );
404
+ $ db ->runTransaction (function (Transaction $ t ) {
405
+ $ t ->update ('Albums ' , [
406
+ 'albumid ' => 1 ,
407
+ 'singerid ' => 1 ,
408
+ 'marketingbudget ' => 1000
409
+ ]);
410
+ $ t ->commit ();
411
+ });
412
+
391
413
$ output = $ this ->runFunctionSnippet ('pg_update_dml_returning ' );
392
414
393
- $ expectedOutput = sprintf (
394
- 'Row with singerid 16 updated to (16, Melissa, Missing) '
395
- );
415
+ $ expectedOutput = sprintf ('MarketingBudget: 2000 ' );
416
+ $ this ->assertStringContainsString ($ expectedOutput , $ output );
417
+
418
+ $ expectedOutput = sprintf ('Updated row(s) count: 1 ' );
396
419
$ this ->assertStringContainsString ($ expectedOutput , $ output );
397
420
}
398
421
399
422
/**
400
- * @depends testDmlReturningUpdate
423
+ * @depends testDmlWithParams
401
424
*/
402
425
public function testDmlReturningDelete ()
403
426
{
427
+ $ db = self ::$ instance ->database (self ::$ databaseId );
428
+
429
+ // Deleting the foreign key dependent entry in the Albums table
430
+ // before deleting the required row(row which has firstName = Alice)
431
+ // in the sample.
432
+ $ db ->runTransaction (function (Transaction $ t ) {
433
+ $ spanner = new SpannerClient (['projectId ' => self ::$ projectId ]);
434
+ $ keySet = $ spanner ->keySet ([
435
+ 'keys ' => [[1 , 1 ]]
436
+ ]);
437
+ $ t ->delete ('Albums ' , $ keySet );
438
+ $ t ->commit ();
439
+ });
440
+
404
441
$ output = $ this ->runFunctionSnippet ('pg_delete_dml_returning ' );
405
442
406
- $ expectedOutput = sprintf ('Row (16, Melissa, Missing) deleted ' );
443
+ $ expectedOutput = sprintf ('1 Alice Henderson ' );
444
+ $ this ->assertStringContainsString ($ expectedOutput , $ output );
445
+
446
+ $ expectedOutput = sprintf ('Deleted row(s) count: 1 ' );
407
447
$ this ->assertStringContainsString ($ expectedOutput , $ output );
408
448
}
409
449
0 commit comments