@@ -172,6 +172,20 @@ public function testDownloadToStream($input)
172
172
$ this ->assertStreamContents ($ input , $ destination );
173
173
}
174
174
175
+ /**
176
+ * @expectedException MongoDB\Exception\InvalidArgumentException
177
+ * @dataProvider provideInvalidStreamValues
178
+ */
179
+ public function testDownloadToStreamShouldRequireDestinationStream ($ destination )
180
+ {
181
+ $ this ->bucket ->downloadToStream ('id ' , $ destination );
182
+ }
183
+
184
+ public function provideInvalidStreamValues ()
185
+ {
186
+ return $ this ->wrapValuesForDataProvider ([null , 123 , 'foo ' , [], hash_init ('md5 ' )]);
187
+ }
188
+
175
189
/**
176
190
* @expectedException MongoDB\GridFS\Exception\FileNotFoundException
177
191
*/
@@ -180,6 +194,73 @@ public function testDownloadToStreamShouldRequireFileToExist()
180
194
$ this ->bucket ->downloadToStream ('nonexistent-id ' , $ this ->createStream ());
181
195
}
182
196
197
+ public function testDownloadToStreamByName ()
198
+ {
199
+ $ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('foo ' ));
200
+ $ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('bar ' ));
201
+ $ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('baz ' ));
202
+
203
+ $ destination = $ this ->createStream ();
204
+ $ this ->bucket ->downloadToStreamByName ('filename ' , $ destination );
205
+ $ this ->assertStreamContents ('baz ' , $ destination );
206
+
207
+ $ destination = $ this ->createStream ();
208
+ $ this ->bucket ->downloadToStreamByName ('filename ' , $ destination , ['revision ' => -3 ]);
209
+ $ this ->assertStreamContents ('foo ' , $ destination );
210
+
211
+ $ destination = $ this ->createStream ();
212
+ $ this ->bucket ->downloadToStreamByName ('filename ' , $ destination , ['revision ' => -2 ]);
213
+ $ this ->assertStreamContents ('bar ' , $ destination );
214
+
215
+ $ destination = $ this ->createStream ();
216
+ $ this ->bucket ->downloadToStreamByName ('filename ' , $ destination , ['revision ' => -1 ]);
217
+ $ this ->assertStreamContents ('baz ' , $ destination );
218
+
219
+ $ destination = $ this ->createStream ();
220
+ $ this ->bucket ->downloadToStreamByName ('filename ' , $ destination , ['revision ' => 0 ]);
221
+ $ this ->assertStreamContents ('foo ' , $ destination );
222
+
223
+ $ destination = $ this ->createStream ();
224
+ $ this ->bucket ->downloadToStreamByName ('filename ' , $ destination , ['revision ' => 1 ]);
225
+ $ this ->assertStreamContents ('bar ' , $ destination );
226
+
227
+ $ destination = $ this ->createStream ();
228
+ $ this ->bucket ->downloadToStreamByName ('filename ' , $ destination , ['revision ' => 2 ]);
229
+ $ this ->assertStreamContents ('baz ' , $ destination );
230
+ }
231
+
232
+ /**
233
+ * @expectedException MongoDB\Exception\InvalidArgumentException
234
+ * @dataProvider provideInvalidStreamValues
235
+ */
236
+ public function testDownloadToStreamByNameShouldRequireDestinationStream ($ destination )
237
+ {
238
+ $ this ->bucket ->downloadToStreamByName ('filename ' , $ destination );
239
+ }
240
+
241
+ /**
242
+ * @expectedException MongoDB\GridFS\Exception\FileNotFoundException
243
+ * @dataProvider provideNonexistentFilenameAndRevision
244
+ */
245
+ public function testDownloadToStreamByNameShouldRequireFilenameAndRevisionToExist ($ filename , $ revision )
246
+ {
247
+ $ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('foo ' ));
248
+ $ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('bar ' ));
249
+
250
+ $ destination = $ this ->createStream ();
251
+ $ this ->bucket ->downloadToStreamByName ($ filename , $ destination , ['revision ' => $ revision ]);
252
+ }
253
+
254
+ public function provideNonexistentFilenameAndRevision ()
255
+ {
256
+ return [
257
+ ['filename ' , 2 ],
258
+ ['filename ' , -3 ],
259
+ ['nonexistent-filename ' , 0 ],
260
+ ['nonexistent-filename ' , -1 ],
261
+ ];
262
+ }
263
+
183
264
public function testDrop ()
184
265
{
185
266
$ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('foobar ' ));
@@ -306,16 +387,6 @@ public function testOpenDownloadStreamByNameShouldRequireFilenameAndRevisionToEx
306
387
$ this ->bucket ->openDownloadStream ($ filename , ['revision ' => $ revision ]);
307
388
}
308
389
309
- public function provideNonexistentFilenameAndRevision ()
310
- {
311
- return [
312
- ['filename ' , 2 ],
313
- ['filename ' , -3 ],
314
- ['nonexistent-filename ' , 0 ],
315
- ['nonexistent-filename ' , -1 ],
316
- ];
317
- }
318
-
319
390
public function testOpenUploadStream ()
320
391
{
321
392
$ stream = $ this ->bucket ->openUploadStream ('filename ' );
@@ -401,6 +472,15 @@ public function testUploadFromStream()
401
472
$ this ->assertSameDocument (['foo ' => 'bar ' ], $ fileDocument ['metadata ' ]);
402
473
}
403
474
475
+ /**
476
+ * @expectedException MongoDB\Exception\InvalidArgumentException
477
+ * @dataProvider provideInvalidStreamValues
478
+ */
479
+ public function testUploadFromStreamShouldRequireSourceStream ($ source )
480
+ {
481
+ $ this ->bucket ->uploadFromStream ('filename ' , $ source );
482
+ }
483
+
404
484
public function testUploadingAnEmptyFile ()
405
485
{
406
486
$ id = $ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('' ));
0 commit comments