Skip to content

Commit 415090d

Browse files
committed
Decode field paths as BSON to preserve BSON int64 types
1 parent bb2e339 commit 415090d

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

tests/SpecTests/ClientSideEncryptionSpecTest.php

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use MongoDB\BSON\Binary;
7+
use MongoDB\BSON\Document;
78
use MongoDB\BSON\Int64;
89
use MongoDB\Client;
910
use MongoDB\Collection;
@@ -116,36 +117,6 @@ class ClientSideEncryptionSpecTest extends FunctionalTestCase
116117
'fle2v2-Range-DecimalPrecision-InsertFind: FLE2 Range DecimalPrecision. Insert and Find.' => 'Bundled libmongocrypt does not support Decimal128 (PHPC-2207)',
117118
'fle2v2-Range-DecimalPrecision-Update: FLE2 Range DecimalPrecision. Update.' => 'Bundled libmongocrypt does not support Decimal128 (PHPC-2207)',
118119
'fle2v2-Range-Decimal-Update: FLE2 Range Decimal. Update.' => 'Bundled libmongocrypt does not support Decimal128 (PHPC-2207)',
119-
'fle2v2-Range-Long-Aggregate: FLE2 Range Long. Aggregate.' => 'PHP encodes integers as 32-bit if range allows',
120-
'fle2v2-Range-Long-Correctness: Find with $gt' => 'PHP encodes integers as 32-bit if range allows',
121-
'fle2v2-Range-Long-Correctness: Find with $gte' => 'PHP encodes integers as 32-bit if range allows',
122-
'fle2v2-Range-Long-Correctness: Find with $gt with no results' => 'PHP encodes integers as 32-bit if range allows',
123-
'fle2v2-Range-Long-Correctness: Find with $lt' => 'PHP encodes integers as 32-bit if range allows',
124-
'fle2v2-Range-Long-Correctness: Find with $lte' => 'PHP encodes integers as 32-bit if range allows',
125-
'fle2v2-Range-Long-Correctness: Find with $lt below min' => 'PHP encodes integers as 32-bit if range allows',
126-
'fle2v2-Range-Long-Correctness: Find with $gt above max' => 'PHP encodes integers as 32-bit if range allows',
127-
'fle2v2-Range-Long-Correctness: Find with $gt and $lt' => 'PHP encodes integers as 32-bit if range allows',
128-
'fle2v2-Range-Long-Correctness: Find with equality' => 'PHP encodes integers as 32-bit if range allows',
129-
'fle2v2-Range-Long-Correctness: Find with full range' => 'PHP encodes integers as 32-bit if range allows',
130-
'fle2v2-Range-Long-Correctness: Find with $in' => 'PHP encodes integers as 32-bit if range allows',
131-
'fle2v2-Range-Long-Correctness: Insert out of range' => 'PHP encodes integers as 32-bit if range allows',
132-
'fle2v2-Range-Long-Correctness: Insert min and max' => 'PHP encodes integers as 32-bit if range allows',
133-
'fle2v2-Range-Long-Correctness: Aggregate with $gte' => 'PHP encodes integers as 32-bit if range allows',
134-
'fle2v2-Range-Long-Correctness: Aggregate with $gt with no results' => 'PHP encodes integers as 32-bit if range allows',
135-
'fle2v2-Range-Long-Correctness: Aggregate with $lt' => 'PHP encodes integers as 32-bit if range allows',
136-
'fle2v2-Range-Long-Correctness: Aggregate with $lte' => 'PHP encodes integers as 32-bit if range allows',
137-
'fle2v2-Range-Long-Correctness: Aggregate with $lt below min' => 'PHP encodes integers as 32-bit if range allows',
138-
'fle2v2-Range-Long-Correctness: Aggregate with $gt above max' => 'PHP encodes integers as 32-bit if range allows',
139-
'fle2v2-Range-Long-Correctness: Aggregate with $gt and $lt' => 'PHP encodes integers as 32-bit if range allows',
140-
'fle2v2-Range-Long-Correctness: Aggregate with equality' => 'PHP encodes integers as 32-bit if range allows',
141-
'fle2v2-Range-Long-Correctness: Aggregate with full range' => 'PHP encodes integers as 32-bit if range allows',
142-
'fle2v2-Range-Long-Correctness: Aggregate with $in' => 'PHP encodes integers as 32-bit if range allows',
143-
'fle2v2-Range-Long-Correctness: Wrong type: Insert Double' => 'PHP encodes integers as 32-bit if range allows',
144-
'fle2v2-Range-Long-Correctness: Wrong type: Find Double' => 'PHP encodes integers as 32-bit if range allows',
145-
'fle2v2-Range-Long-Delete: FLE2 Range Long. Delete.' => 'PHP encodes integers as 32-bit if range allows',
146-
'fle2v2-Range-Long-FindOneAndUpdate: FLE2 Range Long. FindOneAndUpdate.' => 'PHP encodes integers as 32-bit if range allows',
147-
'fle2v2-Range-Long-InsertFind: FLE2 Range Long. Insert and Find.' => 'PHP encodes integers as 32-bit if range allows',
148-
'fle2v2-Range-Long-Update: FLE2 Range Long. Update.' => 'PHP encodes integers as 32-bit if range allows',
149120
'timeoutMS: timeoutMS applied to listCollections to get collection schema' => 'Not yet implemented (PHPC-1760)',
150121
'timeoutMS: remaining timeoutMS applied to find to get keyvault data' => 'Not yet implemented (PHPC-1760)',
151122
];
@@ -261,8 +232,21 @@ public function provideTests()
261232
foreach (glob(__DIR__ . '/client-side-encryption/tests/*.json') as $filename) {
262233
$group = basename($filename, '.json');
263234

235+
/* Some tests need to differentiate int32 and int64 BSON types.
236+
* Decode certain field paths as BSON to preserve type information
237+
* that would otherwise be lost by round-tripping through PHP. */
238+
$typeMap = [
239+
'fieldPaths' => [
240+
'encrypted_fields.fields' => 'bson',
241+
'tests.$.operations.$.arguments.document' => 'bson',
242+
'tests.$.operations.$.arguments.pipeline.$' => 'bson',
243+
'tests.$.operations.$.arguments.filter' => 'bson',
244+
'tests.$.operations.$.arguments.update' => 'bson',
245+
],
246+
];
247+
264248
try {
265-
$json = $this->decodeJson(file_get_contents($filename));
249+
$json = Document::fromJSON(file_get_contents($filename))->toPHP($typeMap);
266250
} catch (Throwable $e) {
267251
$testArgs[$group] = [
268252
(object) ['skipReason' => sprintf('Exception loading file "%s": %s', $filename, $e->getMessage())],

0 commit comments

Comments
 (0)