From f4962c994a7cf19867370f9791424ddceb5a2d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 1 Oct 2024 12:26:11 +0200 Subject: [PATCH] PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) --- UPGRADE-2.0.md | 14 +++++ psalm-baseline.xml | 15 ----- src/Client.php | 15 +---- src/Collection.php | 30 +++------- src/Database.php | 60 ++++--------------- src/Operation/CreateCollection.php | 19 +----- src/Operation/CreateEncryptedCollection.php | 18 +++--- src/Operation/DropCollection.php | 26 ++------ src/Operation/DropDatabase.php | 21 +------ src/Operation/DropEncryptedCollection.php | 9 +-- src/Operation/DropIndexes.php | 20 +------ src/Operation/RenameCollection.php | 20 +------ tests/ClientFunctionalTest.php | 3 +- tests/Collection/CollectionFunctionalTest.php | 9 +-- .../CollectionManagementFunctionalTest.php | 21 +++---- tests/Database/DatabaseFunctionalTest.php | 12 ++-- tests/FunctionalTestCase.php | 5 +- tests/Operation/CreateCollectionTest.php | 1 - ...reateEncryptedCollectionFunctionalTest.php | 15 ++--- .../DropCollectionFunctionalTest.php | 9 +-- tests/Operation/DropCollectionTest.php | 1 - tests/Operation/DropDatabaseTest.php | 1 - tests/Operation/DropIndexesFunctionalTest.php | 6 +- tests/Operation/DropIndexesTest.php | 1 - .../RenameCollectionFunctionalTest.php | 3 +- tests/Operation/RenameCollectionTest.php | 1 - ...rose21_AutomaticDataEncryptionKeysTest.php | 6 +- 27 files changed, 89 insertions(+), 272 deletions(-) diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index 8b3562013..0492cef9e 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -23,6 +23,20 @@ UPGRADE FROM 1.x to 2.0 * `MongoDB\Model\IndexInfoIteratorIterator` * `MongoDB\Operation\Executable` +Operations with no result +------------------------- + +The following operations no longer return the raw command result. The return +type changed to `void`. In case of an error, an exception is thrown. + + * `MongoDB\Client`: `dropDatabase` + * `MongoDB\Collection`: `drop`, `dropIndex`, `dropIndexes`, `dropSearchIndex`, `rename` + * `MongoDB\Database`: `createCollection`, `drop`, `dropCollection`, `renameCollection` + * `MongoDB\Database::createEncryptedCollection()` returns the list of encrypted fields + +If you still need to access the raw command result, you can use a +[`CommandSubscriber`](https://www.php.net/manual/en/class.mongodb-driver-monitoring-commandsubscriber.php). + GridFS ------ diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 541a5380f..6521b8544 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -519,9 +519,6 @@ - - options['typeMap']]]> - @@ -593,9 +590,6 @@ - - options['typeMap']]]> - @@ -606,9 +600,6 @@ - - options['typeMap']]]> - @@ -621,9 +612,6 @@ - - options['typeMap']]]> - @@ -755,9 +743,6 @@ - - options['typeMap']]]> - diff --git a/src/Client.php b/src/Client.php index 7141b7e72..43856439b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -49,10 +49,6 @@ use function array_diff_key; use function is_array; use function is_string; -use function sprintf; -use function trigger_error; - -use const E_USER_DEPRECATED; class Client { @@ -217,19 +213,12 @@ public function createClientEncryption(array $options): ClientEncryption * @see DropDatabase::__construct() for supported options * @param string $databaseName Database name * @param array $options Additional options - * @return array|object Command result document * @throws UnsupportedException if options are unsupported on the selected server * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function dropDatabase(string $databaseName, array $options = []): array|object + public function dropDatabase(string $databaseName, array $options = []): void { - if (! isset($options['typeMap'])) { - $options['typeMap'] = $this->typeMap; - } else { - @trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED); - } - $server = select_server_for_write($this->manager, $options); if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { @@ -238,7 +227,7 @@ public function dropDatabase(string $databaseName, array $options = []): array|o $operation = new DropDatabase($databaseName, $options); - return $operation->execute($server); + $operation->execute($server); } /** diff --git a/src/Collection.php b/src/Collection.php index 86aeb17fa..23072b9d3 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -501,15 +501,13 @@ public function distinct(string $fieldName, array|object $filter = [], array $op * * @see DropCollection::__construct() for supported options * @param array $options Additional options - * @return array|object Command result document * @throws UnsupportedException if options are not supported by the selected server * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function drop(array $options = []): array|object + public function drop(array $options = []): void { $options = $this->inheritWriteOptions($options); - $options = $this->inheritTypeMap($options, __FUNCTION__); $server = select_server_for_write($this->manager, $options); @@ -522,7 +520,7 @@ public function drop(array $options = []): array|object ? new DropEncryptedCollection($this->databaseName, $this->collectionName, $options) : new DropCollection($this->databaseName, $this->collectionName, $options); - return $operation->execute($server); + $operation->execute($server); } /** @@ -531,12 +529,11 @@ public function drop(array $options = []): array|object * @see DropIndexes::__construct() for supported options * @param string|IndexInfo $indexName Index name or model object * @param array $options Additional options - * @return array|object Command result document * @throws UnsupportedException if options are not supported by the selected server * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function dropIndex(string|IndexInfo $indexName, array $options = []): array|object + public function dropIndex(string|IndexInfo $indexName, array $options = []): void { $indexName = (string) $indexName; @@ -545,11 +542,10 @@ public function dropIndex(string|IndexInfo $indexName, array $options = []): arr } $options = $this->inheritWriteOptions($options); - $options = $this->inheritTypeMap($options, __FUNCTION__); $operation = new DropIndexes($this->databaseName, $this->collectionName, $indexName, $options); - return $operation->execute(select_server_for_write($this->manager, $options)); + $operation->execute(select_server_for_write($this->manager, $options)); } /** @@ -557,19 +553,17 @@ public function dropIndex(string|IndexInfo $indexName, array $options = []): arr * * @see DropIndexes::__construct() for supported options * @param array $options Additional options - * @return array|object Command result document * @throws UnsupportedException if options are not supported by the selected server * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function dropIndexes(array $options = []): array|object + public function dropIndexes(array $options = []): void { $options = $this->inheritWriteOptions($options); - $options = $this->inheritTypeMap($options, __FUNCTION__); $operation = new DropIndexes($this->databaseName, $this->collectionName, '*', $options); - return $operation->execute(select_server_for_write($this->manager, $options)); + $operation->execute(select_server_for_write($this->manager, $options)); } /** @@ -909,23 +903,21 @@ public function listSearchIndexes(array $options = []): Iterator * @param string $toCollectionName New name of the collection * @param string|null $toDatabaseName New database name of the collection. Defaults to the original database. * @param array $options Additional options - * @return array|object Command result document * @throws UnsupportedException if options are not supported by the selected server * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function rename(string $toCollectionName, ?string $toDatabaseName = null, array $options = []): array|object + public function rename(string $toCollectionName, ?string $toDatabaseName = null, array $options = []): void { if (! isset($toDatabaseName)) { $toDatabaseName = $this->databaseName; } $options = $this->inheritWriteOptions($options); - $options = $this->inheritTypeMap($options); $operation = new RenameCollection($this->databaseName, $this->collectionName, $toDatabaseName, $toCollectionName, $options); - return $operation->execute(select_server_for_write($this->manager, $options)); + $operation->execute(select_server_for_write($this->manager, $options)); } /** @@ -1127,12 +1119,8 @@ private function inheritReadPreference(array $options): array return $options; } - private function inheritTypeMap(array $options, ?string $deprecatedFunction = null): array + private function inheritTypeMap(array $options): array { - if ($deprecatedFunction !== null && isset($options['typeMap'])) { - @trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', $deprecatedFunction), E_USER_DEPRECATED); - } - // Only inherit the type map if no codec is used if (! isset($options['typeMap']) && ! isset($options['codec'])) { $options['typeMap'] = $this->typeMap; diff --git a/src/Database.php b/src/Database.php index 623d9a624..08817dbba 100644 --- a/src/Database.php +++ b/src/Database.php @@ -54,11 +54,7 @@ use Throwable; use function is_array; -use function sprintf; use function strlen; -use function trigger_error; - -use const E_USER_DEPRECATED; class Database { @@ -274,19 +270,12 @@ public function command(array|object $command, array $options = []): CursorInter * @see CreateCollection::__construct() for supported options * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#create-collection-helper * @see https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manage-collections/ - * @return array|object Command result document * @throws UnsupportedException if options are not supported by the selected server * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function createCollection(string $collectionName, array $options = []): array|object + public function createCollection(string $collectionName, array $options = []): void { - if (! isset($options['typeMap'])) { - $options['typeMap'] = $this->typeMap; - } else { - @trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED); - } - if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { $options['writeConcern'] = $this->writeConcern; } @@ -301,7 +290,7 @@ public function createCollection(string $collectionName, array $options = []): a $server = select_server_for_write($this->manager, $options); - return $operation->execute($server); + $operation->execute($server); } /** @@ -319,19 +308,13 @@ public function createCollection(string $collectionName, array $options = []): a * getPrevious() and getEncryptedFields() methods, respectively. * * @see CreateCollection::__construct() for supported options - * @return array A tuple containing the command result document from creating the collection and the modified "encryptedFields" option + * @return array The modified "encryptedFields" option * @throws InvalidArgumentException for parameter/option parsing errors * @throws CreateEncryptedCollectionException for any errors creating data keys or creating the collection * @throws UnsupportedException if Queryable Encryption is not supported by the selected server */ public function createEncryptedCollection(string $collectionName, ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey, array $options): array { - if (! isset($options['typeMap'])) { - $options['typeMap'] = $this->typeMap; - } else { - @trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED); - } - if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { $options['writeConcern'] = $this->writeConcern; } @@ -340,10 +323,10 @@ public function createEncryptedCollection(string $collectionName, ClientEncrypti $server = select_server_for_write($this->manager, $options); try { - $operation->createDataKeys($clientEncryption, $kmsProvider, $masterKey, $encryptedFields); - $result = $operation->execute($server); + $encryptedFields = $operation->createDataKeys($clientEncryption, $kmsProvider, $masterKey); + $operation->execute($server); - return [$result, $encryptedFields]; + return $encryptedFields; } catch (Throwable $e) { throw new CreateEncryptedCollectionException($e, $encryptedFields ?? []); } @@ -354,19 +337,12 @@ public function createEncryptedCollection(string $collectionName, ClientEncrypti * * @see DropDatabase::__construct() for supported options * @param array $options Additional options - * @return array|object Command result document * @throws UnsupportedException if options are unsupported on the selected server * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function drop(array $options = []): array|object + public function drop(array $options = []): void { - if (! isset($options['typeMap'])) { - $options['typeMap'] = $this->typeMap; - } else { - @trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED); - } - $server = select_server_for_write($this->manager, $options); if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { @@ -375,7 +351,7 @@ public function drop(array $options = []): array|object $operation = new DropDatabase($this->databaseName, $options); - return $operation->execute($server); + $operation->execute($server); } /** @@ -384,19 +360,12 @@ public function drop(array $options = []): array|object * @see DropCollection::__construct() for supported options * @param string $collectionName Collection name * @param array $options Additional options - * @return array|object Command result document * @throws UnsupportedException if options are unsupported on the selected server * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function dropCollection(string $collectionName, array $options = []): array|object + public function dropCollection(string $collectionName, array $options = []): void { - if (! isset($options['typeMap'])) { - $options['typeMap'] = $this->typeMap; - } else { - @trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED); - } - $server = select_server_for_write($this->manager, $options); if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { @@ -412,7 +381,7 @@ public function dropCollection(string $collectionName, array $options = []): arr ? new DropEncryptedCollection($this->databaseName, $collectionName, $options) : new DropCollection($this->databaseName, $collectionName, $options); - return $operation->execute($server); + $operation->execute($server); } /** @@ -534,21 +503,16 @@ public function modifyCollection(string $collectionName, array $collectionOption * @param string $toCollectionName New name of the collection * @param string|null $toDatabaseName New database name of the collection. Defaults to the original database. * @param array $options Additional options - * @return array|object Command result document * @throws UnsupportedException if options are unsupported on the selected server * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function renameCollection(string $fromCollectionName, string $toCollectionName, ?string $toDatabaseName = null, array $options = []): array|object + public function renameCollection(string $fromCollectionName, string $toCollectionName, ?string $toDatabaseName = null, array $options = []): void { if (! isset($toDatabaseName)) { $toDatabaseName = $this->databaseName; } - if (! isset($options['typeMap'])) { - $options['typeMap'] = $this->typeMap; - } - $server = select_server_for_write($this->manager, $options); if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { @@ -557,7 +521,7 @@ public function renameCollection(string $fromCollectionName, string $toCollectio $operation = new RenameCollection($this->databaseName, $fromCollectionName, $toDatabaseName, $toCollectionName, $options); - return $operation->execute($server); + $operation->execute($server); } /** diff --git a/src/Operation/CreateCollection.php b/src/Operation/CreateCollection.php index 0e7918f37..7f125801b 100644 --- a/src/Operation/CreateCollection.php +++ b/src/Operation/CreateCollection.php @@ -24,7 +24,6 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; -use function current; use function is_array; use function is_bool; use function is_integer; @@ -112,9 +111,6 @@ final class CreateCollection * * This is not supported for servers versions < 5.0. * - * * typeMap (array): Type map for BSON deserialization. This will only be - * used for the returned command result document. - * * * validationAction (string): Validation action. * * * validationLevel (string): Validation level. @@ -199,10 +195,6 @@ public function __construct(private string $databaseName, private string $collec throw InvalidArgumentException::expectedDocumentType('"timeseries" option', $this->options['timeseries']); } - if (isset($this->options['typeMap']) && ! is_array($this->options['typeMap'])) { - throw InvalidArgumentException::invalidType('"typeMap" option', $this->options['typeMap'], 'array'); - } - if (isset($this->options['validationAction']) && ! is_string($this->options['validationAction'])) { throw InvalidArgumentException::invalidType('"validationAction" option', $this->options['validationAction'], 'string'); } @@ -239,18 +231,11 @@ public function __construct(private string $databaseName, private string $collec /** * Execute the operation. * - * @return array|object Command result document * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function execute(Server $server): array|object + public function execute(Server $server): void { - $cursor = $server->executeWriteCommand($this->databaseName, $this->createCommand(), $this->createOptions()); - - if (isset($this->options['typeMap'])) { - $cursor->setTypeMap($this->options['typeMap']); - } - - return current($cursor->toArray()); + $server->executeWriteCommand($this->databaseName, $this->createCommand(), $this->createOptions()); } /** diff --git a/src/Operation/CreateEncryptedCollection.php b/src/Operation/CreateEncryptedCollection.php index 7c1075c29..c30db34af 100644 --- a/src/Operation/CreateEncryptedCollection.php +++ b/src/Operation/CreateEncryptedCollection.php @@ -97,21 +97,20 @@ public function __construct(private string $databaseName, private string $collec * "encryptedFields" option and reconstruct the internal CreateCollection * operation used for creating the encrypted collection. * - * The $encryptedFields reference parameter may be used to determine which - * data keys have been created. + * Returns the data keys that have been created. * * @see \MongoDB\Database::createEncryptedCollection() * @see https://www.php.net/manual/en/mongodb-driver-clientencryption.createdatakey.php * @throws DriverRuntimeException for errors creating a data key */ - public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey, ?array &$encryptedFields = null): void + public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey): array { /** @psalm-var array{fields: list|Serializable|PackedArray} */ $encryptedFields = document_to_array($this->options['encryptedFields']); // NOP if there are no fields to examine if (! isset($encryptedFields['fields'])) { - return; + return $encryptedFields; } // Allow PackedArray or Serializable object for the fields array @@ -128,7 +127,7 @@ public function createDataKeys(ClientEncryption $clientEncryption, string $kmsPr // Skip invalid types and defer to the server to raise an error if (! is_array($encryptedFields['fields'])) { - return; + return $encryptedFields; } $createDataKeyArgs = [ @@ -152,14 +151,15 @@ public function createDataKeys(ClientEncryption $clientEncryption, string $kmsPr $this->options['encryptedFields'] = $encryptedFields; $this->createCollection = new CreateCollection($this->databaseName, $this->collectionName, $this->options); + + return $encryptedFields; } /** - * @return array|object Command result document from creating the encrypted collection * @throws DriverRuntimeException for other driver errors (e.g. connection errors) * @throws UnsupportedException if the server does not support Queryable Encryption */ - public function execute(Server $server): array|object + public function execute(Server $server): void { if (! server_supports_feature($server, self::WIRE_VERSION_FOR_QUERYABLE_ENCRYPTION_V2)) { throw new UnsupportedException('Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption.'); @@ -169,10 +169,8 @@ public function execute(Server $server): array|object $createMetadataCollection->execute($server); } - $result = $this->createCollection->execute($server); + $this->createCollection->execute($server); $this->createSafeContentIndex->execute($server); - - return $result; } } diff --git a/src/Operation/DropCollection.php b/src/Operation/DropCollection.php index c5878359e..0c520801c 100644 --- a/src/Operation/DropCollection.php +++ b/src/Operation/DropCollection.php @@ -26,9 +26,6 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\UnsupportedException; -use function current; -use function is_array; - /** * Operation for the drop command. * @@ -51,9 +48,6 @@ final class DropCollection * * * session (MongoDB\Driver\Session): Client session. * - * * typeMap (array): Type map for BSON deserialization. This will be used - * for the returned command result document. - * * * writeConcern (MongoDB\Driver\WriteConcern): Write concern. * * @param string $databaseName Database name @@ -67,10 +61,6 @@ public function __construct(private string $databaseName, private string $collec throw InvalidArgumentException::invalidType('"session" option', $this->options['session'], Session::class); } - if (isset($this->options['typeMap']) && ! is_array($this->options['typeMap'])) { - throw InvalidArgumentException::invalidType('"typeMap" option', $this->options['typeMap'], 'array'); - } - if (isset($this->options['writeConcern']) && ! $this->options['writeConcern'] instanceof WriteConcern) { throw InvalidArgumentException::invalidType('"writeConcern" option', $this->options['writeConcern'], WriteConcern::class); } @@ -83,11 +73,10 @@ public function __construct(private string $databaseName, private string $collec /** * Execute the operation. * - * @return array|object Command result document * @throws UnsupportedException if write concern is used and unsupported * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function execute(Server $server): array|object + public function execute(Server $server): void { $inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction(); if ($inTransaction && isset($this->options['writeConcern'])) { @@ -95,23 +84,16 @@ public function execute(Server $server): array|object } try { - $cursor = $server->executeWriteCommand($this->databaseName, $this->createCommand(), $this->createOptions()); + $server->executeWriteCommand($this->databaseName, $this->createCommand(), $this->createOptions()); } catch (CommandException $e) { /* The server may return an error if the collection does not exist. - * Check for an error code and return the command reply instead of - * throwing. */ + * Ignore the exception to make the drop operation idempotent */ if ($e->getCode() === self::ERROR_CODE_NAMESPACE_NOT_FOUND) { - return $e->getResultDocument(); + return; } throw $e; } - - if (isset($this->options['typeMap'])) { - $cursor->setTypeMap($this->options['typeMap']); - } - - return current($cursor->toArray()); } /** diff --git a/src/Operation/DropDatabase.php b/src/Operation/DropDatabase.php index 3f9d7756f..1cc71a4c0 100644 --- a/src/Operation/DropDatabase.php +++ b/src/Operation/DropDatabase.php @@ -24,9 +24,6 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; -use function current; -use function is_array; - /** * Operation for the dropDatabase command. * @@ -47,9 +44,6 @@ final class DropDatabase * * * session (MongoDB\Driver\Session): Client session. * - * * typeMap (array): Type map for BSON deserialization. This will be used - * for the returned command result document. - * * * writeConcern (MongoDB\Driver\WriteConcern): Write concern. * * @param string $databaseName Database name @@ -62,10 +56,6 @@ public function __construct(private string $databaseName, private array $options throw InvalidArgumentException::invalidType('"session" option', $this->options['session'], Session::class); } - if (isset($this->options['typeMap']) && ! is_array($this->options['typeMap'])) { - throw InvalidArgumentException::invalidType('"typeMap" option', $this->options['typeMap'], 'array'); - } - if (isset($this->options['writeConcern']) && ! $this->options['writeConcern'] instanceof WriteConcern) { throw InvalidArgumentException::invalidType('"writeConcern" option', $this->options['writeConcern'], WriteConcern::class); } @@ -78,18 +68,11 @@ public function __construct(private string $databaseName, private array $options /** * Execute the operation. * - * @return array|object Command result document * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function execute(Server $server): array|object + public function execute(Server $server): void { - $cursor = $server->executeWriteCommand($this->databaseName, $this->createCommand(), $this->createOptions()); - - if (isset($this->options['typeMap'])) { - $cursor->setTypeMap($this->options['typeMap']); - } - - return current($cursor->toArray()); + $server->executeWriteCommand($this->databaseName, $this->createCommand(), $this->createOptions()); } /** diff --git a/src/Operation/DropEncryptedCollection.php b/src/Operation/DropEncryptedCollection.php index 52fa1b8e3..6caa07d2a 100644 --- a/src/Operation/DropEncryptedCollection.php +++ b/src/Operation/DropEncryptedCollection.php @@ -84,16 +84,13 @@ public function __construct(string $databaseName, string $collectionName, array $this->dropCollection = new DropCollection($databaseName, $collectionName, $options); } - /** - * @return array|object Command result document from dropping the encrypted collection - * @throws DriverRuntimeException for other driver errors (e.g. connection errors) - */ - public function execute(Server $server): array|object + /** @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ + public function execute(Server $server): void { foreach ($this->dropMetadataCollections as $dropMetadataCollection) { $dropMetadataCollection->execute($server); } - return $this->dropCollection->execute($server); + $this->dropCollection->execute($server); } } diff --git a/src/Operation/DropIndexes.php b/src/Operation/DropIndexes.php index 152977445..46a89f22f 100644 --- a/src/Operation/DropIndexes.php +++ b/src/Operation/DropIndexes.php @@ -25,8 +25,6 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\UnsupportedException; -use function current; -use function is_array; use function is_integer; /** @@ -51,9 +49,6 @@ final class DropIndexes * * * session (MongoDB\Driver\Session): Client session. * - * * typeMap (array): Type map for BSON deserialization. This will be used - * for the returned command result document. - * * * writeConcern (MongoDB\Driver\WriteConcern): Write concern. * * @param string $databaseName Database name @@ -76,10 +71,6 @@ public function __construct(private string $databaseName, private string $collec throw InvalidArgumentException::invalidType('"session" option', $this->options['session'], Session::class); } - if (isset($this->options['typeMap']) && ! is_array($this->options['typeMap'])) { - throw InvalidArgumentException::invalidType('"typeMap" option', $this->options['typeMap'], 'array'); - } - if (isset($this->options['writeConcern']) && ! $this->options['writeConcern'] instanceof WriteConcern) { throw InvalidArgumentException::invalidType('"writeConcern" option', $this->options['writeConcern'], WriteConcern::class); } @@ -92,24 +83,17 @@ public function __construct(private string $databaseName, private string $collec /** * Execute the operation. * - * @return array|object Command result document * @throws UnsupportedException if write concern is used and unsupported * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function execute(Server $server): array|object + public function execute(Server $server): void { $inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction(); if ($inTransaction && isset($this->options['writeConcern'])) { throw UnsupportedException::writeConcernNotSupportedInTransaction(); } - $cursor = $server->executeWriteCommand($this->databaseName, $this->createCommand(), $this->createOptions()); - - if (isset($this->options['typeMap'])) { - $cursor->setTypeMap($this->options['typeMap']); - } - - return current($cursor->toArray()); + $server->executeWriteCommand($this->databaseName, $this->createCommand(), $this->createOptions()); } /** diff --git a/src/Operation/RenameCollection.php b/src/Operation/RenameCollection.php index 5804bb474..b3848c67e 100644 --- a/src/Operation/RenameCollection.php +++ b/src/Operation/RenameCollection.php @@ -25,8 +25,6 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\UnsupportedException; -use function current; -use function is_array; use function is_bool; /** @@ -53,9 +51,6 @@ final class RenameCollection * * * session (MongoDB\Driver\Session): Client session. * - * * typeMap (array): Type map for BSON deserialization. This will be used - * for the returned command result document. - * * * writeConcern (MongoDB\Driver\WriteConcern): Write concern. * * * dropTarget (boolean): If true, MongoDB will drop the target before @@ -74,10 +69,6 @@ public function __construct(string $fromDatabaseName, string $fromCollectionName throw InvalidArgumentException::invalidType('"session" option', $this->options['session'], Session::class); } - if (isset($this->options['typeMap']) && ! is_array($this->options['typeMap'])) { - throw InvalidArgumentException::invalidType('"typeMap" option', $this->options['typeMap'], 'array'); - } - if (isset($this->options['writeConcern']) && ! $this->options['writeConcern'] instanceof WriteConcern) { throw InvalidArgumentException::invalidType('"writeConcern" option', $this->options['writeConcern'], WriteConcern::class); } @@ -97,24 +88,17 @@ public function __construct(string $fromDatabaseName, string $fromCollectionName /** * Execute the operation. * - * @return array|object Command result document * @throws UnsupportedException if write concern is used and unsupported * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ - public function execute(Server $server): array|object + public function execute(Server $server): void { $inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction(); if ($inTransaction && isset($this->options['writeConcern'])) { throw UnsupportedException::writeConcernNotSupportedInTransaction(); } - $cursor = $server->executeWriteCommand('admin', $this->createCommand(), $this->createOptions()); - - if (isset($this->options['typeMap'])) { - $cursor->setTypeMap($this->options['typeMap']); - } - - return current($cursor->toArray()); + $server->executeWriteCommand('admin', $this->createCommand(), $this->createOptions()); } /** diff --git a/tests/ClientFunctionalTest.php b/tests/ClientFunctionalTest.php index aa10d4a19..393f23607 100644 --- a/tests/ClientFunctionalTest.php +++ b/tests/ClientFunctionalTest.php @@ -47,8 +47,7 @@ public function testDropDatabase(): void $writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite); $this->assertEquals(1, $writeResult->getInsertedCount()); - $commandResult = $this->client->dropDatabase($this->getDatabaseName()); - $this->assertCommandSucceeded($commandResult); + $this->client->dropDatabase($this->getDatabaseName()); $this->assertCollectionCount($this->getNamespace(), 0); } diff --git a/tests/Collection/CollectionFunctionalTest.php b/tests/Collection/CollectionFunctionalTest.php index 4a75c8525..0578d8bd5 100644 --- a/tests/Collection/CollectionFunctionalTest.php +++ b/tests/Collection/CollectionFunctionalTest.php @@ -251,8 +251,7 @@ public function testDrop(): void $writeResult = $this->collection->insertOne(['x' => 1]); $this->assertEquals(1, $writeResult->getInsertedCount()); - $commandResult = $this->collection->drop(); - $this->assertCommandSucceeded($commandResult); + $this->collection->drop(); $this->assertCollectionDoesNotExist($this->getCollectionName()); } @@ -328,8 +327,7 @@ public function testRenameToSameDatabase(): void $writeResult = $this->collection->insertOne(['_id' => 1]); $this->assertEquals(1, $writeResult->getInsertedCount()); - $commandResult = $this->collection->rename($toCollectionName, null, ['dropTarget' => true]); - $this->assertCommandSucceeded($commandResult); + $this->collection->rename($toCollectionName, null, ['dropTarget' => true]); $this->assertCollectionDoesNotExist($this->getCollectionName()); $this->assertCollectionExists($toCollectionName); @@ -357,8 +355,7 @@ public function testRenameToDifferentDatabase(): void $writeResult = $this->collection->insertOne(['_id' => 1]); $this->assertEquals(1, $writeResult->getInsertedCount()); - $commandResult = $this->collection->rename($toCollectionName, $toDatabaseName); - $this->assertCommandSucceeded($commandResult); + $this->collection->rename($toCollectionName, $toDatabaseName); $this->assertCollectionDoesNotExist($this->getCollectionName()); $this->assertCollectionExists($toCollectionName, $toDatabaseName); diff --git a/tests/Database/CollectionManagementFunctionalTest.php b/tests/Database/CollectionManagementFunctionalTest.php index e3a3ca5fa..dc5b49974 100644 --- a/tests/Database/CollectionManagementFunctionalTest.php +++ b/tests/Database/CollectionManagementFunctionalTest.php @@ -16,8 +16,7 @@ public function testCreateCollection(): void $that = $this; $basicCollectionName = $this->getCollectionName() . '.basic'; - $commandResult = $this->database->createCollection($basicCollectionName); - $this->assertCommandSucceeded($commandResult); + $this->database->createCollection($basicCollectionName); $this->assertCollectionExists($basicCollectionName, null, function (CollectionInfo $info) use ($that): void { $that->assertFalse($info->isCapped()); }); @@ -29,8 +28,7 @@ public function testCreateCollection(): void 'size' => 1_048_576, ]; - $commandResult = $this->database->createCollection($cappedCollectionName, $cappedCollectionOptions); - $this->assertCommandSucceeded($commandResult); + $this->database->createCollection($cappedCollectionName, $cappedCollectionOptions); $this->assertCollectionExists($cappedCollectionName, null, function (CollectionInfo $info) use ($that): void { $that->assertTrue($info->isCapped()); $that->assertEquals(100, $info->getCappedMax()); @@ -46,15 +44,13 @@ public function testDropCollection(): void $writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite); $this->assertEquals(1, $writeResult->getInsertedCount()); - $commandResult = $this->database->dropCollection($this->getCollectionName()); - $this->assertCommandSucceeded($commandResult); + $this->database->dropCollection($this->getCollectionName()); $this->assertCollectionCount($this->getNamespace(), 0); } public function testListCollections(): void { - $commandResult = $this->database->createCollection($this->getCollectionName()); - $this->assertCommandSucceeded($commandResult); + $this->database->createCollection($this->getCollectionName()); $collections = $this->database->listCollections(); $this->assertInstanceOf(Iterator::class, $collections); @@ -66,8 +62,7 @@ public function testListCollections(): void public function testListCollectionsWithFilter(): void { - $commandResult = $this->database->createCollection($this->getCollectionName()); - $this->assertCommandSucceeded($commandResult); + $this->database->createCollection($this->getCollectionName()); $collectionName = $this->getCollectionName(); $options = ['filter' => ['name' => $collectionName]]; @@ -83,8 +78,7 @@ public function testListCollectionsWithFilter(): void public function testListCollectionNames(): void { - $commandResult = $this->database->createCollection($this->getCollectionName()); - $this->assertCommandSucceeded($commandResult); + $this->database->createCollection($this->getCollectionName()); $collections = $this->database->listCollectionNames(); @@ -95,8 +89,7 @@ public function testListCollectionNames(): void public function testListCollectionNamesWithFilter(): void { - $commandResult = $this->database->createCollection($this->getCollectionName()); - $this->assertCommandSucceeded($commandResult); + $this->database->createCollection($this->getCollectionName()); $collectionName = $this->getCollectionName(); $options = ['filter' => ['name' => $collectionName]]; diff --git a/tests/Database/DatabaseFunctionalTest.php b/tests/Database/DatabaseFunctionalTest.php index d6e3ff5b7..2da985aef 100644 --- a/tests/Database/DatabaseFunctionalTest.php +++ b/tests/Database/DatabaseFunctionalTest.php @@ -139,8 +139,7 @@ public function testDrop(): void $writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite); $this->assertEquals(1, $writeResult->getInsertedCount()); - $commandResult = $this->database->drop(); - $this->assertCommandSucceeded($commandResult); + $this->database->drop(); $this->assertCollectionCount($this->getNamespace(), 0); } @@ -152,8 +151,7 @@ public function testDropCollection(): void $writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite); $this->assertEquals(1, $writeResult->getInsertedCount()); - $commandResult = $this->database->dropCollection($this->getCollectionName()); - $this->assertCommandSucceeded($commandResult); + $this->database->dropCollection($this->getCollectionName()); $this->assertCollectionDoesNotExist($this->getCollectionName()); } @@ -219,13 +217,12 @@ public function testRenameCollectionToSameDatabase(): void $writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite); $this->assertEquals(1, $writeResult->getInsertedCount()); - $commandResult = $this->database->renameCollection( + $this->database->renameCollection( $this->getCollectionName(), $toCollectionName, null, ['dropTarget' => true], ); - $this->assertCommandSucceeded($commandResult); $this->assertCollectionDoesNotExist($this->getCollectionName()); $this->assertCollectionExists($toCollectionName); @@ -256,12 +253,11 @@ public function testRenameCollectionToDifferentDatabase(): void $writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite); $this->assertEquals(1, $writeResult->getInsertedCount()); - $commandResult = $this->database->renameCollection( + $this->database->renameCollection( $this->getCollectionName(), $toCollectionName, $toDatabaseName, ); - $this->assertCommandSucceeded($commandResult); $this->assertCollectionDoesNotExist($this->getCollectionName()); $this->assertCollectionExists($toCollectionName, $toDatabaseName); diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php index 07c03e45e..d121cc0d4 100644 --- a/tests/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -242,10 +242,7 @@ public function configureFailPoint(array|stdClass $command, ?Server $server = nu $failPointServer = $server ?: $this->getPrimaryServer(); $operation = new DatabaseCommand('admin', $command); - $cursor = $operation->execute($failPointServer); - $result = $cursor->toArray()[0]; - - $this->assertCommandSucceeded($result); + $operation->execute($failPointServer); // Record the fail point so it can be disabled during tearDown() $this->configuredFailPoints[] = [$command->configureFailPoint, $failPointServer]; diff --git a/tests/Operation/CreateCollectionTest.php b/tests/Operation/CreateCollectionTest.php index 21a280032..6ed8a1f47 100644 --- a/tests/Operation/CreateCollectionTest.php +++ b/tests/Operation/CreateCollectionTest.php @@ -41,7 +41,6 @@ public static function provideInvalidConstructorOptions() 'size' => self::getInvalidIntegerValues(), 'storageEngine' => self::getInvalidDocumentValues(), 'timeseries' => self::getInvalidDocumentValues(), - 'typeMap' => self::getInvalidArrayValues(), 'validationAction' => self::getInvalidStringValues(), 'validationLevel' => self::getInvalidStringValues(), 'validator' => self::getInvalidDocumentValues(), diff --git a/tests/Operation/CreateEncryptedCollectionFunctionalTest.php b/tests/Operation/CreateEncryptedCollectionFunctionalTest.php index 8d4978639..69381620c 100644 --- a/tests/Operation/CreateEncryptedCollectionFunctionalTest.php +++ b/tests/Operation/CreateEncryptedCollectionFunctionalTest.php @@ -64,11 +64,10 @@ public function testCreateDataKeysNopIfFieldsIsMissing($input, array $expectedOu ['encryptedFields' => $input], ); - $operation->createDataKeys( + $encryptedFieldsOutput = $operation->createDataKeys( $this->clientEncryption, 'local', null, - $encryptedFieldsOutput, ); $this->assertSame($expectedOutput, $encryptedFieldsOutput); @@ -95,11 +94,10 @@ public function testCreateDataKeysNopIfFieldsHasInvalidType($input, array $expec ['encryptedFields' => $input], ); - $operation->createDataKeys( + $encryptedFieldsOutput = $operation->createDataKeys( $this->clientEncryption, 'local', null, - $encryptedFieldsOutput, ); $this->assertSame($expectedOutput, $encryptedFieldsOutput); @@ -126,11 +124,10 @@ public function testCreateDataKeysSkipsNonDocumentFields($input, array $expected ['encryptedFields' => $input], ); - $operation->createDataKeys( + $encryptedFieldsOutput = $operation->createDataKeys( $this->clientEncryption, 'local', null, - $encryptedFieldsOutput, ); $this->assertSame($expectedOutput, $encryptedFieldsOutput); @@ -159,11 +156,10 @@ public function testCreateDataKeysDoesNotModifyOriginalEncryptedFieldsOption(): ['encryptedFields' => $originalEncryptedFields], ); - $operation->createDataKeys( + $modifiedEncryptedFields = $operation->createDataKeys( $this->clientEncryption, 'local', null, - $modifiedEncryptedFields, ); $this->assertSame($originalField, $originalEncryptedFields->fields[0]); @@ -181,11 +177,10 @@ public function testEncryptedFieldsDocuments($input): void ['encryptedFields' => $input], ); - $operation->createDataKeys( + $modifiedEncryptedFields = $operation->createDataKeys( $this->clientEncryption, 'local', null, - $modifiedEncryptedFields, ); $this->assertInstanceOf(Binary::class, $modifiedEncryptedFields['fields'][0]['keyId'] ?? null); diff --git a/tests/Operation/DropCollectionFunctionalTest.php b/tests/Operation/DropCollectionFunctionalTest.php index a7d317e67..3d2015521 100644 --- a/tests/Operation/DropCollectionFunctionalTest.php +++ b/tests/Operation/DropCollectionFunctionalTest.php @@ -36,9 +36,8 @@ public function testDropExistingCollection(): void $this->assertEquals(1, $writeResult->getInsertedCount()); $operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName()); - $commandResult = $operation->execute($server); + $operation->execute($server); - $this->assertCommandSucceeded($commandResult); $this->assertCollectionDoesNotExist($this->getCollectionName()); } @@ -48,11 +47,7 @@ public function testDropNonexistentCollection(): void $this->assertCollectionDoesNotExist($this->getCollectionName()); $operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName()); - $commandResult = $operation->execute($this->getPrimaryServer()); - - /* Avoid inspecting the result document as mongos returns {ok:1.0}, - * which is inconsistent from the expected mongod response of {ok:0}. */ - $this->assertIsObject($commandResult); + $operation->execute($this->getPrimaryServer()); } public function testSessionOption(): void diff --git a/tests/Operation/DropCollectionTest.php b/tests/Operation/DropCollectionTest.php index 19dc28bd4..5aa580520 100644 --- a/tests/Operation/DropCollectionTest.php +++ b/tests/Operation/DropCollectionTest.php @@ -19,7 +19,6 @@ public static function provideInvalidConstructorOptions() { return self::createOptionDataProvider([ 'session' => self::getInvalidSessionValues(), - 'typeMap' => self::getInvalidArrayValues(), 'writeConcern' => self::getInvalidWriteConcernValues(), ]); } diff --git a/tests/Operation/DropDatabaseTest.php b/tests/Operation/DropDatabaseTest.php index cd58e6356..c2d950223 100644 --- a/tests/Operation/DropDatabaseTest.php +++ b/tests/Operation/DropDatabaseTest.php @@ -19,7 +19,6 @@ public static function provideInvalidConstructorOptions() { return self::createOptionDataProvider([ 'session' => self::getInvalidSessionValues(), - 'typeMap' => self::getInvalidArrayValues(), 'writeConcern' => self::getInvalidWriteConcernValues(), ]); } diff --git a/tests/Operation/DropIndexesFunctionalTest.php b/tests/Operation/DropIndexesFunctionalTest.php index d54c8544a..f273cb216 100644 --- a/tests/Operation/DropIndexesFunctionalTest.php +++ b/tests/Operation/DropIndexesFunctionalTest.php @@ -48,7 +48,7 @@ public function testDropOneIndexByName(): void $this->assertIndexExists('x_1'); $operation = new DropIndexes($this->getDatabaseName(), $this->getCollectionName(), 'x_1'); - $this->assertCommandSucceeded($operation->execute($this->getPrimaryServer())); + $operation->execute($this->getPrimaryServer()); $operation = new ListIndexes($this->getDatabaseName(), $this->getCollectionName()); $indexes = $operation->execute($this->getPrimaryServer()); @@ -76,7 +76,7 @@ public function testDropAllIndexesByWildcard(): void $this->assertIndexExists('y_1'); $operation = new DropIndexes($this->getDatabaseName(), $this->getCollectionName(), '*'); - $this->assertCommandSucceeded($operation->execute($this->getPrimaryServer())); + $operation->execute($this->getPrimaryServer()); $operation = new ListIndexes($this->getDatabaseName(), $this->getCollectionName()); $indexes = $operation->execute($this->getPrimaryServer()); @@ -108,7 +108,7 @@ public function testDropByIndexInfo(): void $this->assertIndexExists('x_1'); $operation = new DropIndexes($this->getDatabaseName(), $this->getCollectionName(), $info); - $this->assertCommandSucceeded($operation->execute($this->getPrimaryServer())); + $operation->execute($this->getPrimaryServer()); $operation = new ListIndexes($this->getDatabaseName(), $this->getCollectionName()); $indexes = $operation->execute($this->getPrimaryServer()); diff --git a/tests/Operation/DropIndexesTest.php b/tests/Operation/DropIndexesTest.php index cc2aff405..214330512 100644 --- a/tests/Operation/DropIndexesTest.php +++ b/tests/Operation/DropIndexesTest.php @@ -26,7 +26,6 @@ public static function provideInvalidConstructorOptions() return self::createOptionDataProvider([ 'maxTimeMS' => self::getInvalidIntegerValues(), 'session' => self::getInvalidSessionValues(), - 'typeMap' => self::getInvalidArrayValues(), 'writeConcern' => self::getInvalidWriteConcernValues(), ]); } diff --git a/tests/Operation/RenameCollectionFunctionalTest.php b/tests/Operation/RenameCollectionFunctionalTest.php index 9dccae0e3..37fb23d4d 100644 --- a/tests/Operation/RenameCollectionFunctionalTest.php +++ b/tests/Operation/RenameCollectionFunctionalTest.php @@ -65,9 +65,8 @@ public function testRenameCollectionToNonexistentTarget(): void $this->getDatabaseName(), $this->toCollectionName, ); - $commandResult = $operation->execute($server); + $operation->execute($server); - $this->assertCommandSucceeded($commandResult); $this->assertCollectionDoesNotExist($this->getCollectionName()); $this->assertCollectionExists($this->toCollectionName); diff --git a/tests/Operation/RenameCollectionTest.php b/tests/Operation/RenameCollectionTest.php index bae80e9ee..e0a438329 100644 --- a/tests/Operation/RenameCollectionTest.php +++ b/tests/Operation/RenameCollectionTest.php @@ -26,7 +26,6 @@ public static function provideInvalidConstructorOptions() return self::createOptionDataProvider([ 'dropTarget' => self::getInvalidBooleanValues(), 'session' => self::getInvalidSessionValues(), - 'typeMap' => self::getInvalidArrayValues(), 'writeConcern' => self::getInvalidWriteConcernValues(), ]); } diff --git a/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php b/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php index 874671642..e5d8e72d5 100644 --- a/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php +++ b/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php @@ -69,7 +69,7 @@ public function tearDown(): void #[DataProvider('provideKmsProviderAndMasterKey')] public function testCase1_SimpleCreationAndValidation(string $kmsProvider, ?array $masterKey): void { - [$result, $encryptedFields] = $this->database->createEncryptedCollection( + $encryptedFields = $this->database->createEncryptedCollection( $this->getCollectionName(), $this->clientEncryption, $kmsProvider, @@ -77,7 +77,6 @@ public function testCase1_SimpleCreationAndValidation(string $kmsProvider, ?arra ['encryptedFields' => ['fields' => [['path' => 'ssn', 'bsonType' => 'string', 'keyId' => null]]]], ); - $this->assertCommandSucceeded($result); $this->assertInstanceOf(Binary::class, $encryptedFields['fields'][0]['keyId'] ?? null); $this->expectException(BulkWriteException::class); @@ -140,7 +139,7 @@ public function testCase3_InvalidKeyId(string $kmsProvider, ?array $masterKey): #[DataProvider('provideKmsProviderAndMasterKey')] public function testCase4_InsertEncryptedValue(string $kmsProvider, ?array $masterKey): void { - [$result, $encryptedFields] = $this->database->createEncryptedCollection( + $encryptedFields = $this->database->createEncryptedCollection( $this->getCollectionName(), $this->clientEncryption, $kmsProvider, @@ -148,7 +147,6 @@ public function testCase4_InsertEncryptedValue(string $kmsProvider, ?array $mast ['encryptedFields' => ['fields' => [['path' => 'ssn', 'bsonType' => 'string', 'keyId' => null]]]], ); - $this->assertCommandSucceeded($result); $this->assertInstanceOf(Binary::class, $encryptedFields['fields'][0]['keyId'] ?? null); $encrypted = $this->clientEncryption->encrypt('123-45-6789', [