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
3b128d3a
Commit
3b128d3a
authored
Dec 23, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70
parents
cb5cf0bb
fdaed29c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
2 deletions
+68
-2
CreateCollection.php
src/Operation/CreateCollection.php
+12
-2
CreateCollectionTest.php
tests/Operation/CreateCollectionTest.php
+56
-0
No files found.
src/Operation/CreateCollection.php
View file @
3b128d3a
...
...
@@ -5,8 +5,7 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\UnexpectedTypeException
;
use
MongoDB\Model\IndexInput
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
/**
* Operation for the create command.
...
...
@@ -40,6 +39,9 @@ class CreateCollection implements Executable
* bitwise combination USE_POWER_OF_2_SIZES and NO_PADDING. The default
* is USE_POWER_OF_2_SIZES.
*
* * indexOptionDefaults (document): Default configuration for indexes when
* creating the collection.
*
* * max (integer): The maximum number of documents allowed in the capped
* collection. The size option takes precedence over this limit.
*
...
...
@@ -70,6 +72,10 @@ class CreateCollection implements Executable
throw
new
InvalidArgumentTypeException
(
'"flags" option'
,
$options
[
'flags'
],
'integer'
);
}
if
(
isset
(
$options
[
'indexOptionDefaults'
])
&&
!
is_array
(
$options
[
'indexOptionDefaults'
])
&&
!
is_object
(
$options
[
'indexOptionDefaults'
]))
{
throw
new
InvalidArgumentTypeException
(
'"indexOptionDefaults" option'
,
$options
[
'indexOptionDefaults'
],
'array or object'
);
}
if
(
isset
(
$options
[
'max'
])
&&
!
is_integer
(
$options
[
'max'
]))
{
throw
new
InvalidArgumentTypeException
(
'"max" option'
,
$options
[
'max'
],
'integer'
);
}
...
...
@@ -120,6 +126,10 @@ class CreateCollection implements Executable
}
}
if
(
!
empty
(
$this
->
options
[
'indexOptionDefaults'
]))
{
$cmd
[
'indexOptionDefaults'
]
=
(
object
)
$this
->
options
[
'indexOptionDefaults'
];
}
if
(
!
empty
(
$this
->
options
[
'storageEngine'
]))
{
$cmd
[
'storageEngine'
]
=
(
object
)
$this
->
options
[
'storageEngine'
];
}
...
...
tests/Operation/CreateCollectionTest.php
0 → 100644
View file @
3b128d3a
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\CreateCollection
;
class
CreateCollectionTest
extends
TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
[];
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
[
'autoIndexId'
=>
$value
];
}
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
[
'capped'
=>
$value
];
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
[
'flags'
=>
$value
];
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
[
'indexOptionDefaults'
=>
$value
];
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
[
'max'
=>
$value
];
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
[
'maxTimeMS'
=>
$value
];
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
[
'size'
=>
$value
];
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
[
'storageEngine'
=>
$value
];
}
return
$options
;
}
}
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