1717
1818namespace Google \Cloud \Samples \Spanner ;
1919
20+ use Google \Cloud \Spanner \InstanceConfiguration ;
2021use Google \Cloud \Spanner \SpannerClient ;
2122use Google \Cloud \Spanner \Instance ;
2223use Google \Cloud \TestUtils \EventuallyConsistentTestTrait ;
@@ -85,6 +86,15 @@ class spannerTest extends TestCase
8586 /** @var $lastUpdateData int */
8687 protected static $ lastUpdateDataTimestamp ;
8788
89+ /** @var string $baseConfigId */
90+ protected static $ baseConfigId ;
91+
92+ /** @var string $customInstanceConfigId */
93+ protected static $ customInstanceConfigId ;
94+
95+ /** @var InstanceConfiguration $customInstanceConfig */
96+ protected static $ customInstanceConfig ;
97+
8898 public static function setUpBeforeClass (): void
8999 {
90100 self ::checkProjectEnvVars ();
@@ -113,6 +123,9 @@ public static function setUpBeforeClass(): void
113123 self ::$ defaultLeader = 'us-central1 ' ;
114124 self ::$ updatedDefaultLeader = 'us-east4 ' ;
115125 self ::$ multiInstance = $ spanner ->instance (self ::$ multiInstanceId );
126+ self ::$ baseConfigId = 'nam7 ' ;
127+ self ::$ customInstanceConfigId = 'custom- ' . time () . rand ();
128+ self ::$ customInstanceConfig = $ spanner ->instanceConfiguration (self ::$ customInstanceConfigId );
116129 }
117130
118131 public function testCreateInstance ()
@@ -133,6 +146,64 @@ public function testCreateInstanceWithProcessingUnits()
133146 $ this ->assertStringContainsString ('Created instance test- ' , $ output );
134147 }
135148
149+ public function testCreateInstanceConfig ()
150+ {
151+ $ output = $ this ->runFunctionSnippet ('create_instance_config ' , [
152+ self ::$ customInstanceConfigId , self ::$ baseConfigId
153+ ]);
154+
155+ $ this ->assertStringContainsString (sprintf ('Created instance configuration %s ' , self ::$ customInstanceConfigId ), $ output );
156+ }
157+
158+ /**
159+ * @depends testCreateInstanceConfig
160+ */
161+ public function testUpdateInstanceConfig ()
162+ {
163+ $ output = $ this ->runFunctionSnippet ('update_instance_config ' , [
164+ self ::$ customInstanceConfigId
165+ ]);
166+
167+ $ this ->assertStringContainsString (sprintf ('Updated instance configuration %s ' , self ::$ customInstanceConfigId ), $ output );
168+ }
169+
170+ /**
171+ * @depends testUpdateInstanceConfig
172+ */
173+ public function testDeleteInstanceConfig ()
174+ {
175+ $ output = $ this ->runFunctionSnippet ('delete_instance_config ' , [
176+ self ::$ customInstanceConfigId
177+ ]);
178+ $ this ->assertStringContainsString (sprintf ('Deleted instance configuration %s ' , self ::$ customInstanceConfigId ), $ output );
179+ }
180+
181+ /**
182+ * @depends testUpdateInstanceConfig
183+ */
184+ public function testListInstanceConfigOperations ()
185+ {
186+ $ output = $ this ->runFunctionSnippet ('list_instance_config_operations ' , [
187+ self ::$ customInstanceConfigId
188+ ]);
189+
190+ $ this ->assertStringContainsString (
191+ sprintf (
192+ 'Instance config operation for %s of type %s has status done. ' ,
193+ self ::$ customInstanceConfigId ,
194+ 'type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceConfigMetadata '
195+ ),
196+ $ output );
197+
198+ $ this ->assertStringContainsString (
199+ sprintf (
200+ 'Instance config operation for %s of type %s has status done. ' ,
201+ self ::$ customInstanceConfigId ,
202+ 'type.googleapis.com/google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata '
203+ ),
204+ $ output );
205+ }
206+
136207 /**
137208 * @depends testCreateInstance
138209 */
@@ -902,5 +973,8 @@ public static function tearDownAfterClass(): void
902973 $ database ->drop ();
903974 self ::$ instance ->delete ();
904975 self ::$ lowCostInstance ->delete ();
976+ if (self ::$ customInstanceConfig ->exists ()) {
977+ self ::$ customInstanceConfig ->delete ();
978+ }
905979 }
906980}
0 commit comments