diff --git a/src/GridFS/Bucket.php b/src/GridFS/Bucket.php index a9a78804064741c2984146217f0c348fa8aba026..3763f2b6195fdbee3f9ab421dc1c9dbc1510592f 100644 --- a/src/GridFS/Bucket.php +++ b/src/GridFS/Bucket.php @@ -529,8 +529,8 @@ class Bucket $metadata = stream_get_meta_data($stream); - if (!$metadata['wrapper_data'] instanceof StreamWrapper) { - throw InvalidArgumentException::invalidType('$stream wrapper data', $metadata['wrapper_data'], 'MongoDB\Driver\GridFS\StreamWrapper'); + if ( ! isset ($metadata['wrapper_data']) || ! $metadata['wrapper_data'] instanceof StreamWrapper) { + throw InvalidArgumentException::invalidType('$stream wrapper data', isset($metadata['wrapper_data']) ? $metadata['wrapper_data'] : null, 'MongoDB\Driver\GridFS\StreamWrapper'); } return $metadata['wrapper_data']->getFile(); diff --git a/tests/GridFS/BucketFunctionalTest.php b/tests/GridFS/BucketFunctionalTest.php index 04733c2f6e2bfa294f92bbf74079aa840e018d2e..113c3bd9e3ff8708ecc250ae0ccb6d2ade98e5b4 100644 --- a/tests/GridFS/BucketFunctionalTest.php +++ b/tests/GridFS/BucketFunctionalTest.php @@ -194,7 +194,7 @@ class BucketFunctionalTest extends FunctionalTestCase public function provideInvalidStreamValues() { - return $this->wrapValuesForDataProvider([null, 123, 'foo', [], hash_init('md5')]); + return $this->wrapValuesForDataProvider($this->getInvalidStreamValues()); } /** @@ -407,13 +407,18 @@ class BucketFunctionalTest extends FunctionalTestCase /** * @expectedException MongoDB\Exception\InvalidArgumentException - * @dataProvider provideInvalidStreamValues + * @dataProvider provideInvalidGridFSStreamValues */ - public function testGetFileDocumentForStreamShouldRequireStreamResource($stream) + public function testGetFileDocumentForStreamShouldRequireGridFSStreamResource($stream) { $this->bucket->getFileDocumentForStream($stream); } + public function provideInvalidGridFSStreamValues() + { + return $this->wrapValuesForDataProvider(array_merge($this->getInvalidStreamValues(), [$this->createStream()])); + } + public function testGetFileIdForStreamUsesTypeMap() { $stream = $this->bucket->openUploadStream('filename', ['_id' => ['x' => 1]]); @@ -441,9 +446,9 @@ class BucketFunctionalTest extends FunctionalTestCase /** * @expectedException MongoDB\Exception\InvalidArgumentException - * @dataProvider provideInvalidStreamValues + * @dataProvider provideInvalidGridFSStreamValues */ - public function testGetFileIdForStreamShouldRequireStreamResource($stream) + public function testGetFileIdForStreamShouldRequireGridFSStreamResource($stream) { $this->bucket->getFileIdForStream($stream); } @@ -714,4 +719,14 @@ class BucketFunctionalTest extends FunctionalTestCase call_user_func($callback, $foundIndex); } } + + /** + * Return a list of invalid stream values. + * + * @return array + */ + private function getInvalidStreamValues() + { + return [null, 123, 'foo', [], hash_init('md5')]; + } }