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
84b82c4a
Commit
84b82c4a
authored
Dec 23, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71
parents
3b128d3a
6b950169
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
16 deletions
+41
-16
IndexInput.php
src/Model/IndexInput.php
+6
-6
CreateIndexes.php
src/Operation/CreateIndexes.php
+11
-3
IndexInputTest.php
tests/Model/IndexInputTest.php
+13
-6
CreateIndexesTest.php
tests/Operation/CreateIndexesTest.php
+11
-1
No files found.
src/Model/IndexInput.php
View file @
84b82c4a
...
...
@@ -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 @
84b82c4a
...
...
@@ -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
;
/**
...
...
@@ -40,9 +40,15 @@ class CreateIndexes implements Executable
throw
new
InvalidArgumentException
(
'$indexes is empty'
);
}
foreach
(
$indexes
as
$index
)
{
$expectedIndex
=
0
;
foreach
(
$indexes
as
$i
=>
$index
)
{
if
(
$i
!==
$expectedIndex
)
{
throw
new
InvalidArgumentException
(
sprintf
(
'$indexes is not a list (unexpected index: "%s")'
,
$i
));
}
if
(
!
is_array
(
$index
))
{
throw
new
UnexpectedTypeException
(
$index
,
'array'
);
throw
new
InvalidArgumentTypeException
(
sprintf
(
'$index[%d]'
,
$i
),
$index
,
'array'
);
}
if
(
!
isset
(
$index
[
'ns'
]))
{
...
...
@@ -50,6 +56,8 @@ class CreateIndexes implements Executable
}
$this
->
indexes
[]
=
new
IndexInput
(
$index
);
$expectedIndex
+=
1
;
}
$this
->
databaseName
=
(
string
)
$databaseName
;
...
...
tests/Model/IndexInputTest.php
View file @
84b82c4a
...
...
@@ -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 @
84b82c4a
...
...
@@ -8,6 +8,7 @@ class CreateIndexesTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $indexes is empty
*/
public
function
testCreateIndexesRequiresAtLeastOneIndex
()
{
...
...
@@ -15,7 +16,16 @@ class CreateIndexesTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\UnexpectedTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $indexes is not a list (unexpected index: "1")
*/
public
function
testConstructorIndexesArgumentMustBeAList
()
{
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
1
=>
[
'key'
=>
[
'x'
=>
1
]]]);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidIndexSpecificationTypes
*/
public
function
testCreateIndexesRequiresIndexSpecificationsToBeAnArray
(
$index
)
...
...
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