Skip to content

Commit 18fe8bc

Browse files
committed
Fix not found in array errors for tests
1 parent d2fb8bf commit 18fe8bc

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

storage/src/get_retention_policy.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ function get_retention_policy($bucketName)
3939

4040
printf('Retention Policy for ' . $bucketName . PHP_EOL);
4141
printf('Retention Period: ' . $bucket->info()['retentionPolicy']['retentionPeriod'] . PHP_EOL);
42-
if ($bucket->info()['retentionPolicy']['isLocked']) {
42+
if (array_key_exists('isLocked', $bucket->info()['retentionPolicy']) &&
43+
$bucket->info()['retentionPolicy']['isLocked']) {
4344
printf('Retention Policy is locked' . PHP_EOL);
4445
}
4546
if ($bucket->info()['retentionPolicy']['effectiveTime']) {
46-
printf('Effective Time: ' . $bucket->info()['retentionPolicy']['effectiveTime'] . PHP_EOL);
47+
printf('Effective Time: ' . $bucket->info()['retentionPolicy']['effectiveTime'] . PHP_EOL);
4748
}
4849
}
4950
# [END storage_get_retention_policy]

storage/src/remove_retention_policy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ function remove_retention_policy($bucketName)
3737
$bucket = $storage->bucket($bucketName);
3838
$bucket->reload();
3939

40-
if ($bucket->info()['retentionPolicy']['isLocked']) {
40+
if (array_key_exists('isLocked', $bucket->info()['retentionPolicy']) &&
41+
$bucket->info()['retentionPolicy']['isLocked']) {
4142
printf('Unable to remove retention period as retention policy is locked.' . PHP_EOL);
4243
return;
4344
}

storage/test/BucketLockCommandTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public function testRetentionPolicyNoLock()
8282
$this->bucket->reload();
8383
$effectiveTime = $this->bucket->info()['retentionPolicy']['effectiveTime'];
8484

85-
$this->assertNull($this->bucket->info()['retentionPolicy']['isLocked']);
85+
$this->assertFalse(array_key_exists('isLocked',
86+
$this->bucket->info()['retentionPolicy']));
8687
$this->assertNotNull($effectiveTime);
8788
$this->assertEquals($this->bucket->info()['retentionPolicy']['retentionPeriod'], $retentionPeriod);
8889

@@ -106,7 +107,7 @@ public function testRetentionPolicyNoLock()
106107
);
107108
$this->bucket->reload();
108109

109-
$this->assertNull($this->bucket->info()['retentionPolicy']);
110+
$this->assertFalse(array_key_exists('retentionPolicy', $this->bucket->info()));
110111

111112
$outputString = <<<EOF
112113
Bucket {$this->bucket->name()} retention period set for $retentionPeriod seconds
@@ -133,7 +134,8 @@ public function testRetentionPolicyLock()
133134
);
134135
$this->bucket->reload();
135136

136-
$this->assertNull($this->bucket->info()['retentionPolicy']['isLocked']);
137+
$this->assertFalse(array_key_exists('isLocked',
138+
$this->bucket->info()['retentionPolicy']));
137139

138140
$this->commandTester->execute(
139141
[
@@ -221,7 +223,8 @@ public function testEnableDisableGetDefaultEventBasedHold()
221223
public function testEnableDisableEventBasedHold()
222224
{
223225
$this->uploadObject();
224-
$this->assertNull($this->object->info()['eventBasedHold']);
226+
227+
$this->assertFalse(array_key_exists('eventBasedHold', $this->object->info()));
225228

226229
$this->commandTester->execute(
227230
[
@@ -256,7 +259,7 @@ public function testEnableDisableEventBasedHold()
256259
public function testEnableDisableTemporaryHold()
257260
{
258261
$this->uploadObject();
259-
$this->assertNull($this->object->info()['temporaryHold']);
262+
$this->assertFalse(array_key_exists('temporaryHold', $this->object->info()));
260263

261264
$this->commandTester->execute(
262265
[

0 commit comments

Comments
 (0)