@@ -68,8 +68,11 @@ public function testCreateDatabase()
6868 {
6969 $ output = $ this ->runFunctionSnippet ('pg_create_database ' );
7070 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+ );
7376
7477 $ this ->assertStringContainsString ($ expected , $ output );
7578 }
@@ -111,8 +114,12 @@ public function testCreateTableCaseSensitivity()
111114 self ::$ instanceId , self ::$ databaseId , $ tableName
112115 ]);
113116 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+ );
116123
117124 $ this ->assertStringContainsString ($ expected , $ output );
118125 }
@@ -181,8 +188,9 @@ public function testPartitionedDml()
181188 $ op ->pollUntilComplete ();
182189
183190 $ 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) ' ,
186194 [
187195 'parameters ' => [
188196 'p1 ' => 1 ,
@@ -192,7 +200,8 @@ public function testPartitionedDml()
192200 'p5 ' => 'Bruce ' ,
193201 'p6 ' => false ,
194202 ]
195- ]);
203+ ]
204+ );
196205 $ t ->commit ();
197206 });
198207
@@ -370,40 +379,71 @@ public function testDmlReturningInsert()
370379 {
371380 $ output = $ this ->runFunctionSnippet ('pg_insert_dml_returning ' );
372381
373- $ expectedOutput = sprintf ('Row (16, Melissa, Garcia) inserted ' );
382+ $ expectedOutput = sprintf ('Melissa Garcia inserted ' );
374383 $ this ->assertStringContainsString ($ expectedOutput , $ output );
375384
376- $ expectedOutput = sprintf ('Row (17, Russell, Morales) inserted ' );
377- $ this ->assertStringContainsString (' Russell ' , $ output );
385+ $ expectedOutput = sprintf ('Russell Morales inserted ' );
386+ $ this ->assertStringContainsString ($ expectedOutput , $ output );
378387
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 );
381393
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 );
384396 }
385397
386398 /**
387- * @depends testDmlReturningInsert
399+ * @depends testDmlWithParams
388400 */
389401 public function testDmlReturningUpdate ()
390402 {
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+
391413 $ output = $ this ->runFunctionSnippet ('pg_update_dml_returning ' );
392414
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 ' );
396419 $ this ->assertStringContainsString ($ expectedOutput , $ output );
397420 }
398421
399422 /**
400- * @depends testDmlReturningUpdate
423+ * @depends testDmlWithParams
401424 */
402425 public function testDmlReturningDelete ()
403426 {
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+
404441 $ output = $ this ->runFunctionSnippet ('pg_delete_dml_returning ' );
405442
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 ' );
407447 $ this ->assertStringContainsString ($ expectedOutput , $ output );
408448 }
409449
0 commit comments