Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
7239ab74
Commit
7239ab74
authored
Dec 23, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use InvalidArgumentTypeException for index option validation
parent
3b128d3a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
14 deletions
+22
-14
IndexInput.php
src/Model/IndexInput.php
+6
-6
CreateIndexes.php
src/Operation/CreateIndexes.php
+2
-2
IndexInputTest.php
tests/Model/IndexInputTest.php
+13
-6
CreateIndexesTest.php
tests/Operation/CreateIndexesTest.php
+1
-0
No files found.
src/Model/IndexInput.php
View file @
7239ab74
...
...
@@ -4,7 +4,7 @@ namespace MongoDB\Model;
use
MongoDB\BSON\Serializable
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\
Unexpected
TypeException
;
use
MongoDB\Exception\
InvalidArgument
TypeException
;
/**
* Index input model class.
...
...
@@ -32,12 +32,12 @@ class IndexInput implements Serializable
}
if
(
!
is_array
(
$index
[
'key'
])
&&
!
is_object
(
$index
[
'key'
]))
{
throw
new
UnexpectedTypeException
(
$index
[
'key'
],
'array or object'
);
throw
new
InvalidArgumentTypeException
(
'"key" option'
,
$index
[
'key'
],
'array or object'
);
}
foreach
(
$index
[
'key'
]
as
$order
)
{
foreach
(
$index
[
'key'
]
as
$
fieldName
=>
$
order
)
{
if
(
!
is_int
(
$order
)
&&
!
is_float
(
$order
)
&&
!
is_string
(
$order
))
{
throw
new
UnexpectedTypeException
(
$order
,
'numeric or string'
);
throw
new
InvalidArgumentTypeException
(
sprintf
(
'order value for "%s" field within "key" option'
,
$fieldName
),
$order
,
'numeric or string'
);
}
}
...
...
@@ -46,7 +46,7 @@ class IndexInput implements Serializable
}
if
(
!
is_string
(
$index
[
'ns'
]))
{
throw
new
UnexpectedTypeException
(
$index
[
'ns'
],
'string'
);
throw
new
InvalidArgumentTypeException
(
'"ns" option'
,
$index
[
'ns'
],
'string'
);
}
if
(
!
isset
(
$index
[
'name'
]))
{
...
...
@@ -54,7 +54,7 @@ class IndexInput implements Serializable
}
if
(
!
is_string
(
$index
[
'name'
]))
{
throw
new
UnexpectedTypeException
(
$index
[
'name'
],
'string'
);
throw
new
InvalidArgumentTypeException
(
'"name" option'
,
$index
[
'name'
],
'string'
);
}
$this
->
index
=
$index
;
...
...
src/Operation/CreateIndexes.php
View file @
7239ab74
...
...
@@ -7,7 +7,7 @@ use MongoDB\Driver\Server;
use
MongoDB\Driver\BulkWrite
as
Bulk
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\
Unexpected
TypeException
;
use
MongoDB\Exception\
InvalidArgument
TypeException
;
use
MongoDB\Model\IndexInput
;
/**
...
...
@@ -42,7 +42,7 @@ class CreateIndexes implements Executable
foreach
(
$indexes
as
$index
)
{
if
(
!
is_array
(
$index
))
{
throw
new
UnexpectedTypeException
(
$index
,
'array'
);
throw
new
InvalidArgumentTypeException
(
sprintf
(
'$index[%d]'
,
$i
),
$index
,
'array'
);
}
if
(
!
isset
(
$index
[
'ns'
]))
{
...
...
tests/Model/IndexInputTest.php
View file @
7239ab74
...
...
@@ -4,6 +4,7 @@ namespace MongoDB\Tests;
use
MongoDB\Model\IndexInput
;
use
MongoDB\Tests\TestCase
;
use
stdClass
;
class
IndexInputTest
extends
TestCase
{
...
...
@@ -16,7 +17,7 @@ class IndexInputTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\
Unexpected
TypeException
* @expectedException MongoDB\Exception\
InvalidArgument
TypeException
*/
public
function
testConstructorShouldRequireKeyToBeArrayOrObject
()
{
...
...
@@ -24,11 +25,17 @@ class IndexInputTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\UnexpectedTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidFieldOrderValues
*/
public
function
testConstructorShouldRequireKey
OrderToBeScalar
(
)
public
function
testConstructorShouldRequireKey
FieldOrderToBeNumericOrString
(
$order
)
{
new
IndexInput
([
'key'
=>
[
'x'
=>
[]]]);
new
IndexInput
([
'key'
=>
[
'x'
=>
$order
]]);
}
public
function
provideInvalidFieldOrderValues
()
{
return
$this
->
wrapValuesForDataProvider
([
true
,
[],
new
stdClass
]);
}
/**
...
...
@@ -40,7 +47,7 @@ class IndexInputTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\
Unexpected
TypeException
* @expectedException MongoDB\Exception\
InvalidArgument
TypeException
*/
public
function
testConstructorShouldRequireNamespaceToBeString
()
{
...
...
@@ -48,7 +55,7 @@ class IndexInputTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\
Unexpected
TypeException
* @expectedException MongoDB\Exception\
InvalidArgument
TypeException
*/
public
function
testConstructorShouldRequireNameToBeString
()
{
...
...
tests/Operation/CreateIndexesTest.php
View file @
7239ab74
...
...
@@ -8,6 +8,7 @@ class CreateIndexesTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $indexes is empty
*/
public
function
testCreateIndexesRequiresAtLeastOneIndex
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment