Skip to content

Instantly share code, notes, and snippets.

@vishwarajanand
Created March 14, 2024 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishwarajanand/a895a5610fefb11c761373882f7fa6a9 to your computer and use it in GitHub Desktop.
Save vishwarajanand/a895a5610fefb11c761373882f7fa6a9 to your computer and use it in GitHub Desktop.
Test Script for implementing touch in google cloud storage php library
<?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