22
33namespace Google \Cloud \Samples \Bigtable \Tests ;
44
5- use Google \Cloud \Bigtable \BigtableClient ;
6- use PHPUnit \Framework \TestCase ;
7-
8- use Google \Cloud \Bigtable \Admin \V2 \BigtableInstanceAdminClient ;
9- use Google \Cloud \Bigtable \Admin \V2 \BigtableTableAdminClient ;
10- use Google \Cloud \TestUtils \ExponentialBackoffTrait ;
11- use Google \Cloud \Bigtable \Admin \V2 \Table \View ;
12- use Google \Cloud \TestUtils \TestTrait ;
135use Google \ApiCore \ApiException ;
6+ use Google \Cloud \Bigtable \Admin \V2 \Table \View ;
7+ use PHPUnit \Framework \TestCase ;
148
159final class BigtableTest extends TestCase
1610{
17- use TestTrait, ExponentialBackoffTrait ;
11+ use BigtableTestTrait ;
1812
1913 const INSTANCE_ID_PREFIX = 'php-instance- ' ;
2014 const CLUSTER_ID_PREFIX = 'php-cluster- ' ;
2115 const TABLE_ID_PREFIX = 'php-table- ' ;
22- private static $ instanceAdminClient ;
23- private static $ tableAdminClient ;
24- private static $ bigtableClient ;
25- private static $ instanceId ;
16+
2617 private static $ clusterId ;
2718
2819 public static function setUpBeforeClass ()
2920 {
30- self ::checkProjectEnvVarBeforeClass ();
31- self ::$ instanceAdminClient = new BigtableInstanceAdminClient ();
32- self ::$ tableAdminClient = new BigtableTableAdminClient ();
33- self ::$ bigtableClient = new BigtableClient ([
34- 'projectId ' => self ::$ projectId ,
35- ]);
36-
37- self ::$ instanceId = uniqid (self ::INSTANCE_ID_PREFIX );
38- self ::$ clusterId = uniqid (self ::CLUSTER_ID_PREFIX );
39-
40- self ::create_production_instance (self ::$ projectId , self ::$ instanceId , self ::$ clusterId );
21+ self ::setUpBigtableVars ();
4122 }
4223
4324 public function setUp ()
4425 {
4526 $ this ->useResourceExhaustedBackoff ();
4627 }
4728
29+ public function testCreateProductionInstance ()
30+ {
31+ self ::$ instanceId = uniqid (self ::INSTANCE_ID_PREFIX );
32+ self ::$ clusterId = uniqid (self ::CLUSTER_ID_PREFIX );
33+
34+ $ content = self ::runSnippet ('create_production_instance ' , [
35+ self ::$ projectId ,
36+ self ::$ instanceId ,
37+ self ::$ clusterId
38+ ]);
39+
40+ $ instanceName = self ::$ instanceAdminClient ->instanceName (
41+ self ::$ projectId ,
42+ self ::$ instanceId
43+ );
44+
45+ $ this ->checkInstance ($ instanceName );
46+ }
47+
48+ /**
49+ * @depends testCreateProductionInstance
50+ */
4851 public function testCreateAndDeleteCluster ()
4952 {
53+ // Create a new cluster as last cluster in an instance cannot be deleted
5054 $ clusterId = uniqid (self ::CLUSTER_ID_PREFIX );
5155
5256 $ content = self ::runSnippet ('create_cluster ' , [
@@ -57,7 +61,11 @@ public function testCreateAndDeleteCluster()
5761 ]);
5862 $ array = explode (PHP_EOL , $ content );
5963
60- $ clusterName = self ::$ instanceAdminClient ->clusterName (self ::$ projectId , self ::$ instanceId , $ clusterId );
64+ $ clusterName = self ::$ instanceAdminClient ->clusterName (
65+ self ::$ projectId ,
66+ self ::$ instanceId ,
67+ $ clusterId
68+ );
6169
6270 $ this ->checkCluster ($ clusterName );
6371
@@ -95,23 +103,9 @@ public function testCreateDevInstance()
95103 $ this ->cleanInstance (self ::$ projectId , $ instanceId );
96104 }
97105
98- public function testCreateProductionInstance ()
99- {
100- $ instanceId = uniqid (self ::INSTANCE_ID_PREFIX );
101- $ clusterId = uniqid (self ::CLUSTER_ID_PREFIX );
102-
103- $ content = self ::runSnippet ('create_production_instance ' , [
104- self ::$ projectId ,
105- $ instanceId ,
106- $ clusterId
107- ]);
108-
109- $ instanceName = self ::$ instanceAdminClient ->instanceName (self ::$ projectId , $ instanceId );
110-
111- $ this ->checkInstance ($ instanceName );
112- $ this ->cleanInstance (self ::$ projectId , $ instanceId );
113- }
114-
106+ /**
107+ * @depends testCreateProductionInstance
108+ */
115109 public function testListInstances ()
116110 {
117111 $ content = self ::runSnippet ('list_instance ' , [
@@ -125,6 +119,9 @@ public function testListInstances()
125119 $ this ->assertContains (self ::$ instanceId , $ array );
126120 }
127121
122+ /**
123+ * @depends testCreateProductionInstance
124+ */
128125 public function testListTable ()
129126 {
130127 $ tableId = uniqid (self ::TABLE_ID_PREFIX );
@@ -141,6 +138,9 @@ public function testListTable()
141138 $ this ->assertContains ('projects/ ' . self ::$ projectId . '/instances/ ' . self ::$ instanceId . '/tables/ ' . $ tableId , $ array );
142139 }
143140
141+ /**
142+ * @depends testCreateProductionInstance
143+ */
144144 public function testListColumnFamilies ()
145145 {
146146 $ tableId = uniqid (self ::TABLE_ID_PREFIX );
@@ -166,6 +166,9 @@ public function testListColumnFamilies()
166166 $ this ->assertContains ('{"gcRule":{"union":{"rules":[{"maxNumVersions":2},{"maxAge":"432000s"}]}}} ' , $ array );
167167 }
168168
169+ /**
170+ * @depends testCreateProductionInstance
171+ */
169172 public function testListInstanceClusters ()
170173 {
171174 $ content = self ::runSnippet ('list_instance_clusters ' , [
@@ -179,7 +182,10 @@ public function testListInstanceClusters()
179182 $ this ->assertContains ('projects/ ' . self ::$ projectId . '/instances/ ' . self ::$ instanceId . '/clusters/ ' . self ::$ clusterId , $ array );
180183 }
181184
182- public function testcreate_table ()
185+ /**
186+ * @depends testCreateProductionInstance
187+ */
188+ public function testCreateTable ()
183189 {
184190 $ tableId = uniqid (self ::TABLE_ID_PREFIX );
185191
@@ -194,6 +200,9 @@ public function testcreate_table()
194200 $ this ->checkTable ($ tableName );
195201 }
196202
203+ /**
204+ * @depends testCreateProductionInstance
205+ */
197206 public function testCreateFamilyGcUnion ()
198207 {
199208 $ tableId = uniqid (self ::TABLE_ID_PREFIX );
@@ -226,6 +235,9 @@ public function testCreateFamilyGcUnion()
226235 $ this ->checkRule ($ tableName , 'cf3 ' , $ gcRuleCompare );
227236 }
228237
238+ /**
239+ * @depends testCreateProductionInstance
240+ */
229241 public function testCreateFamilyGcNested ()
230242 {
231243 $ tableId = uniqid (self ::TABLE_ID_PREFIX );
@@ -267,6 +279,9 @@ public function testCreateFamilyGcNested()
267279 $ this ->checkRule ($ tableName , 'cf5 ' , $ gcRuleCompare );
268280 }
269281
282+ /**
283+ * @depends testCreateProductionInstance
284+ */
270285 public function testCreateFamilyGcMaxVersions ()
271286 {
272287 $ tableId = uniqid (self ::TABLE_ID_PREFIX );
@@ -290,6 +305,9 @@ public function testCreateFamilyGcMaxVersions()
290305 $ this ->checkRule ($ tableName , 'cf2 ' , $ gcRuleCompare );
291306 }
292307
308+ /**
309+ * @depends testCreateProductionInstance
310+ */
293311 public function testCreateFamilyGcMaxAge ()
294312 {
295313 $ tableId = uniqid (self ::TABLE_ID_PREFIX );
@@ -313,6 +331,9 @@ public function testCreateFamilyGcMaxAge()
313331 $ this ->checkRule ($ tableName , 'cf1 ' , $ gcRuleCompare );
314332 }
315333
334+ /**
335+ * @depends testCreateProductionInstance
336+ */
316337 public function testCreateFamilyGcIntersection ()
317338 {
318339 $ tableId = uniqid (self ::TABLE_ID_PREFIX );
@@ -345,6 +366,9 @@ public function testCreateFamilyGcIntersection()
345366 $ this ->checkRule ($ tableName , 'cf4 ' , $ gcRuleCompare );
346367 }
347368
369+ /**
370+ * @depends testCreateProductionInstance
371+ */
348372 public function testDeleteTable ()
349373 {
350374 $ tableId = uniqid (self ::TABLE_ID_PREFIX );
@@ -369,6 +393,9 @@ public function testDeleteTable()
369393 }
370394 }
371395
396+ /**
397+ * @depends testCreateProductionInstance
398+ */
372399 public function testHelloWorld ()
373400 {
374401 $ this ->requireGrpc ();
@@ -395,15 +422,9 @@ public function testHelloWorld()
395422 $ this ->assertContains (sprintf ('Deleted %s table. ' , $ tableId ), $ array );
396423 }
397424
398- private static function create_production_instance ($ projectId , $ instanceId , $ clusterId )
399- {
400- $ content = self ::runSnippet ('create_production_instance ' , [
401- $ projectId ,
402- $ instanceId ,
403- $ clusterId
404- ]);
405- }
406-
425+ /**
426+ * @depends testCreateProductionInstance
427+ */
407428 public function testDeleteInstance ()
408429 {
409430 $ instanceName = self ::$ instanceAdminClient ->instanceName (self ::$ projectId , self ::$ instanceId );
0 commit comments