Skip to content

Commit b9262b9

Browse files
committed
Prose test 22.3
1 parent f176d59 commit b9262b9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,43 @@ public function testCase2_CanFindEncryptedRangeAndReturnTheMaximum(string $type,
248248
$this->assertMultipleDocumentsMatch($expectedDocuments, $cursor);
249249
}
250250

251+
/**
252+
* @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.rst#case-3-can-find-encrypted-range-and-return-the-minimum
253+
* @dataProvider provideTypeAndRangeOpts
254+
*/
255+
public function testCase3_CanFindEncryptedRangeAndReturnTheMinimum(string $type, array $rangeOpts): void
256+
{
257+
$this->setUpWithTypeAndRangeOpts($type, $rangeOpts);
258+
259+
$encryptOpts = [
260+
'keyId' => $this->key1Id,
261+
'algorithm' => ClientEncryption::ALGORITHM_RANGE_PREVIEW,
262+
'queryType' => ClientEncryption::QUERY_TYPE_RANGE_PREVIEW,
263+
'contentionFactor' => 0,
264+
'rangeOpts' => $rangeOpts,
265+
];
266+
267+
$cast = self::getCastCallableForType($type);
268+
$fieldName = 'encrypted' . $type;
269+
270+
$expr = [
271+
'$and' => [
272+
[$fieldName => ['$gte' => $cast(0)]],
273+
[$fieldName => ['$lte' => $cast(6)]],
274+
],
275+
];
276+
277+
$encryptedExpr = $this->clientEncryption->encryptExpression($expr, $encryptOpts);
278+
$cursor = $this->collection->find($encryptedExpr, ['sort' => ['_id' => 1]]);
279+
280+
$expectedDocuments = [
281+
['_id' => 0, $fieldName => $cast(0)],
282+
['_id' => 1, $fieldName => $cast(6)],
283+
];
284+
285+
$this->assertMultipleDocumentsMatch($expectedDocuments, $cursor);
286+
}
287+
251288
private function assertMultipleDocumentsMatch(array $expectedDocuments, Iterator $actualDocuments): void
252289
{
253290
$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ANY);

0 commit comments

Comments
 (0)