@@ -30,6 +30,7 @@ class ObjectsTest extends TestCase
3030
3131 private static $ bucketName ;
3232 private static $ storage ;
33+ private static $ contents ;
3334
3435 public static function setUpBeforeClass (): void
3536 {
@@ -38,6 +39,7 @@ public static function setUpBeforeClass(): void
3839 self ::requireEnv ('GOOGLE_STORAGE_BUCKET ' )
3940 );
4041 self ::$ storage = new StorageClient ();
42+ self ::$ contents = ' !"#$%& \'()*,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~ ' ;
4143 }
4244
4345 public function testListObjects ()
@@ -184,12 +186,36 @@ public function testUploadAndDownloadObjectFromMemory()
184186 {
185187 $ objectName = 'test-object- ' . time ();
186188 $ bucket = self ::$ storage ->bucket (self ::$ bucketName );
187- $ contents = ' !"#$%& \'()*,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~ ' ;
188189 $ object = $ bucket ->object ($ objectName );
189190
190191 $ this ->assertFalse ($ object ->exists ());
191192
192193 $ output = self ::runFunctionSnippet ('upload_object_from_memory ' , [
194+ self ::$ bucketName ,
195+ $ objectName ,
196+ self ::$ contents ,
197+ ]);
198+
199+ $ object ->reload ();
200+ $ this ->assertTrue ($ object ->exists ());
201+
202+ $ output = self ::runFunctionSnippet ('download_object_into_memory ' , [
203+ self ::$ bucketName ,
204+ $ objectName ,
205+ ]);
206+ $ this ->assertStringContainsString (self ::$ contents , $ output );
207+ }
208+
209+ public function testUploadAndDownloadObjectStream ()
210+ {
211+ $ objectName = 'test-object-stream- ' . time ();
212+ // contents larger than atleast one chunk size
213+ $ contents = str_repeat (self ::$ contents , 1024 * 10 );
214+ $ bucket = self ::$ storage ->bucket (self ::$ bucketName );
215+ $ object = $ bucket ->object ($ objectName );
216+ $ this ->assertFalse ($ object ->exists ());
217+
218+ $ output = self ::runFunctionSnippet ('upload_object_stream ' , [
193219 self ::$ bucketName ,
194220 $ objectName ,
195221 $ contents ,
@@ -200,7 +226,7 @@ public function testUploadAndDownloadObjectFromMemory()
200226
201227 $ output = self ::runFunctionSnippet ('download_object_into_memory ' , [
202228 self ::$ bucketName ,
203- $ objectName
229+ $ objectName,
204230 ]);
205231 $ this ->assertStringContainsString ($ contents , $ output );
206232 }
@@ -209,19 +235,18 @@ public function testDownloadByteRange()
209235 {
210236 $ objectName = 'test-object-download-byte-range- ' . time ();
211237 $ bucket = self ::$ storage ->bucket (self ::$ bucketName );
212- $ contents = ' !"#$%& \'()*,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~ ' ;
213238 $ object = $ bucket ->object ($ objectName );
214239 $ downloadTo = tempnam (sys_get_temp_dir (), '/tests ' );
215240 $ downloadToBasename = basename ($ downloadTo );
216241 $ startPos = 1 ;
217- $ endPos = strlen ($ contents ) - 2 ;
242+ $ endPos = strlen (self :: $ contents ) - 2 ;
218243
219244 $ this ->assertFalse ($ object ->exists ());
220245
221246 $ output = self ::runFunctionSnippet ('upload_object_from_memory ' , [
222247 self ::$ bucketName ,
223248 $ objectName ,
224- $ contents
249+ self :: $ contents,
225250 ]);
226251
227252 $ object ->reload ();
@@ -236,7 +261,7 @@ public function testDownloadByteRange()
236261 ]);
237262
238263 $ this ->assertTrue (file_exists ($ downloadTo ));
239- $ expectedContents = substr ($ contents , $ startPos , $ endPos - $ startPos + 1 );
264+ $ expectedContents = substr (self :: $ contents , $ startPos , $ endPos - $ startPos + 1 );
240265 $ this ->assertEquals ($ expectedContents , file_get_contents ($ downloadTo ));
241266 $ this ->assertStringContainsString (
242267 sprintf (
0 commit comments