Commit c674aac2 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-141: Remove InvalidArgumentTypeException in GridFS

parent 03e9decb
...@@ -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)
......
...@@ -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