diff --git a/storage/src/list_buckets_partial_success.php b/storage/src/list_buckets_partial_success.php new file mode 100644 index 000000000..f95dce4d1 --- /dev/null +++ b/storage/src/list_buckets_partial_success.php @@ -0,0 +1,55 @@ + true ]; + $buckets = $storage->buckets($options); + + // Check for unreachable locations first + // Note: unreachable() returns an array of strings for buckets in unavailable regions + if ($unreachable = $buckets->unreachable()) { + foreach ($unreachable as $location) { + printf('Unreachable Bucket: %s' . PHP_EOL, $location); + } + } + + // Iterate through the buckets that were successfully retrieved + foreach ($buckets as $bucket) { + printf('Bucket: %s' . PHP_EOL, $bucket->name()); + } +} +# [END storage_list_buckets_partial_success] + +// The following 2 lines are only needed to run the samples +require_once __DIR__ . '/../../testing/sample_helpers.php'; +\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); diff --git a/storage/test/storageTest.php b/storage/test/storageTest.php index 4ee45c9ce..c71e30e9c 100644 --- a/storage/test/storageTest.php +++ b/storage/test/storageTest.php @@ -147,6 +147,13 @@ public function testListBuckets() $this->assertStringContainsString('Bucket:', $output); } + public function testListBucketsPartialSuccess() + { + $output = $this->runFunctionSnippet('list_buckets_partial_success'); + $this->assertStringContainsString('Bucket:', $output); + $this->assertTrue(true); + } + public function testListSoftDeletedBuckets() { $output = $this->runFunctionSnippet('list_soft_deleted_buckets');