Created
March 14, 2024 12:25
-
-
Save vishwarajanand/a895a5610fefb11c761373882f7fa6a9 to your computer and use it in GitHub Desktop.
Test Script for implementing touch in google cloud storage php library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
// https://github.com/googleapis/google-cloud-php/issues/5118 | |
// Warning: touch(): Google\Cloud\Storage\StreamWrapper::stream_metadata is not implemented! #5118 | |
// PR raised: https://github.com/googleapis/google-cloud-php/pull/7144 | |
use Google\Cloud\Storage\StorageClient; | |
$client = new StorageClient(['projectId' => 'XXXXXXXXXXX']); | |
$client->registerStreamWrapper(); | |
$file = '5118-touch_throws_warnings.txt'; | |
$bucket = $client->bucket('XXXXXXXXXXX'); | |
if ($bucket->object($file)->exists()) { | |
$bucket->object($file)->upload('Hello'); | |
print('File deleted: ' . $file . PHP_EOL); | |
} | |
$bucket->upload("Hello".PHP_EOL, ['name' => $file]); | |
touch('gs://XXXXXXXXXXX/' . $file); | |
$out = $bucket->object($file)->downloadAsString(); | |
if ($bucket->object($file)->exists()) { | |
print('File exists and has: ' . $out . PHP_EOL); | |
print('TEST PASSED' . PHP_EOL); | |
} else { | |
print('File does not exist: ' . $file . PHP_EOL); | |
print('TEST FAILED' . PHP_EOL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment