Skip to content

Commit aaee9ad

Browse files
authored
Support encrypted colls in FunctionalTestCase::createCollection (#1820)
1 parent ce083fb commit aaee9ad

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/FunctionalTestCase.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use MongoDB\Driver\ServerApi;
1616
use MongoDB\Driver\WriteConcern;
1717
use MongoDB\Operation\CreateCollection;
18+
use MongoDB\Operation\CreateEncryptedCollection;
1819
use MongoDB\Operation\DatabaseCommand;
1920
use MongoDB\Operation\ListCollections;
2021
use stdClass;
@@ -257,6 +258,9 @@ public static function getModuleInfo(string $row): ?string
257258
* dropped again during tearDown(). If the collection already exists, it
258259
* is dropped and recreated.
259260
*
261+
* This method supports creation of encrypted collections (as indicated by
262+
* the "encryptedFields" option).
263+
*
260264
* A majority write concern is applied by default to ensure that the
261265
* transaction can acquire the required locks.
262266
* See: https://www.mongodb.com/docs/manual/core/transactions/#transactions-and-operations
@@ -265,17 +269,14 @@ public static function getModuleInfo(string $row): ?string
265269
*/
266270
protected function createCollection(string $databaseName, string $collectionName, array $options = []): Collection
267271
{
268-
// See: https://jira.mongodb.org/browse/PHPLIB-1145
269-
if (isset($options['encryptedFields'])) {
270-
throw new InvalidArgumentException('The "encryptedFields" option is not supported by createCollection(). Time to refactor!');
271-
}
272-
273272
// Pass only relevant options to drop the collection in case it already exists
274273
$dropOptions = array_intersect_key($options, ['writeConcern' => 1, 'encryptedFields' => 1]);
275274
$collection = $this->dropCollection($databaseName, $collectionName, $dropOptions);
276275

277276
$options += ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
278-
$operation = new CreateCollection($databaseName, $collectionName, $options);
277+
$operation = isset($options['encryptedFields'])
278+
? new CreateEncryptedCollection($databaseName, $collectionName, $options)
279+
: new CreateCollection($databaseName, $collectionName, $options);
279280
$operation->execute($this->getPrimaryServer());
280281

281282
return $collection;

0 commit comments

Comments
 (0)