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
4dc895c8
Commit
4dc895c8
authored
Mar 19, 2018
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v1.3'
parents
39057724
7417ecf1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
3 deletions
+35
-3
Collection.php
src/Collection.php
+4
-3
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+31
-0
No files found.
src/Collection.php
View file @
4dc895c8
...
...
@@ -277,7 +277,7 @@ class Collection
* @see CreateIndexes::__construct() for supported command options
* @param array|object $key Document containing fields mapped to values,
* which denote order or an index type
* @param array $options Index options
* @param array $options Index
and command
options
* @return string The name of the created index
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
...
...
@@ -285,8 +285,9 @@ class Collection
*/
public
function
createIndex
(
$key
,
array
$options
=
[])
{
$indexOptions
=
array_diff_key
(
$options
,
[
'maxTimeMS'
=>
1
,
'writeConcern'
=>
1
]);
$commandOptions
=
array_intersect_key
(
$options
,
[
'maxTimeMS'
=>
1
,
'writeConcern'
=>
1
]);
$commandOptionKeys
=
[
'maxTimeMS'
=>
1
,
'session'
=>
1
,
'writeConcern'
=>
1
];
$indexOptions
=
array_diff_key
(
$options
,
$commandOptionKeys
);
$commandOptions
=
array_intersect_key
(
$options
,
$commandOptionKeys
);
return
current
(
$this
->
createIndexes
([[
'key'
=>
$key
]
+
$indexOptions
],
$commandOptions
));
}
...
...
tests/Collection/CollectionFunctionalTest.php
View file @
4dc895c8
...
...
@@ -10,6 +10,8 @@ use MongoDB\Driver\ReadPreference;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Operation\MapReduce
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
/**
* Functional tests for the Collection class.
...
...
@@ -101,6 +103,35 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this
->
assertEquals
(
$this
->
getNamespace
(),
$this
->
collection
->
getNamespace
());
}
public
function
testCreateIndexSplitsCommandOptions
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.6.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'Sessions are not supported'
);
}
(
new
CommandObserver
)
->
observe
(
function
()
{
$this
->
collection
->
createIndex
(
[
'x'
=>
1
],
[
'maxTimeMS'
=>
1000
,
'session'
=>
$this
->
manager
->
startSession
(),
'sparse'
=>
true
,
'unique'
=>
true
,
'writeConcern'
=>
new
WriteConcern
(
1
),
]
);
},
function
(
stdClass
$command
)
{
$this
->
assertObjectHasAttribute
(
'lsid'
,
$command
);
$this
->
assertObjectHasAttribute
(
'maxTimeMS'
,
$command
);
$this
->
assertObjectHasAttribute
(
'writeConcern'
,
$command
);
$this
->
assertObjectHasAttribute
(
'sparse'
,
$command
->
indexes
[
0
]);
$this
->
assertObjectHasAttribute
(
'unique'
,
$command
->
indexes
[
0
]);
}
);
}
public
function
testDrop
()
{
$writeResult
=
$this
->
collection
->
insertOne
([
'x'
=>
1
]);
...
...
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