Skip to content

Commit 62dec14

Browse files
committed
Decode field paths as BSON to preserve BSON int64 types
1 parent 1b02a0d commit 62dec14

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
];
@@ -257,8 +228,21 @@ public function provideTests()
257228
foreach (glob(__DIR__ . '/client-side-encryption/tests/*.json') as $filename) {
258229
$group = basename($filename, '.json');
259230

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

0 commit comments

Comments
 (0)