Commit 4dc895c8 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge branch 'v1.3'

parents 39057724 7417ecf1
...@@ -277,7 +277,7 @@ class Collection ...@@ -277,7 +277,7 @@ class Collection
* @see CreateIndexes::__construct() for supported command options * @see CreateIndexes::__construct() for supported command options
* @param array|object $key Document containing fields mapped to values, * @param array|object $key Document containing fields mapped to values,
* which denote order or an index type * 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 * @return string The name of the created index
* @throws UnsupportedException if options are not supported by the selected server * @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors * @throws InvalidArgumentException for parameter/option parsing errors
...@@ -285,8 +285,9 @@ class Collection ...@@ -285,8 +285,9 @@ class Collection
*/ */
public function createIndex($key, array $options = []) public function createIndex($key, array $options = [])
{ {
$indexOptions = array_diff_key($options, ['maxTimeMS' => 1, 'writeConcern' => 1]); $commandOptionKeys = ['maxTimeMS' => 1, 'session' => 1, 'writeConcern' => 1];
$commandOptions = array_intersect_key($options, ['maxTimeMS' => 1, 'writeConcern' => 1]); $indexOptions = array_diff_key($options, $commandOptionKeys);
$commandOptions = array_intersect_key($options, $commandOptionKeys);
return current($this->createIndexes([['key' => $key] + $indexOptions], $commandOptions)); return current($this->createIndexes([['key' => $key] + $indexOptions], $commandOptions));
} }
......
...@@ -10,6 +10,8 @@ use MongoDB\Driver\ReadPreference; ...@@ -10,6 +10,8 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\MapReduce; use MongoDB\Operation\MapReduce;
use MongoDB\Tests\CommandObserver;
use stdClass;
/** /**
* Functional tests for the Collection class. * Functional tests for the Collection class.
...@@ -101,6 +103,35 @@ class CollectionFunctionalTest extends FunctionalTestCase ...@@ -101,6 +103,35 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this->assertEquals($this->getNamespace(), $this->collection->getNamespace()); $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() public function testDrop()
{ {
$writeResult = $this->collection->insertOne(['x' => 1]); $writeResult = $this->collection->insertOne(['x' => 1]);
......
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