Skip to content

Commit 74989eb

Browse files
committed
Merge pull request #143
2 parents 03e9dec + 4cd5342 commit 74989eb

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

src/GridFS/Bucket.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use MongoDB\Driver\Cursor;
77
use MongoDB\Driver\Manager;
88
use MongoDB\Exception\GridFSFileNotFoundException;
9-
use MongoDB\Exception\InvalidArgumentTypeException;
9+
use MongoDB\Exception\InvalidArgumentException;
1010
use MongoDB\Operation\Find;
1111

1212
/**
@@ -51,19 +51,19 @@ public function __construct(Manager $manager, $databaseName, array $options = []
5151
];
5252

5353
if (isset($options['bucketName']) && ! is_string($options['bucketName'])) {
54-
throw new InvalidArgumentTypeException('"bucketName" option', $options['bucketName'], 'string');
54+
throw InvalidArgumentException::invalidType('"bucketName" option', $options['bucketName'], 'string');
5555
}
5656

5757
if (isset($options['chunkSizeBytes']) && ! is_integer($options['chunkSizeBytes'])) {
58-
throw new InvalidArgumentTypeException('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
58+
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
5959
}
6060

6161
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
62-
throw new InvalidArgumentTypeException('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
62+
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
6363
}
6464

6565
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
66-
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
66+
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
6767
}
6868

6969
$this->databaseName = (string) $databaseName;

src/GridFS/GridFSCollectionsWrapper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use MongoDB\Driver\Manager;
77
use MongoDB\Driver\ReadPreference;
88
use MongoDB\Driver\WriteConcern;
9-
use MongoDB\Exception\InvalidArgumentTypeException;
109

1110
/**
1211
* GridFSCollectionsWrapper abstracts the GridFS files and chunks collections.

src/GridFS/GridFSUpload.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use MongoDB\BSON\ObjectId;
77
use MongoDB\BSON\UTCDateTime;
88
use MongoDB\Driver\Exception\Exception;
9-
use MongoDB\Exception\InvalidArgumentTypeException;
9+
use MongoDB\Exception\InvalidArgumentException;
1010

1111
/**
1212
* GridFSUpload abstracts the process of writing a GridFS file.
@@ -47,22 +47,22 @@ class GridFSUpload
4747
* @param GridFSCollectionsWrapper $collectionsWrapper GridFS collections wrapper
4848
* @param string $filename File name
4949
* @param array $options Upload options
50-
* @throws InvalidArgumentTypeException
50+
* @throws InvalidArgumentException
5151
*/
5252
public function __construct(GridFSCollectionsWrapper $collectionsWrapper, $filename, array $options = [])
5353
{
5454
$options += ['chunkSizeBytes' => 261120];
5555

5656
if (isset($options['aliases']) && ! \MongoDB\is_string_array($options['aliases'])) {
57-
throw new InvalidArgumentTypeException('"aliases" option', $options['aliases'], 'array of strings');
57+
throw InvalidArgumentException::invalidType('"aliases" option', $options['aliases'], 'array of strings');
5858
}
5959

6060
if (isset($options['contentType']) && ! is_string($options['contentType'])) {
61-
throw new InvalidArgumentTypeException('"contentType" option', $options['contentType'], 'string');
61+
throw InvalidArgumentException::invalidType('"contentType" option', $options['contentType'], 'string');
6262
}
6363

6464
if (isset($options['metadata']) && ! is_array($options['metadata']) && ! is_object($options['metadata'])) {
65-
throw new InvalidArgumentTypeException('"metadata" option', $options['metadata'], 'array or object');
65+
throw InvalidArgumentException::invalidType('"metadata" option', $options['metadata'], 'array or object');
6666
}
6767

6868
$this->chunkSize = $options['chunkSizeBytes'];
@@ -175,7 +175,7 @@ public function isEOF()
175175
public function uploadFromStream($source)
176176
{
177177
if ( ! is_resource($source) || get_resource_type($source) != "stream") {
178-
throw new InvalidArgumentTypeException('$stream', $source, 'resource');
178+
throw InvalidArgumentException::invalidType('$source', $source, 'resource');
179179
}
180180

181181
$streamMetadata = stream_get_meta_data($source);

tests/GridFS/BucketFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class BucketFunctionalTest extends FunctionalTestCase
1111
{
1212

1313
/**
14-
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
14+
* @expectedException MongoDB\Exception\InvalidArgumentException
1515
* @dataProvider provideInvalidConstructorOptions
1616
*/
1717
public function testConstructorOptionTypeChecks(array $options)

tests/GridFS/GridFSStreamTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testBasic()
2020
$this->assertEquals(1, $this->collectionsWrapper->getFilesCollection()->count());
2121
$this->assertEquals(1, $this->collectionsWrapper->getChunksCollection()->count());
2222

23-
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$id]);
23+
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$id], ['typeMap' => ['root' => 'stdClass']]);
2424

