Skip to content

Commit 9ce148c

Browse files
committed
Prepare RewrapManyDataKeyResult for expectResult assertion
1 parent b19deae commit 9ce148c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tests/UnifiedSpecTests/Operation.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private function executeForClientEncryption(ClientEncryption $clientEncryption)
327327
// CSFLE spec tests nest options under an "opts" key (see: DRIVERS-2414)
328328
$options = array_key_exists('opts', $args) ? (array) $args['opts'] : [];
329329

330-
return $clientEncryption->rewrapManyDataKey($args['filter'], $options);
330+
return static::prepareRewrapManyDataKeyResult($clientEncryption->rewrapManyDataKey($args['filter'], $options));
331331

332332
default:
333333
Assert::fail('Unsupported clientEncryption operation: ' . $this->name);
@@ -992,6 +992,31 @@ private static function prepareBulkWriteRequest(stdClass $request): array
992992
}
993993
}
994994

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+
9951020
private static function prepareUploadArguments(array $args): array
9961021
{
9971022
$source = $args['source'] ?? null;

0 commit comments

Comments
 (0)