@@ -323,12 +323,63 @@ public function testGetDatabaseName()
323323 $ this ->assertEquals ($ this ->getDatabaseName (), $ this ->bucket ->getDatabaseName ());
324324 }
325325
326- public function testGetIdFromStream ()
326+ public function testGetFileDocumentForStreamWithReadableStream ()
327+ {
328+ $ metadata = ['foo ' => 'bar ' ];
329+ $ id = $ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('foobar ' ), ['metadata ' => $ metadata ]);
330+ $ stream = $ this ->bucket ->openDownloadStream ($ id );
331+
332+ $ fileDocument = $ this ->bucket ->getFileDocumentForStream ($ stream );
333+
334+ $ this ->assertEquals ($ id , $ fileDocument ->_id );
335+ $ this ->assertSame ('filename ' , $ fileDocument ->filename );
336+ $ this ->assertSame (6 , $ fileDocument ->length );
337+ $ this ->assertSameDocument ($ metadata , $ fileDocument ->metadata );
338+ }
339+
340+ public function testGetFileDocumentForStreamWithWritableStream ()
341+ {
342+ $ metadata = ['foo ' => 'bar ' ];
343+ $ stream = $ this ->bucket ->openUploadStream ('filename ' , ['_id ' => 1 , 'metadata ' => $ metadata ]);
344+
345+ $ fileDocument = $ this ->bucket ->getFileDocumentForStream ($ stream );
346+
347+ $ this ->assertEquals (1 , $ fileDocument ->_id );
348+ $ this ->assertSame ('filename ' , $ fileDocument ->filename );
349+ $ this ->assertSameDocument ($ metadata , $ fileDocument ->metadata );
350+ }
351+
352+ /**
353+ * @expectedException MongoDB\Exception\InvalidArgumentException
354+ * @dataProvider provideInvalidStreamValues
355+ */
356+ public function testGetFileDocumentForStreamShouldRequireStreamResource ($ stream )
357+ {
358+ $ this ->bucket ->getFileDocumentForStream ($ stream );
359+ }
360+
361+ public function testGetFileIdForStreamWithReadableStream ()
327362 {
328363 $ id = $ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('foobar ' ));
329364 $ stream = $ this ->bucket ->openDownloadStream ($ id );
330365
331- $ this ->assertEquals ($ id , $ this ->bucket ->getIdFromStream ($ stream ));
366+ $ this ->assertEquals ($ id , $ this ->bucket ->getFileIdForStream ($ stream ));
367+ }
368+
369+ public function testGetFileIdForStreamWithWritableStream ()
370+ {
371+ $ stream = $ this ->bucket ->openUploadStream ('filename ' , ['_id ' => 1 ]);
372+
373+ $ this ->assertEquals (1 , $ this ->bucket ->getFileIdForStream ($ stream ));
374+ }
375+
376+ /**
377+ * @expectedException MongoDB\Exception\InvalidArgumentException
378+ * @dataProvider provideInvalidStreamValues
379+ */
380+ public function testGetFileIdForStreamShouldRequireStreamResource ($ stream )
381+ {
382+ $ this ->bucket ->getFileIdForStream ($ stream );
332383 }
333384
334385 /**
0 commit comments