Skip to content

Commit 6220e1d

Browse files
committed
Sync bson-corpus spec tests for binary
1 parent 64cb72e commit 6220e1d

10 files changed

+164
-23
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Binary type: $uuid wrong type
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/tools.php';
11+
12+
throws(function() {
13+
fromJSON('{"x" : { "$uuid" : { "data" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4"}}}');
14+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
15+
16+
?>
17+
===DONE===
18+
<?php exit(0); ?>
19+
--EXPECT--
20+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
21+
===DONE===
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Binary type: $uuid invalid value--too short
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/tools.php';
11+
12+
throws(function() {
13+
fromJSON('{"x" : { "$uuid" : "73ffd264-44b3-90e8-e7d1dfc035d4"}}');
14+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
15+
16+
?>
17+
===DONE===
18+
<?php exit(0); ?>
19+
--EXPECT--
20+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
21+
===DONE===
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Binary type: $uuid invalid value--too long
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/tools.php';
11+
12+
throws(function() {
13+
fromJSON('{"x" : { "$uuid" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4"}}');
14+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
15+
16+
?>
17+
===DONE===
18+
<?php exit(0); ?>
19+
--EXPECT--
20+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
21+
===DONE===
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Binary type: $uuid invalid value--misplaced hyphens
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/tools.php';
11+
12+
throws(function() {
13+
fromJSON('{"x" : { "$uuid" : "73ff-d26444b-34c6-990e8e-7d1dfc035d4"}}');
14+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
15+
16+
?>
17+
===DONE===
18+
<?php exit(0); ?>
19+
--EXPECT--
20+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
21+
===DONE===
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Binary type: $uuid invalid value--too many hyphens
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/tools.php';
11+
12+
throws(function() {
13+
fromJSON('{"x" : { "$uuid" : "----d264-44b3-4--9-90e8-e7d1dfc0----"}}');
14+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
15+
16+
?>
17+
===DONE===
18+
<?php exit(0); ?>
19+
--EXPECT--
20+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
21+
===DONE===
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Binary type: subtype 0x05
2+
Binary type: subtype 0x04 UUID
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

@@ -9,8 +9,9 @@ DO NOT EDIT THIS FILE
99

1010
require_once __DIR__ . '/../utils/tools.php';
1111

12-
$canonicalBson = hex2bin('1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400');
13-
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "c//SZESzTGmQ6OfR38A11A==", "subType" : "05"}}}';
12+
$canonicalBson = hex2bin('1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400');
13+
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "c//SZESzTGmQ6OfR38A11A==", "subType" : "04"}}}';
14+
$degenerateExtJson = '{"x" : { "$uuid" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4"}}';
1415

1516
// Canonical BSON -> Native -> Canonical BSON
1617
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
@@ -21,11 +22,15 @@ echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";
2122
// Canonical extJSON -> Canonical BSON
2223
echo bin2hex(fromJSON($canonicalExtJson)), "\n";
2324

25+
// Degenerate extJSON -> Canonical BSON
26+
echo bin2hex(fromJSON($degenerateExtJson)), "\n";
27+
2428
?>
2529
===DONE===
2630
<?php exit(0); ?>
2731
--EXPECT--
28-
1d000000057800100000000573ffd26444b34c6990e8e7d1dfc035d400
29-
{"x":{"$binary":{"base64":"c\/\/SZESzTGmQ6OfR38A11A==","subType":"05"}}}
30-
1d000000057800100000000573ffd26444b34c6990e8e7d1dfc035d400
32+
1d000000057800100000000473ffd26444b34c6990e8e7d1dfc035d400
33+
{"x":{"$binary":{"base64":"c\/\/SZESzTGmQ6OfR38A11A==","subType":"04"}}}
34+
1d000000057800100000000473ffd26444b34c6990e8e7d1dfc035d400
35+
1d000000057800100000000473ffd26444b34c6990e8e7d1dfc035d400
3136
===DONE===

tests/bson-corpus/binary-valid-009.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Binary type: subtype 0x80
2+
Binary type: subtype 0x05
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

@@ -9,8 +9,8 @@ DO NOT EDIT THIS FILE
99

1010
require_once __DIR__ . '/../utils/tools.php';
1111

12-
$canonicalBson = hex2bin('0F0000000578000200000080FFFF00');
13-
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "//8=", "subType" : "80"}}}';
12+
$canonicalBson = hex2bin('1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400');
13+
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "c//SZESzTGmQ6OfR38A11A==", "subType" : "05"}}}';
1414

