Skip to content

Commit 13f0666

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

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,19 @@ public function testAggregateWithinTransaction(): void
132132

133133
public function testCreateIndexSplitsCommandOptions(): void
134134
{
135+
$this->skipIfServerVersion('<', '4.4', 'commitQuorum and comment options are not supported');
136+
137+
if ($this->isStandalone()) {
138+
$this->markTestSkipped('commitQuorum is not supported');
139+
}
140+
135141
(new CommandObserver())->observe(
136142
function (): void {
137143
$this->collection->createIndex(
138144
['x' => 1],
139145
[
146+
'comment' => 'foo',
147+
'commitQuorum' => 'majority',
140148
'maxTimeMS' => 10000,
141149
'session' => $this->manager->startSession(),
142150
'sparse' => true,
@@ -147,6 +155,8 @@ function (): void {
147155
},
148156
function (array $event): void {
149157
$command = $event['started']->getCommand();
158+
$this->assertObjectHasAttribute('comment', $command);
159+
$this->assertObjectHasAttribute('commitQuorum', $command);
150160
$this->assertObjectHasAttribute('lsid', $command);
151161
$this->assertObjectHasAttribute('maxTimeMS', $command);
152162
$this->assertObjectHasAttribute('writeConcern', $command);

0 commit comments

Comments
 (0)