3
3
require_once __DIR__ . '/../tests/utils/basic.inc ' ;
4
4
5
5
$ expectedFailures = [
6
- 'Int64 type: -1 ' => 'PHP encodes integers as 32-bit if range allows ' ,
7
- 'Int64 type: 0 ' => 'PHP encodes integers as 32-bit if range allows ' ,
8
- 'Int64 type: 1 ' => 'PHP encodes integers as 32-bit if range allows ' ,
9
6
'Javascript Code: Embedded nulls ' => 'Embedded null in code string is not supported in libbson (CDRIVER-1879) ' ,
10
7
'Javascript Code with Scope: Unicode and embedded null in code string, empty scope ' => 'Embedded null in code string is not supported in libbson (CDRIVER-1879) ' ,
11
- 'Multiple types within the same document: All BSON types ' => 'PHP encodes integers as 32-bit if range allows ' ,
12
8
'Top-level document validity: Bad $date (number, not string or hash) ' => 'Legacy extended JSON $date syntax uses numbers (CDRIVER-2223) ' ,
13
9
];
14
10
@@ -147,85 +143,49 @@ function getParamsForValid(array $test, array $case)
147
143
$ code .= sprintf ('$convertedExtJson = %s; ' , var_export ($ convertedExtJson , true )) . "\n" ;
148
144
}
149
145
150
- $ code .= "\n// Canonical BSON -> Native -> Canonical BSON \n" ;
151
- $ code .= 'echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n"; ' . "\n" ;
152
- $ expect .= $ expectedCanonicalBson . "\n" ;
153
-
154
146
$ code .= "\n// Canonical BSON -> BSON object -> Canonical BSON \n" ;
155
147
$ code .= 'echo bin2hex((string) MongoDB\BSON\Document::fromBSON($canonicalBson)), "\n"; ' . "\n" ;
156
148
$ expect .= $ expectedCanonicalBson . "\n" ;
157
149
158
- $ code .= "\n// Canonical BSON -> Canonical extJSON \n" ;
159
- $ code .= 'echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n"; ' . "\n" ;
160
- $ expect .= $ expectedCanonicalExtJson . "\n" ;
161
-
162
150
$ code .= "\n// Canonical BSON -> BSON object -> Canonical extJSON \n" ;
163
151
$ code .= 'echo json_canonicalize(MongoDB\BSON\Document::fromBSON($canonicalBson)->toCanonicalExtendedJSON()), "\n"; ' . "\n" ;
164
152
$ expect .= $ expectedCanonicalExtJson . "\n" ;
165
153
166
154
if (isset ($ relaxedExtJson )) {
167
- $ code .= "\n// Canonical BSON -> Relaxed extJSON \n" ;
168
- $ code .= 'echo json_canonicalize(toRelaxedExtendedJSON($canonicalBson)), "\n"; ' . "\n" ;
169
- $ expect .= $ expectedRelaxedExtJson . "\n" ;
170
-
171
155
$ code .= "\n// Canonical BSON -> BSON object -> Relaxed extJSON \n" ;
172
156
$ code .= 'echo json_canonicalize(MongoDB\BSON\Document::fromBSON($canonicalBson)->toRelaxedExtendedJSON()), "\n"; ' . "\n" ;
173
157
$ expect .= $ expectedRelaxedExtJson . "\n" ;
174
158
}
175
159
176
160
if (!$ lossy ) {
177
- $ code .= "\n// Canonical extJSON -> Canonical BSON \n" ;
178
- $ code .= 'echo bin2hex(fromJSON($canonicalExtJson)), "\n"; ' . "\n" ;
179
- $ expect .= $ expectedCanonicalBson . "\n" ;
180
-
181
161
$ code .= "\n// Canonical extJSON -> BSON object -> Canonical BSON \n" ;
182
162
$ code .= 'echo bin2hex((string) MongoDB\BSON\Document::fromJSON($canonicalExtJson)), "\n"; ' . "\n" ;
183
163
$ expect .= $ expectedCanonicalBson . "\n" ;
184
164
}
185
165
186
166
if (isset ($ degenerateBson )) {
187
- $ code .= "\n// Degenerate BSON -> Native -> Canonical BSON \n" ;
188
- $ code .= 'echo bin2hex(fromPHP(toPHP($degenerateBson))), "\n"; ' . "\n" ;
189
- $ expect .= $ expectedCanonicalBson . "\n" ;
190
-
191
167
$ code .= "\n// Degenerate BSON -> BSON object -> Canonical BSON \n" ;
192
- $ code .= 'echo bin2hex(fromPHP(MongoDB\BSON\Document::fromBSON($degenerateBson)->toPHP())), "\n"; ' . "\n" ;
168
+ $ code .= 'echo bin2hex((string) MongoDB\BSON\Document:: fromPHP(MongoDB\BSON\Document::fromBSON($degenerateBson)->toPHP())), "\n"; ' . "\n" ;
193
169
$ expect .= $ expectedCanonicalBson . "\n" ;
194
170
195
- $ code .= "\n// Degenerate BSON -> Canonical extJSON \n" ;
196
- $ code .= 'echo json_canonicalize(toCanonicalExtendedJSON($degenerateBson)), "\n"; ' . "\n" ;
197
- $ expect .= $ expectedCanonicalExtJson . "\n" ;
198
-
199
171
$ code .= "\n// Degenerate BSON -> BSON object -> Canonical extJSON \n" ;
200
172
$ code .= 'echo json_canonicalize(MongoDB\BSON\Document::fromBSON($degenerateBson)->toCanonicalExtendedJSON()), "\n"; ' . "\n" ;
201
173
$ expect .= $ expectedCanonicalExtJson . "\n" ;
202
174
203
175
if (isset ($ relaxedExtJson )) {
204
- $ code .= "\n// Degenerate BSON -> Relaxed extJSON \n" ;
205
- $ code .= 'echo json_canonicalize(toRelaxedExtendedJSON($degenerateBson)), "\n"; ' . "\n" ;
206
- $ expect .= $ expectedRelaxedExtJson . "\n" ;
207
-
208
176
$ code .= "\n// Degenerate BSON -> BSON object -> Relaxed extJSON \n" ;
209
177
$ code .= 'echo json_canonicalize(MongoDB\BSON\Document::fromBSON($degenerateBson)->toRelaxedExtendedJSON()), "\n"; ' . "\n" ;
210
178
$ expect .= $ expectedRelaxedExtJson . "\n" ;
211
179
}
212
180
}
213
181
214
182
if (isset ($ degenerateExtJson ) && !$ lossy ) {
215
- $ code .= "\n// Degenerate extJSON -> Canonical BSON \n" ;
216
- $ code .= 'echo bin2hex(fromJSON($degenerateExtJson)), "\n"; ' . "\n" ;
217
- $ expect .= $ expectedCanonicalBson . "\n" ;
218
-
219
183
$ code .= "\n// Degenerate extJSON -> BSON object -> Canonical BSON \n" ;
220
184
$ code .= 'echo bin2hex((string) MongoDB\BSON\Document::fromJSON($degenerateExtJson)), "\n"; ' . "\n" ;
221
185
$ expect .= $ expectedCanonicalBson . "\n" ;
222
186
}
223
187
224
188
if (isset ($ relaxedExtJson )) {
225
- $ code .= "\n// Relaxed extJSON -> BSON -> Relaxed extJSON \n" ;
226
- $ code .= 'echo json_canonicalize(toRelaxedExtendedJSON(fromJSON($relaxedExtJson))), "\n"; ' . "\n" ;
227
- $ expect .= $ expectedRelaxedExtJson . "\n" ;
228
-
229
189
$ code .= "\n// Relaxed extJSON -> BSON object -> Relaxed extJSON \n" ;
230
190
$ code .= 'echo json_canonicalize(MongoDB\BSON\Document::fromJSON($relaxedExtJson)->toRelaxedExtendedJSON()), "\n"; ' . "\n" ;
231
191
$ expect .= $ expectedRelaxedExtJson . "\n" ;
@@ -248,7 +208,7 @@ function getParamsForDecodeError(array $test, array $case)
248
208
249
209
$ code = sprintf ('$bson = hex2bin(%s); ' , var_export ($ case ['bson ' ], true )) . "\n\n" ;
250
210
$ code .= "throws(function() use ( \$bson) { \n" ;
251
- $ code .= " var_dump(toPHP( \$bson)); \n" ;
211
+ $ code .= " MongoDB \\ BSON \\ Document::fromBSON( \$bson)->toPHP( ); \n" ;
252
212
$ code .= "}, 'MongoDB\Driver\Exception\UnexpectedValueException'); " ;
253
213
254
214
/* We do not test for the exception message, since that may differ based on
@@ -277,7 +237,7 @@ function getParamsForParseError(array $test, array $case)
277
237
case '0x00 ' : // Top-level document
278
238
case '0x05 ' : // Binary
279
239
$ code = "throws(function() { \n" ;
280
- $ code .= sprintf (" fromJSON(%s); \n" , var_export ($ case ['string ' ], true ));
240
+ $ code .= sprintf (" MongoDB \\ BSON \\ Document:: fromJSON(%s); \n" , var_export ($ case ['string ' ], true ));
281
241
$ code .= "}, 'MongoDB\Driver\Exception\UnexpectedValueException'); " ;
282
242
283
243
/* We do not test for the exception message, since that may differ
0 commit comments