Skip to content

Commit 48712c2

Browse files
committed
Merge pull request #301
2 parents b433869 + 471baea commit 48712c2

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/GridFS/Bucket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ private function getRawFileDocumentForStream($stream)
529529

530530
$metadata = stream_get_meta_data($stream);
531531

532-
if (!$metadata['wrapper_data'] instanceof StreamWrapper) {
533-
throw InvalidArgumentException::invalidType('$stream wrapper data', $metadata['wrapper_data'], 'MongoDB\Driver\GridFS\StreamWrapper');
532+
if ( ! isset ($metadata['wrapper_data']) || ! $metadata['wrapper_data'] instanceof StreamWrapper) {
533+
throw InvalidArgumentException::invalidType('$stream wrapper data', isset($metadata['wrapper_data']) ? $metadata['wrapper_data'] : null, 'MongoDB\Driver\GridFS\StreamWrapper');
534534
}
535535

536536
return $metadata['wrapper_data']->getFile();

tests/GridFS/BucketFunctionalTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function testDownloadToStreamShouldRequireDestinationStream($destination)
194194

195195
public function provideInvalidStreamValues()
196196
{
197-
return $this->wrapValuesForDataProvider([null, 123, 'foo', [], hash_init('md5')]);
197+
return $this->wrapValuesForDataProvider($this->getInvalidStreamValues());
198198
}
199199

200200
/**
@@ -407,13 +407,18 @@ public function testGetFileDocumentForStreamWithWritableStream()
407407

408408
/**
409409
* @expectedException MongoDB\Exception\InvalidArgumentException
410-
* @dataProvider provideInvalidStreamValues
410+
* @dataProvider provideInvalidGridFSStreamValues
411411
*/
412-
public function testGetFileDocumentForStreamShouldRequireStreamResource($stream)
412+
public function testGetFileDocumentForStreamShouldRequireGridFSStreamResource($stream)
413413
{
414414
$this->bucket->getFileDocumentForStream($stream);
415415
}
416416

417+
public function provideInvalidGridFSStreamValues()
418+
{
419+
return $this->wrapValuesForDataProvider(array_merge($this->getInvalidStreamValues(), [$this->createStream()]));
420+
}
421+
417422
public function testGetFileIdForStreamUsesTypeMap()
418423
{
419424
$stream = $this->bucket->openUploadStream('filename', ['_id' => ['x' => 1]]);
@@ -441,9 +446,9 @@ public function testGetFileIdForStreamWithWritableStream()
441446

442447
/**
443448
* @expectedException MongoDB\Exception\InvalidArgumentException
444-
* @dataProvider provideInvalidStreamValues
449+
* @dataProvider provideInvalidGridFSStreamValues
445450
*/
446-
public function testGetFileIdForStreamShouldRequireStreamResource($stream)
451+
public function testGetFileIdForStreamShouldRequireGridFSStreamResource($stream)
447452
{
448453
$this->bucket->getFileIdForStream($stream);
449454
}
@@ -714,4 +719,14 @@ private function assertIndexExists($collectionName, $indexName, $callback = null
714719
call_user_func($callback, $foundIndex);
715720
}
716721
}
722+
723+
/**
724+
* Return a list of invalid stream values.
725+
*
726+
* @return array
727+
*/
728+
private function getInvalidStreamValues()
729+
{
730+
return [null, 123, 'foo', [], hash_init('md5')];
731+
}
717732
}

0 commit comments

Comments
 (0)