@@ -327,7 +327,7 @@ private function executeForClientEncryption(ClientEncryption $clientEncryption)
327
327
// CSFLE spec tests nest options under an "opts" key (see: DRIVERS-2414)
328
328
$ options = array_key_exists ('opts ' , $ args ) ? (array ) $ args ['opts ' ] : [];
329
329
330
- return $ clientEncryption ->rewrapManyDataKey ($ args ['filter ' ], $ options );
330
+ return static :: prepareRewrapManyDataKeyResult ( $ clientEncryption ->rewrapManyDataKey ($ args ['filter ' ], $ options) );
331
331
332
332
default :
333
333
Assert::fail ('Unsupported clientEncryption operation: ' . $ this ->name );
@@ -992,6 +992,31 @@ private static function prepareBulkWriteRequest(stdClass $request): array
992
992
}
993
993
}
994
994
995
+ /**
996
+ * ClientEncryption::rewrapManyDataKey() returns its result as a raw BSON
997
+ * document and does not utilize WriteResult because getServer() cannot be
998
+ * implemented. To satisfy result expectations, unset bulkWriteResult if it
999
+ * is null and rename its fields (per the CRUD spec) otherwise. */
1000
+ private static function prepareRewrapManyDataKeyResult (stdClass $ result ): object
1001
+ {
1002
+ if ($ result ->bulkWriteResult === null ) {
1003
+ unset($ result ->bulkWriteResult );
1004
+
1005
+ return $ result ;
1006
+ }
1007
+
1008
+ $ result ->bulkWriteResult = [
1009
+ 'insertedCount ' => $ result ->bulkWriteResult ->nInserted ,
1010
+ 'matchedCount ' => $ result ->bulkWriteResult ->nMatched ,
1011
+ 'modifiedCount ' => $ result ->bulkWriteResult ->nModified ,
1012
+ 'deletedCount ' => $ result ->bulkWriteResult ->nRemoved ,
1013
+ 'upsertedCount ' => $ result ->bulkWriteResult ->nUpserted ,
1014
+ 'upsertedIds ' => $ result ->bulkWriteResult ->upserted ?? new stdClass (),
1015
+ ];
1016
+
1017
+ return $ result ;
1018
+ }
1019
+
995
1020
private static function prepareUploadArguments (array $ args ): array
996
1021
{
997
1022
$ source = $ args ['source ' ] ?? null ;
0 commit comments