1515
// Canonical BSON -> Native -> Canonical BSON
1616
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
@@ -25,7 +25,7 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
2525
===DONE===
2626
<?php exit(0); ?>
2727
--EXPECT--
28-
0f0000000578000200000080ffff00
29-
{"x":{"$binary":{"base64":"\/\/8=","subType":"80"}}}
30-
0f0000000578000200000080ffff00
28+
1d000000057800100000000573ffd26444b34c6990e8e7d1dfc035d400
29+
{"x":{"$binary":{"base64":"c\/\/SZESzTGmQ6OfR38A11A==","subType":"05"}}}
30+
1d000000057800100000000573ffd26444b34c6990e8e7d1dfc035d400
3131
===DONE===

tests/bson-corpus/binary-valid-010.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Binary type: $type query operator (conflicts with legacy $binary form with $type field)
2+
Binary type: subtype 0x80
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

@@ -9,8 +9,8 @@ DO NOT EDIT THIS FILE
99

1010
require_once __DIR__ . '/../utils/tools.php';
1111

12-
$canonicalBson = hex2bin('1F000000037800170000000224747970650007000000737472696E67000000');
13-
$canonicalExtJson = '{"x" : { "$type" : "string"}}';
12+
$canonicalBson = hex2bin('0F0000000578000200000080FFFF00');
13+
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "//8=", "subType" : "80"}}}';
1414

1515
// Canonical BSON -> Native -> Canonical BSON
1616
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
@@ -25,7 +25,7 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
2525
===DONE===
2626
<?php exit(0); ?>
2727
--EXPECT--
28-
1f000000037800170000000224747970650007000000737472696e67000000
29-
{"x":{"$type":"string"}}
30-
1f000000037800170000000224747970650007000000737472696e67000000
28+
0f0000000578000200000080ffff00
29+
{"x":{"$binary":{"base64":"\/\/8=","subType":"80"}}}
30+
0f0000000578000200000080ffff00
3131
===DONE===

tests/bson-corpus/binary-valid-011.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ DO NOT EDIT THIS FILE
99

1010
require_once __DIR__ . '/../utils/tools.php';
1111

12-
$canonicalBson = hex2bin('180000000378001000000010247479706500020000000000');
13-
$canonicalExtJson = '{"x" : { "$type" : {"$numberInt": "2"}}}';
12+
$canonicalBson = hex2bin('1F000000037800170000000224747970650007000000737472696E67000000');
13+
$canonicalExtJson = '{"x" : { "$type" : "string"}}';
1414

1515
// Canonical BSON -> Native -> Canonical BSON
1616
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
@@ -25,7 +25,7 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
2525
===DONE===
2626
<?php exit(0); ?>
2727
--EXPECT--
28-
180000000378001000000010247479706500020000000000
29-
{"x":{"$type":{"$numberInt":"2"}}}
30-
180000000378001000000010247479706500020000000000
28+
1f000000037800170000000224747970650007000000737472696e67000000
29+
{"x":{"$type":"string"}}
30+
1f000000037800170000000224747970650007000000737472696e67000000
3131
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Binary type: $type query operator (conflicts with legacy $binary form with $type field)
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/tools.php';
11+
12+
$canonicalBson = hex2bin('180000000378001000000010247479706500020000000000');
13+
$canonicalExtJson = '{"x" : { "$type" : {"$numberInt": "2"}}}';
14+
15+
// Canonical BSON -> Native -> Canonical BSON
16+
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
17+
18+
// Canonical BSON -> Canonical extJSON
19+
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";
20+
21+
// Canonical extJSON -> Canonical BSON
22+
echo bin2hex(fromJSON($canonicalExtJson)), "\n";
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
180000000378001000000010247479706500020000000000
29+
{"x":{"$type":{"$numberInt":"2"}}}
30+
180000000378001000000010247479706500020000000000
31+
===DONE===

0 commit comments

Comments
 (0)