Skip to content

Commit befa8be

Browse files
committed
PHPLIB-1320: Support "comment" command option in Collection::createIndex()
Adds test coverage for "comment" and "commitQuorum" options.
1 parent be19b52 commit befa8be

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ public function countDocuments($filter = [], array $options = [])
322322
*/
323323
public function createIndex($key, array $options = [])
324324
{
325-
$commandOptionKeys = ['commitQuorum' => 1, 'maxTimeMS' => 1, 'session' => 1, 'writeConcern' => 1];
326-
$indexOptions = array_diff_key($options, $commandOptionKeys);
327-
$commandOptions = array_intersect_key($options, $commandOptionKeys);
325+
$operationOptionKeys = ['comment' => 1, 'commitQuorum' => 1, 'maxTimeMS' => 1, 'session' => 1, 'writeConcern' => 1];
326+
$indexOptions = array_diff_key($options, $operationOptionKeys);
327+
$operationOptions = array_intersect_key($options, $operationOptionKeys);
328328

329-
return current($this->createIndexes([['key' => $key] + $indexOptions], $commandOptions));
329+
return current($this->createIndexes([['key' => $key] + $indexOptions], $operationOptions));
330330
}
331331

332332
/**

tests/Collection/CollectionFunctionalTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,15 @@ public function testAggregateWithinTransaction(): void
132132

133133
public function testCreateIndexSplitsCommandOptions(): void
134134
{
135+
$this->skipIfServerVersion('<', '4.4', 'commitQuorum and comment options are not supported');
136+
135137
(new CommandObserver())->observe(
136138
function (): void {
137139
$this->collection->createIndex(
138140
['x' => 1],
139141
[
142+
'comment' => 'foo',
143+
'commitQuorum' => 'majority',
140144
'maxTimeMS' => 10000,
141145
'session' => $this->manager->startSession(),
142146
'sparse' => true,
@@ -147,6 +151,8 @@ function (): void {
147151
},
148152
function (array $event): void {
149153
$command = $event['started']->getCommand();
154+
$this->assertObjectHasAttribute('comment', $command);
155+
$this->assertObjectHasAttribute('commitQuorum', $command);
150156
$this->assertObjectHasAttribute('lsid', $command);
151157
$this->assertObjectHasAttribute('maxTimeMS', $command);
152158
$this->assertObjectHasAttribute('writeConcern', $command);

0 commit comments

Comments
 (0)