Skip to content

Commit 96f97f8

Browse files
committed
PHPC-1653: Resync BSON corpus spec tests
Syncs tests with mongodb/specifications@1713439. Includes tests for PHPC-1655 and PHPC-1652. Adds logic to canonicalize $numberDouble values, which allows previously skipped tests to pass. This was noticed because SPEC-1537 changed the description of these tests and they were no loner skipped by convert-bson-corpus-tests.php.
1 parent e722c2f commit 96f97f8

37 files changed

+147
-86
lines changed

scripts/convert-bson-corpus-tests.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
require_once __DIR__ . '/../tests/utils/tools.php';
44

55
$expectedFailures = [
6-
'Double type: 1.23456789012345677E+18' => 'Variation in double\'s string representation (SPEC-850)',
7-
'Double type: -1.23456789012345677E+18' => 'Variation in double\'s string representation (SPEC-850)',
86
'Int64 type: -1' => 'PHP encodes integers as 32-bit if range allows',
97
'Int64 type: 0' => 'PHP encodes integers as 32-bit if range allows',
108
'Int64 type: 1' => 'PHP encodes integers as 32-bit if range allows',

tests/bson-corpus/array-valid-005.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ $canonicalBson = hex2bin('1b000000046100130000001030000a000000103100140000000000
1313
$degenerateBson = hex2bin('1b000000046100130000001030000a000000103000140000000000');
1414
$canonicalExtJson = '{"a" : [{"$numberInt": "10"}, {"$numberInt": "20"}]}';
1515

16-
// Canonical BSON -> Native -> Canonical BSON
16+
// Canonical BSON -> Native -> Canonical BSON
1717
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
1818

19-
// Canonical BSON -> Canonical extJSON
19+
// Canonical BSON -> Canonical extJSON
2020
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";
2121

22-
// Canonical extJSON -> Canonical BSON
22+
// Canonical extJSON -> Canonical BSON
2323
echo bin2hex(fromJSON($canonicalExtJson)), "\n";
2424

25-
// Degenerate BSON -> Native -> Canonical BSON
25+
// Degenerate BSON -> Native -> Canonical BSON
2626
echo bin2hex(fromPHP(toPHP($degenerateBson))), "\n";
2727

28-
// Degenerate BSON -> Canonical extJSON
28+
// Degenerate BSON -> Canonical extJSON
2929
echo json_canonicalize(toCanonicalExtendedJSON($degenerateBson)), "\n";
3030

3131
?>

tests/bson-corpus/datetime-valid-005.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ $canonicalBson = hex2bin('10000000096100D1D6D6CC3B01000000');
1313
$canonicalExtJson = '{"a" : {"$date" : {"$numberLong" : "1356351330001"}}}';
1414
$relaxedExtJson = '{"a" : {"$date" : "2012-12-24T12:15:30.001Z"}}';
1515

16-
// Canonical BSON -> Native -> Canonical BSON
16+
// Canonical BSON -> Native -> Canonical BSON
1717
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
1818

19-
// Canonical BSON -> Canonical extJSON
19+
// Canonical BSON -> Canonical extJSON
2020
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";
2121

22-
// Canonical BSON -> Relaxed extJSON
22+
// Canonical BSON -> Relaxed extJSON
2323
echo json_canonicalize(toRelaxedExtendedJSON($canonicalBson)), "\n";
2424

25-
// Canonical extJSON -> Canonical BSON
25+
// Canonical extJSON -> Canonical BSON
2626
echo bin2hex(fromJSON($canonicalExtJson)), "\n";
2727

28-
// Relaxed extJSON -> BSON -> Relaxed extJSON
28+
// Relaxed extJSON -> BSON -> Relaxed extJSON
2929
echo json_canonicalize(toRelaxedExtendedJSON(fromJSON($relaxedExtJson))), "\n";
3030

3131
?>

tests/bson-corpus/double-valid-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ echo json_canonicalize(toRelaxedExtendedJSON(fromJSON($relaxedExtJson))), "\n";
3333
<?php exit(0); ?>
3434
--EXPECT--
3535
10000000016400000000000000f03f00
36-
{"d":{"$numberDouble":"1.0"}}
36+
{"d":{"$numberDouble":"1"}}
3737
{"d":1}
3838
10000000016400000000000000f03f00
3939
{"d":1}

tests/bson-corpus/double-valid-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ echo json_canonicalize(toRelaxedExtendedJSON(fromJSON($relaxedExtJson))), "\n";
3333
<?php exit(0); ?>
3434
--EXPECT--
3535
10000000016400000000000000f0bf00
36-
{"d":{"$numberDouble":"-1.0"}}
36+
{"d":{"$numberDouble":"-1"}}
3737
{"d":-1}
3838
10000000016400000000000000f0bf00
3939
{"d":-1}

tests/bson-corpus/double-valid-005.phpt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
2-
Double type: 1.23456789012345677E+18
3-
--XFAIL--
4-
Variation in double's string representation (SPEC-850)
2+
Double type: 1.2345678921232E+18
53
--DESCRIPTION--
64
Generated by scripts/convert-bson-corpus-tests.php
75

@@ -11,9 +9,9 @@ DO NOT EDIT THIS FILE
119

1210
require_once __DIR__ . '/../utils/tools.php';
1311

14-
$canonicalBson = hex2bin('1000000001640081E97DF41022B14300');
15-
$canonicalExtJson = '{"d" : {"$numberDouble": "1.23456789012345677E+18"}}';
16-
$relaxedExtJson = '{"d" : 1.23456789012345677E+18}';
12+
$canonicalBson = hex2bin('100000000164002a1bf5f41022b14300');
13+
$canonicalExtJson = '{"d" : {"$numberDouble": "1.2345678921232E+18"}}';
14+
$relaxedExtJson = '{"d" : 1.2345678921232E+18}';
1715

1816
// Canonical BSON -> Native -> Canonical BSON
1917
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
@@ -34,9 +32,9 @@ echo json_canonicalize(toRelaxedExtendedJSON(fromJSON($relaxedExtJson))), "\n";
3432
===DONE===
3533
<?php exit(0); ?>
3634
--EXPECT--
37-
1000000001640081e97df41022b14300
38-
{"d":{"$numberDouble":"1.23456789012345677E+18"}}
39-
{"d":1.2345678901234568e+18}
40-
1000000001640081e97df41022b14300
41-
{"d":1.2345678901234568e+18}
35+
100000000164002a1bf5f41022b14300
36+
{"d":{"$numberDouble":"1.2345678921232e+18"}}
37+
{"d":1.2345678921232e+18}
38+
100000000164002a1bf5f41022b14300
39+
{"d":1.2345678921232e+18}
4240
===DONE===

tests/bson-corpus/double-valid-006.phpt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
2-
Double type: -1.23456789012345677E+18
3-
--XFAIL--
4-
Variation in double's string representation (SPEC-850)
2+
Double type: -1.2345678921232E+18
53
--DESCRIPTION--
64
Generated by scripts/convert-bson-corpus-tests.php
75

@@ -11,9 +9,9 @@ DO NOT EDIT THIS FILE
119

1210
require_once __DIR__ . '/../utils/tools.php';
1311

14-
$canonicalBson = hex2bin('1000000001640081E97DF41022B1C300');
15-
$canonicalExtJson = '{"d" : {"$numberDouble": "-1.23456789012345677E+18"}}';
16-
$relaxedExtJson = '{"d" : -1.23456789012345677E+18}';
12+
$canonicalBson = hex2bin('100000000164002a1bf5f41022b1c300');
13+
$canonicalExtJson = '{"d" : {"$numberDouble": "-1.2345678921232E+18"}}';
14+
$relaxedExtJson = '{"d" : -1.2345678921232E+18}';
1715

1816
// Canonical BSON -> Native -> Canonical BSON
1917
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
@@ -34,9 +32,9 @@ echo json_canonicalize(toRelaxedExtendedJSON(fromJSON($relaxedExtJson))), "\n";
3432
===DONE===
3533
<?php exit(0); ?>
3634
--EXPECT--
37-
1000000001640081e97df41022b1c300
38-
{"d":{"$numberDouble":"-1.23456789012345677E+18"}}
39-
{"d":-1.2345678901234568e+18}
40-
1000000001640081e97df41022b1c300
41-
{"d":-1.2345678901234568e+18}
35+
100000000164002a1bf5f41022b1c300
36+
{"d":{"$numberDouble":"-1.2345678921232e+18"}}
37+
{"d":-1.2345678921232e+18}
38+
100000000164002a1bf5f41022b1c300
39+
{"d":-1.2345678921232e+18}
4240
===DONE===

tests/bson-corpus/double-valid-007.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ echo json_canonicalize(toRelaxedExtendedJSON(fromJSON($relaxedExtJson))), "\n";
3333
<?php exit(0); ?>
3434
--EXPECT--
3535
10000000016400000000000000000000
36-
{"d":{"$numberDouble":"0.0"}}
36+
{"d":{"$numberDouble":"0"}}
3737
{"d":0}
3838
10000000016400000000000000000000
3939
{"d":0}

tests/bson-corpus/double-valid-008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ echo json_canonicalize(toRelaxedExtendedJSON(fromJSON($relaxedExtJson))), "\n";
3333
<?php exit(0); ?>
3434
--EXPECT--
3535
10000000016400000000000000008000
36-
{"d":{"$numberDouble":"-0.0"}}
36+
{"d":{"$numberDouble":"-0"}}
3737
{"d":-0}
3838
10000000016400000000000000008000
3939
{"d":-0}

tests/bson-corpus/multi-type-deprecated-valid-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
3030
<?php exit(0); ?>
3131
--EXPECT--
3232
38020000075f69640057e193d7a9cc81b4027498b50e53796d626f6c000700000073796d626f6c0002537472696e670007000000737472696e670010496e743332002a00000012496e743634002a0000000000000001446f75626c6500000000000000f0bf0542696e617279001000000003a34c38f7c3abedc8a37814a992ab8db60542696e61727955736572446566696e656400050000008001020304050d436f6465000e00000066756e6374696f6e2829207b7d000f436f64655769746853636f7065001b0000000e00000066756e6374696f6e2829207b7d00050000000003537562646f63756d656e74001200000002666f6f0004000000626172000004417272617900280000001030000100000010310002000000103200030000001033000400000010340005000000001154696d657374616d7000010000002a0000000b5265676578007061747465726e0000094461746574696d6545706f6368000000000000000000094461746574696d65506f73697469766500ffffff7f00000000094461746574696d654e656761746976650000000080ffffffff085472756500010846616c736500000c4442506f696e746572000b000000636f6c6c656374696f6e0057e193d7a9cc81b4027498b1034442526566003d0000000224726566000b000000636f6c6c656374696f6e00072469640057fd71e96e32ab4225b723fb02246462000900000064617461626173650000ff4d696e6b6579007f4d61786b6579000a4e756c6c0006556e646566696e65640000
33-
{"_id":{"$oid":"57e193d7a9cc81b4027498b5"},"Symbol":{"$symbol":"symbol"},"String":"string","Int32":{"$numberInt":"42"},"Int64":{"$numberLong":"42"},"Double":{"$numberDouble":"-1.0"},"Binary":{"$binary":{"base64":"o0w498Or7cijeBSpkquNtg==","subType":"03"}},"BinaryUserDefined":{"$binary":{"base64":"AQIDBAU=","subType":"80"}},"Code":{"$code":"function() {}"},"CodeWithScope":{"$code":"function() {}","$scope":{}},"Subdocument":{"foo":"bar"},"Array":[{"$numberInt":"1"},{"$numberInt":"2"},{"$numberInt":"3"},{"$numberInt":"4"},{"$numberInt":"5"}],"Timestamp":{"$timestamp":{"t":42,"i":1}},"Regex":{"$regularExpression":{"pattern":"pattern","options":""}},"DatetimeEpoch":{"$date":{"$numberLong":"0"}},"DatetimePositive":{"$date":{"$numberLong":"2147483647"}},"DatetimeNegative":{"$date":{"$numberLong":"-2147483648"}},"True":true,"False":false,"DBPointer":{"$dbPointer":{"$ref":"collection","$id":{"$oid":"57e193d7a9cc81b4027498b1"}}},"DBRef":{"$ref":"collection","$id":{"$oid":"57fd71e96e32ab4225b723fb"},"$db":"database"},"Minkey":{"$minKey":1},"Maxkey":{"$maxKey":1},"Null":null,"Undefined":{"$undefined":true}}
33+
{"_id":{"$oid":"57e193d7a9cc81b4027498b5"},"Symbol":{"$symbol":"symbol"},"String":"string","Int32":{"$numberInt":"42"},"Int64":{"$numberLong":"42"},"Double":{"$numberDouble":"-1"},"Binary":{"$binary":{"base64":"o0w498Or7cijeBSpkquNtg==","subType":"03"}},"BinaryUserDefined":{"$binary":{"base64":"AQIDBAU=","subType":"80"}},"Code":{"$code":"function() {}"},"CodeWithScope":{"$code":"function() {}","$scope":{}},"Subdocument":{"foo":"bar"},"Array":[{"$numberInt":"1"},{"$numberInt":"2"},{"$numberInt":"3"},{"$numberInt":"4"},{"$numberInt":"5"}],"Timestamp":{"$timestamp":{"t":42,"i":1}},"Regex":{"$regularExpression":{"pattern":"pattern","options":""}},"DatetimeEpoch":{"$date":{"$numberLong":"0"}},"DatetimePositive":{"$date":{"$numberLong":"2147483647"}},"DatetimeNegative":{"$date":{"$numberLong":"-2147483648"}},"True":true,"False":false,"DBPointer":{"$dbPointer":{"$ref":"collection","$id":{"$oid":"57e193d7a9cc81b4027498b1"}}},"DBRef":{"$ref":"collection","$id":{"$oid":"57fd71e96e32ab4225b723fb"},"$db":"database"},"Minkey":{"$minKey":1},"Maxkey":{"$maxKey":1},"Null":null,"Undefined":{"$undefined":true}}
3434
38020000075f69640057e193d7a9cc81b4027498b50e53796d626f6c000700000073796d626f6c0002537472696e670007000000737472696e670010496e743332002a00000012496e743634002a0000000000000001446f75626c6500000000000000f0bf0542696e617279001000000003a34c38f7c3abedc8a37814a992ab8db60542696e61727955736572446566696e656400050000008001020304050d436f6465000e00000066756e6374696f6e2829207b7d000f436f64655769746853636f7065001b0000000e00000066756e6374696f6e2829207b7d00050000000003537562646f63756d656e74001200000002666f6f0004000000626172000004417272617900280000001030000100000010310002000000103200030000001033000400000010340005000000001154696d657374616d7000010000002a0000000b5265676578007061747465726e0000094461746574696d6545706f6368000000000000000000094461746574696d65506f73697469766500ffffff7f00000000094461746574696d654e656761746976650000000080ffffffff085472756500010846616c736500000c4442506f696e746572000b000000636f6c6c656374696f6e0057e193d7a9cc81b4027498b1034442526566003d0000000224726566000b000000636f6c6c656374696f6e00072469640057fd71e96e32ab4225b723fb02246462000900000064617461626173650000ff4d696e6b6579007f4d61786b6579000a4e756c6c0006556e646566696e65640000
3535
===DONE===

0 commit comments

Comments
 (0)