2525
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
2626
$stream = fopen('php://temp', 'w+');
@@ -46,7 +46,7 @@ public function testBasic()
4646
$this->assertEquals(2, $this->collectionsWrapper->getFilesCollection()->count());
4747
$this->assertEquals(1, $this->collectionsWrapper->getChunksCollection()->count());
4848

49-
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$id]);
49+
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$id], ['typeMap' => ['root' => 'stdClass']]);
5050
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
5151
$stream = fopen('php://temp', 'w+');
5252
$download->downloadToStream($stream);
@@ -100,7 +100,7 @@ public function testDownloadDefaultOpts()
100100
$upload = new \MongoDB\GridFS\GridFSUpload($this->collectionsWrapper, "test");
101101
$upload->close();
102102

103-
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id" => $upload->getId()]);
103+
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id" => $upload->getId()], ['typeMap' => ['root' => 'stdClass']]);
104104
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
105105
$download->close();
106106

@@ -124,7 +124,7 @@ public function testDownloadCustomOpts()
124124
$upload->insertChunks("hello world");
125125
$upload->close();
126126

127-
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id" => $upload->getId()]);
127+
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id" => $upload->getId()], ['typeMap' => ['root' => 'stdClass']]);
128128
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
129129

130130
$this->assertEquals("test", $download->getFile()->filename);
@@ -185,7 +185,7 @@ public function testMultipleReads()
185185
$upload = new \MongoDB\GridFS\GridFSUpload($this->collectionsWrapper, "test", ["chunkSizeBytes"=>3]);
186186
$upload->insertChunks("hello world");
187187
$upload->close();
188-
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$upload->getId()]);
188+
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$upload->getId()], ['typeMap' => ['root' => 'stdClass']]);
189189
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
190190
$this->assertEquals("he", $download->downloadNumBytes(2));
191191
$this->assertEquals("ll", $download->downloadNumBytes(2));
@@ -205,7 +205,7 @@ public function testProvidedMultipleReads($data)
205205
$upload = new \MongoDB\GridFS\GridFSUpload($this->collectionsWrapper, "test", ["chunkSizeBytes"=>rand(1, 5)]);
206206
$upload->insertChunks($data);
207207
$upload->close();
208-
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$upload->getId()]);
208+
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$upload->getId()], ['typeMap' => ['root' => 'stdClass']]);
209209
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
210210

211211
$readPos = 0;
@@ -222,7 +222,7 @@ public function testProvidedMultipleReads($data)
222222
$download->close();
223223
}
224224
/**
225-
* @expectedException \MongoDB\Exception\InvalidArgumentTypeException
225+
* @expectedException \MongoDB\Exception\InvalidArgumentException
226226
* @dataProvider provideInvalidUploadConstructorOptions
227227
*/
228228
public function testUploadConstructorOptionTypeChecks(array $options)

0 commit comments

Comments
 (0)