Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use MongoDB\Driver\ServerApi;
use MongoDB\Driver\WriteConcern;
use MongoDB\Operation\CreateCollection;
use MongoDB\Operation\CreateEncryptedCollection;
use MongoDB\Operation\DatabaseCommand;
use MongoDB\Operation\ListCollections;
use stdClass;
Expand Down Expand Up @@ -258,6 +259,9 @@ public static function getModuleInfo(string $row): ?string
* dropped again during tearDown(). If the collection already exists, it
* is dropped and recreated.
*
* This method supports creation of encrypted collections (as indicated by
* the "encryptedFields" option).
*
* A majority write concern is applied by default to ensure that the
* transaction can acquire the required locks.
* See: https://www.mongodb.com/docs/manual/core/transactions/#transactions-and-operations
Expand All @@ -266,17 +270,14 @@ public static function getModuleInfo(string $row): ?string
*/
protected function createCollection(string $databaseName, string $collectionName, array $options = []): Collection
{
// See: https://jira.mongodb.org/browse/PHPLIB-1145
if (isset($options['encryptedFields'])) {
throw new InvalidArgumentException('The "encryptedFields" option is not supported by createCollection(). Time to refactor!');
}

// Pass only relevant options to drop the collection in case it already exists
$dropOptions = array_intersect_key($options, ['writeConcern' => 1, 'encryptedFields' => 1]);
$collection = $this->dropCollection($databaseName, $collectionName, $dropOptions);

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

return $collection;
Expand Down
Loading