Commit aaec5d5a authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-336: Split out session command option in createIndex()

parent 99453efa
...@@ -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));
} }
......
...@@ -9,6 +9,8 @@ use MongoDB\Driver\ReadConcern; ...@@ -9,6 +9,8 @@ use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
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.
...@@ -100,6 +102,35 @@ class CollectionFunctionalTest extends FunctionalTestCase ...@@ -100,6 +102,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