Skip to content

Commit df6df1c

Browse files
committed
Merge pull request #533
2 parents 5e1ce36 + 37168ad commit df6df1c

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

docs/includes/apiargs-MongoDBDatabase-method-createCollection-option.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ description: |
99
1010
For replica sets, do not set ``autoIndexId`` to ``false``.
1111
12-
.. deprecated:: 3.2. The ``autoIndexId`` option will be removed in MongoDB 3.4.
12+
.. deprecated:: 1.4
13+
This option has been deprecated since MongoDB 3.2. As of MongoDB 4.0, this
14+
option cannot be ``false`` when creating a replicated collection (i.e. a
15+
collection outside of the ``local`` database in any mongod mode).
1316
interface: phpmethod
1417
operation: ~
1518
optional: true

src/Operation/CreateCollection.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class CreateCollection implements Executable
5353
* of an index on the _id field. For replica sets, this option cannot be
5454
* false. The default is true.
5555
*
56+
* This option has been deprecated since MongoDB 3.2. As of MongoDB 4.0,
57+
* this option cannot be false when creating a replicated collection
58+
* (i.e. a collection outside of the local database in any mongod mode).
59+
*
5660
* * capped (boolean): Specify true to create a capped collection. If set,
5761
* the size option must also be specified. The default is false.
5862
*
@@ -170,6 +174,10 @@ public function __construct($databaseName, $collectionName, array $options = [])
170174
unset($options['writeConcern']);
171175
}
172176

177+
if (isset($options['autoIndexId'])) {
178+
trigger_error('The "autoIndexId" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
179+
}
180+
173181
$this->databaseName = (string) $databaseName;
174182
$this->collectionName = (string) $collectionName;
175183
$this->options = $options;

tests/Operation/CreateCollectionTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,15 @@ public function provideInvalidConstructorOptions()
8282

8383
return $options;
8484
}
85+
86+
public function testAutoIndexIdOptionIsDeprecated()
87+
{
88+
$this->assertDeprecated(function() {
89+
new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), ['autoIndexId' => true]);
90+
});
91+
92+
$this->assertDeprecated(function() {
93+
new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), ['autoIndexId' => false]);
94+
});
95+
}
8596
}

tests/TestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ public function provideInvalidDocumentValues()
5252
return $this->wrapValuesForDataProvider($this->getInvalidDocumentValues());
5353
}
5454

55+
protected function assertDeprecated(callable $execution)
56+
{
57+
$errors = [];
58+
59+
set_error_handler(function($errno, $errstr) use (&$errors) {
60+
$errors[] = $errstr;
61+
}, E_USER_DEPRECATED);
62+
63+
try {
64+
call_user_func($execution);
65+
} finally {
66+
restore_error_handler();
67+
}
68+
69+
$this->assertCount(1, $errors);
70+
}
71+
5572
protected function assertSameDocument($expectedDocument, $actualDocument)
5673
{
5774
$this->assertEquals(

0 commit comments

Comments
 (0)