Commit 74989eb7 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #143

parents 03e9decb 4cd5342e
...@@ -6,7 +6,7 @@ use MongoDB\BSON\ObjectId; ...@@ -6,7 +6,7 @@ use MongoDB\BSON\ObjectId;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Exception\GridFSFileNotFoundException; use MongoDB\Exception\GridFSFileNotFoundException;
use MongoDB\Exception\InvalidArgumentTypeException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Find; use MongoDB\Operation\Find;
/** /**
...@@ -51,19 +51,19 @@ class Bucket ...@@ -51,19 +51,19 @@ class Bucket
]; ];
if (isset($options['bucketName']) && ! is_string($options['bucketName'])) { if (isset($options['bucketName']) && ! is_string($options['bucketName'])) {
throw new InvalidArgumentTypeException('"bucketName" option', $options['bucketName'], 'string'); throw InvalidArgumentException::invalidType('"bucketName" option', $options['bucketName'], 'string');
} }
if (isset($options['chunkSizeBytes']) && ! is_integer($options['chunkSizeBytes'])) { if (isset($options['chunkSizeBytes']) && ! is_integer($options['chunkSizeBytes'])) {
throw new InvalidArgumentTypeException('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer'); throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
} }
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) { if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw new InvalidArgumentTypeException('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference'); throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
} }
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) { if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern'); throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
} }
$this->databaseName = (string) $databaseName; $this->databaseName = (string) $databaseName;
......
...@@ -6,7 +6,6 @@ use MongoDB\Collection; ...@@ -6,7 +6,6 @@ use MongoDB\Collection;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentTypeException;
/** /**
* GridFSCollectionsWrapper abstracts the GridFS files and chunks collections. * GridFSCollectionsWrapper abstracts the GridFS files and chunks collections.
......
...@@ -6,7 +6,7 @@ use MongoDB\BSON\Binary; ...@@ -6,7 +6,7 @@ use MongoDB\BSON\Binary;
use MongoDB\BSON\ObjectId; use MongoDB\BSON\ObjectId;
use MongoDB\BSON\UTCDateTime; use MongoDB\BSON\UTCDateTime;
use MongoDB\Driver\Exception\Exception; use MongoDB\Driver\Exception\Exception;
use MongoDB\Exception\InvalidArgumentTypeException; use MongoDB\Exception\InvalidArgumentException;
/** /**
* GridFSUpload abstracts the process of writing a GridFS file. * GridFSUpload abstracts the process of writing a GridFS file.
...@@ -47,22 +47,22 @@ class GridFSUpload ...@@ -47,22 +47,22 @@ class GridFSUpload
* @param GridFSCollectionsWrapper $collectionsWrapper GridFS collections wrapper * @param GridFSCollectionsWrapper $collectionsWrapper GridFS collections wrapper
* @param string $filename File name * @param string $filename File name
* @param array $options Upload options * @param array $options Upload options
* @throws InvalidArgumentTypeException * @throws InvalidArgumentException
*/ */
public function __construct(GridFSCollectionsWrapper $collectionsWrapper, $filename, array $options = []) public function __construct(GridFSCollectionsWrapper $collectionsWrapper, $filename, array $options = [])
{ {
$options += ['chunkSizeBytes' => 261120]; $options += ['chunkSizeBytes' => 261120];
if (isset($options['aliases']) && ! \MongoDB\is_string_array($options['aliases'])) { if (isset($options['aliases']) && ! \MongoDB\is_string_array($options['aliases'])) {
throw new InvalidArgumentTypeException('"aliases" option', $options['aliases'], 'array of strings'); throw InvalidArgumentException::invalidType('"aliases" option', $options['aliases'], 'array of strings');
} }
if (isset($options['contentType']) && ! is_string($options['contentType'])) { if (isset($options['contentType']) && ! is_string($options['contentType'])) {
throw new InvalidArgumentTypeException('"contentType" option', $options['contentType'], 'string'); throw InvalidArgumentException::invalidType('"contentType" option', $options['contentType'], 'string');
} }
if (isset($options['metadata']) && ! is_array($options['metadata']) && ! is_object($options['metadata'])) { if (isset($options['metadata']) && ! is_array($options['metadata']) && ! is_object($options['metadata'])) {
throw new InvalidArgumentTypeException('"metadata" option', $options['metadata'], 'array or object'); throw InvalidArgumentException::invalidType('"metadata" option', $options['metadata'], 'array or object');
} }
$this->chunkSize = $options['chunkSizeBytes']; $this->chunkSize = $options['chunkSizeBytes'];
...@@ -175,7 +175,7 @@ class GridFSUpload ...@@ -175,7 +175,7 @@ class GridFSUpload
public function uploadFromStream($source) public function uploadFromStream($source)
{ {
if ( ! is_resource($source) || get_resource_type($source) != "stream") { if ( ! is_resource($source) || get_resource_type($source) != "stream") {
throw new InvalidArgumentTypeException('$stream', $source, 'resource'); throw InvalidArgumentException::invalidType('$source', $source, 'resource');
} }
$streamMetadata = stream_get_meta_data($source); $streamMetadata = stream_get_meta_data($source);
......
...@@ -11,7 +11,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -11,7 +11,7 @@ class BucketFunctionalTest extends FunctionalTestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
......
...@@ -20,7 +20,7 @@ class GridFSStreamTest extends FunctionalTestCase ...@@ -20,7 +20,7 @@ class GridFSStreamTest extends FunctionalTestCase
$this->assertEquals(1, $this->collectionsWrapper->getFilesCollection()->count()); $this->assertEquals(1, $this->collectionsWrapper->getFilesCollection()->count());
$this->assertEquals(1, $this->collectionsWrapper->getChunksCollection()->count()); $this->assertEquals(1, $this->collectionsWrapper->getChunksCollection()->count());
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$id]); $file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$id], ['typeMap' => ['root' => 'stdClass']]);
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file); $download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
$stream = fopen('php://temp', 'w+'); $stream = fopen('php://temp', 'w+');
...@@ -46,7 +46,7 @@ class GridFSStreamTest extends FunctionalTestCase ...@@ -46,7 +46,7 @@ class GridFSStreamTest extends FunctionalTestCase
$this->assertEquals(2, $this->collectionsWrapper->getFilesCollection()->count()); $this->assertEquals(2, $this->collectionsWrapper->getFilesCollection()->count());
$this->assertEquals(1, $this->collectionsWrapper->getChunksCollection()->count()); $this->assertEquals(1, $this->collectionsWrapper->getChunksCollection()->count());
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$id]); $file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$id], ['typeMap' => ['root' => 'stdClass']]);
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file); $download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
$stream = fopen('php://temp', 'w+'); $stream = fopen('php://temp', 'w+');
$download->downloadToStream($stream); $download->downloadToStream($stream);
...@@ -100,7 +100,7 @@ class GridFSStreamTest extends FunctionalTestCase ...@@ -100,7 +100,7 @@ class GridFSStreamTest extends FunctionalTestCase
$upload = new \MongoDB\GridFS\GridFSUpload($this->collectionsWrapper, "test"); $upload = new \MongoDB\GridFS\GridFSUpload($this->collectionsWrapper, "test");
$upload->close(); $upload->close();
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id" => $upload->getId()]); $file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id" => $upload->getId()], ['typeMap' => ['root' => 'stdClass']]);
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file); $download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
$download->close(); $download->close();
...@@ -124,7 +124,7 @@ class GridFSStreamTest extends FunctionalTestCase ...@@ -124,7 +124,7 @@ class GridFSStreamTest extends FunctionalTestCase
$upload->insertChunks("hello world"); $upload->insertChunks("hello world");
$upload->close(); $upload->close();
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id" => $upload->getId()]); $file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id" => $upload->getId()], ['typeMap' => ['root' => 'stdClass']]);
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file); $download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
$this->assertEquals("test", $download->getFile()->filename); $this->assertEquals("test", $download->getFile()->filename);
...@@ -185,7 +185,7 @@ class GridFSStreamTest extends FunctionalTestCase ...@@ -185,7 +185,7 @@ class GridFSStreamTest extends FunctionalTestCase
$upload = new \MongoDB\GridFS\GridFSUpload($this->collectionsWrapper, "test", ["chunkSizeBytes"=>3]); $upload = new \MongoDB\GridFS\GridFSUpload($this->collectionsWrapper, "test", ["chunkSizeBytes"=>3]);
$upload->insertChunks("hello world"); $upload->insertChunks("hello world");
$upload->close(); $upload->close();
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$upload->getId()]); $file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$upload->getId()], ['typeMap' => ['root' => 'stdClass']]);
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file); $download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
$this->assertEquals("he", $download->downloadNumBytes(2)); $this->assertEquals("he", $download->downloadNumBytes(2));
$this->assertEquals("ll", $download->downloadNumBytes(2)); $this->assertEquals("ll", $download->downloadNumBytes(2));
...@@ -205,7 +205,7 @@ class GridFSStreamTest extends FunctionalTestCase ...@@ -205,7 +205,7 @@ class GridFSStreamTest extends FunctionalTestCase
$upload = new \MongoDB\GridFS\GridFSUpload($this->collectionsWrapper, "test", ["chunkSizeBytes"=>rand(1, 5)]); $upload = new \MongoDB\GridFS\GridFSUpload($this->collectionsWrapper, "test", ["chunkSizeBytes"=>rand(1, 5)]);
$upload->insertChunks($data); $upload->insertChunks($data);
$upload->close(); $upload->close();
$file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$upload->getId()]); $file = $this->collectionsWrapper->getFilesCollection()->findOne(["_id"=>$upload->getId()], ['typeMap' => ['root' => 'stdClass']]);
$download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file); $download = new \MongoDB\GridFS\GridFSDownload($this->collectionsWrapper, $file);
$readPos = 0; $readPos = 0;
...@@ -222,7 +222,7 @@ class GridFSStreamTest extends FunctionalTestCase ...@@ -222,7 +222,7 @@ class GridFSStreamTest extends FunctionalTestCase
$download->close(); $download->close();
} }
/** /**
* @expectedException \MongoDB\Exception\InvalidArgumentTypeException * @expectedException \MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidUploadConstructorOptions * @dataProvider provideInvalidUploadConstructorOptions
*/ */
public function testUploadConstructorOptionTypeChecks(array $options) public function testUploadConstructorOptionTypeChecks(array $options)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment