Skip to content

Commit f45424f

Browse files
author
Frank Natividad
committed
Fix tests
1 parent ecad177 commit f45424f

File tree

7 files changed

+30
-37
lines changed

7 files changed

+30
-37
lines changed

storage/src/activate_hmac_key.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function activate_hmac_key($accessId, $projectId)
4141

4242
$hmacKey->update('ACTIVE');
4343

44-
print("The HMAC key is now active.");
45-
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info()));
44+
print("The HMAC key is now active." . PHP_EOL);
45+
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info(), true));
4646
}
4747
# [END storage_activate_hmac_key]

storage/src/create_hmac_key.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function create_hmac_key($serviceAccountEmail, $projectId)
3939
// By default createHmacKey will use the projectId used by StorageClient().
4040
$hmacKeyCreated = $storage->createHmacKey($serviceAccountEmail, ['projectId' => $projectId]);
4141

42-
printf("The base64 encoded secret is: %s", $hmacKeyCreated->secret());
43-
print("Do not miss that secret, there is no API to recover it.");
44-
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKeyCreated->hmacKey()->info()));
42+
printf("The base64 encoded secret is: %s" . PHP_EOL, $hmacKeyCreated->secret());
43+
print("Do not miss that secret, there is no API to recover it." . PHP_EOL);
44+
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKeyCreated->hmacKey()->info(), true));
4545
}
4646
# [END storage_create_hmac_key]

storage/src/deactivate_hmac_key.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function deactivate_hmac_key($accessId, $projectId)
4141

4242
$hmacKey->update('INACTIVE');
4343

44-
print("The HMAC key is now inactive.");
45-
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info()));
44+
print("The HMAC key is now inactive." . PHP_EOL);
45+
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info(), true));
4646
}
4747
# [END storage_deactivate_hmac_key]

storage/src/delete_hmac_key.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ function delete_hmac_key($accessId, $projectId)
4040
$hmacKey = $storage->hmacKey($accessId, $projectId);
4141

4242
$hmacKey->delete();
43-
print("The key is deleted, though it may still appear in StorageClient.hmacKeys() results.");
43+
print("The key is deleted, though it may still appear in StorageClient.hmacKeys() results." . PHP_EOL);
4444
}
4545
# [END storage_get_hmac_key]

storage/src/get_hmac_key.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ function get_hmac_key($accessId, $projectId)
3838
$storage = new StorageClient();
3939
$hmacKey = $storage->hmacKey($accessId, $projectId);
4040

41-
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info()));
41+
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info(), true));
4242
}
4343
# [END storage_get_hmac_key]

storage/src/list_hmac_keys.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function list_hmac_keys($projectId)
3939
$hmacKeys = $storage->hmacKeys(['projectId' => $projectId]);
4040

4141
foreach ($hmacKeys as $hmacKey) {
42-
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info()));
42+
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info(), true));
4343
}
4444
}
4545
# [END storage_list_hmac_keys]

storage/test/HmacCommandTest.php

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public function setUp()
4949
// Create test key.
5050
$hmacKeyCreated = $this->storage->createHmacKey($this->hmacServiceAccount, ['projectId' => self::$projectId]);
5151
$this->accessId = $hmacKeyCreated->hmacKey()->accessId();
52+
$this->setOutputCallback(function () {
53+
// disable output
54+
});
5255
}
5356

5457
public function tearDown()
@@ -61,7 +64,9 @@ private function deleteAllHmacKeys($serviceAccountEmail)
6164
{
6265
$hmacKeys = $this->storage->hmacKeys(['serviceAccountEmail' => $serviceAccountEmail]);
6366
foreach ($hmacKeys as $hmacKey) {
64-
$hmacKey->update('INACTIVE');
67+
if ($hmacKey->info()['state'] == 'ACTIVE') {
68+
$hmacKey->update('INACTIVE');
69+
}
6570
$hmacKey->delete();
6671
}
6772
}
@@ -73,8 +78,7 @@ public function testHmacKeyList()
7378
'projectId' => self::$projectId
7479
],
7580
['interactive' => false]);
76-
$outputString = "/HMAC key Metadata:/";
77-
$this->expectOutputRegex($outputString);
81+
$this->assertContains("HMAC key Metadata:", $this->getActualOutput());
7882
}
7983

8084
/** @depends testHmacKeyList */
@@ -86,8 +90,7 @@ public function testHmacKeyCreate()
8690
'serviceAccountEmail' => $this->hmacServiceAccount
8791
],
8892
['interactive' => false]);
89-
$outputString = "/The base64 encoded secret is:/";
90-
$this->expectOutputRegex($outputString);
93+
$this->assertContains("The base64 encoded secret is:", $this->getActualOutput());
9194
}
9295

9396
/** @depends testHmacKeyCreate */
@@ -100,12 +103,11 @@ public function testHmacKeyGet()
100103
'--get' => true
101104
],
102105
['interactive' => false]);
103-
$outputString = "/HMAC key Metadata:/";
104-
$this->expectOutputRegex($outputString);
106+
$this->assertContains("HMAC key Metadata:", $this->getActualOutput());
105107
}
106108

107109
/** @depends testHmacKeyGet */
108-
public function testHmacKeyDeactivate()
110+
public function testHmacKeyDeactivateActivate()
109111
{
110112
$this->commandTesterManage->execute(
111113
[
@@ -114,25 +116,17 @@ public function testHmacKeyDeactivate()
114116
'--deactivate' => true
115117
],
116118
['interactive' => false]);
117-
$outputString = "/The HMAC key is now inactive./";
118-
$this->expectOutputRegex($outputString);
119-
}
120-
121-
/** @depends testHmacKeyDeactivate */
122-
public function testHmacKeyActivate()
123-
{
119+
$this->assertContains("The HMAC key is now inactive", $this->getActualOutput());
124120
$this->commandTesterManage->execute(
125-
[
126-
'projectId' => self::$projectId,
127-
'accessId' => $this->accessId,
128-
'--activate' => true
129-
],
130-
['interactive' => false]);
131-
$outputString = "/The HMAC key is now active./";
132-
$this->expectOutputRegex($outputString);
121+
[
122+
'projectId' => self::$projectId,
123+
'accessId' => $this->accessId,
124+
'--activate' => true
125+
],
126+
['interactive' => false]);
127+
$this->assertContains("The HMAC key is now active", $this->getActualOutput());
133128
}
134-
135-
/** @depends testHmacKeyActivate */
129+
/** @depends testHmacKeyDeactivateActivate */
136130
public function testHmacKeyDelete()
137131
{
138132
$this->commandTesterManage->execute(
@@ -149,7 +143,6 @@ public function testHmacKeyDelete()
149143
'--delete' => true
150144
],
151145
['interactive' => false]);
152-
$outputString = "/The key is deleted, though it may still appear in StorageClient.hmacKeys() results./";
153-
$this->expectOutputRegex($outputString);
146+
$this->assertContains("The key is deleted,", $this->getActualOutput());
154147
}
155148
}

0 commit comments

Comments
 (0)