Skip to content

Commit 44f54d9

Browse files
committed
PHPC-714: Generate BSON corpus tests
Generated from mongodb/specifications@784379e
1 parent 56f3a9d commit 44f54d9

File tree

863 files changed

+31431
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

863 files changed

+31431
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Array: Array length too long: eats outer terminator
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+
$bson = hex2bin('140000000461000D0000001030000A0000000000');
13+
14+
throws(function() use ($bson) {
15+
var_dump(toPHP($bson));
16+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECT--
22+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
23+
===DONE===
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Array: Array length too short: leaks terminator
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+
$bson = hex2bin('140000000461000B0000001030000A0000000000');
13+
14+
throws(function() use ($bson) {
15+
var_dump(toPHP($bson));
16+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECT--
22+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
23+
===DONE===
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Array: Invalid Array: bad string length in 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+
$bson = hex2bin('1A00000004666F6F00100000000230000500000062617A000000');
13+
14+
throws(function() use ($bson) {
15+
var_dump(toPHP($bson));
16+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECT--
22+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
23+
===DONE===
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Array: Empty
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+
$bson = hex2bin('0D000000046100050000000000');
13+
14+
// BSON to Canonical BSON
15+
echo bin2hex(fromPHP(toPHP($bson))), "\n";
16+
17+
// BSON to Canonical extJSON
18+
echo json_canonicalize(toJSON($bson)), "\n";
19+
20+
$json = '{"a" : []}';
21+
22+
// extJSON to Canonical extJSON
23+
echo json_canonicalize(toJSON(fromJSON($json))), "\n";
24+
25+
// extJSON to Canonical BSON
26+
echo bin2hex(fromJSON($json)), "\n";
27+
28+
?>
29+
===DONE===
30+
<?php exit(0); ?>
31+
--EXPECT--
32+
0d000000046100050000000000
33+
{"a":[]}
34+
{"a":[]}
35+
0d000000046100050000000000
36+
===DONE===
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Array: Single Element Array
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+
$bson = hex2bin('140000000461000C0000001030000A0000000000');
13+
14+
// BSON to Canonical BSON
15+
echo bin2hex(fromPHP(toPHP($bson))), "\n";
16+
17+
// BSON to Canonical extJSON
18+
echo json_canonicalize(toJSON($bson)), "\n";
19+
20+
$json = '{"a" : [10]}';
21+
22+
// extJSON to Canonical extJSON
23+
echo json_canonicalize(toJSON(fromJSON($json))), "\n";
24+
25+
// extJSON to Canonical BSON
26+
echo bin2hex(fromJSON($json)), "\n";
27+
28+
?>
29+
===DONE===
30+
<?php exit(0); ?>
31+
--EXPECT--
32+
140000000461000c0000001030000a0000000000
33+
{"a":[10]}
34+
{"a":[10]}
35+
140000000461000c0000001030000a0000000000
36+
===DONE===
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
Array: Single Element Array with index set incorrectly
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+
$bson = hex2bin('130000000461000B00000010000A0000000000');
13+
14+
// BSON to Canonical BSON
15+
echo bin2hex(fromPHP(toPHP($bson))), "\n";
16+
17+
$canonicalBson = hex2bin('140000000461000C0000001030000A0000000000');
18+
19+
// Canonical BSON to Canonical BSON
20+
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
21+
22+
// BSON to Canonical extJSON
23+
echo json_canonicalize(toJSON($bson)), "\n";
24+
25+
$json = '{"a" : [10]}';
26+
27+
// extJSON to Canonical extJSON
28+
echo json_canonicalize(toJSON(fromJSON($json))), "\n";
29+
30+
// Canonical BSON to Canonical extJSON
31+
echo json_canonicalize(toJSON($canonicalBson)), "\n";
32+
33+
// extJSON to Canonical BSON
34+
echo bin2hex(fromJSON($json)), "\n";
35+
36+
?>
37+
===DONE===
38+
<?php exit(0); ?>
39+
--EXPECT--
40+
140000000461000c0000001030000a0000000000
41+
140000000461000c0000001030000a0000000000
42+
{"a":[10]}
43+
{"a":[10]}
44+
{"a":[10]}
45+
140000000461000c0000001030000a0000000000
46+
===DONE===
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
Array: Single Element Array with index set incorrectly
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+
$bson = hex2bin('150000000461000D000000106162000A0000000000');
13+
14+
// BSON to Canonical BSON
15+
echo bin2hex(fromPHP(toPHP($bson))), "\n";
16+
17+
$canonicalBson = hex2bin('140000000461000C0000001030000A0000000000');
18+
19+
// Canonical BSON to Canonical BSON
20+
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
21+
22+
// BSON to Canonical extJSON
23+
echo json_canonicalize(toJSON($bson)), "\n";
24+
25+
$json = '{"a" : [10]}';
26+
27+
// extJSON to Canonical extJSON
28+
echo json_canonicalize(toJSON(fromJSON($json))), "\n";
29+
30+
// Canonical BSON to Canonical extJSON
31+
echo json_canonicalize(toJSON($canonicalBson)), "\n";
32+
33+
// extJSON to Canonical BSON
34+
echo bin2hex(fromJSON($json)), "\n";
35+
36+
?>
37+
===DONE===
38+
<?php exit(0); ?>
39+
--EXPECT--
40+
140000000461000c0000001030000a0000000000
41+
140000000461000c0000001030000a0000000000
42+
{"a":[10]}
43+
{"a":[10]}
44+
{"a":[10]}
45+
140000000461000c0000001030000a0000000000
46+
===DONE===
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Binary type: Length longer than document
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+
$bson = hex2bin('1D000000057800FF0000000573FFD26444B34C6990E8E7D1DFC035D400');
13+
14+
throws(function() use ($bson) {
15+
var_dump(toPHP($bson));
16+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECT--
22+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
23+
===DONE===
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Binary type: Negative length
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+
$bson = hex2bin('0D000000057800FFFFFFFF0000');
13+
14+
throws(function() use ($bson) {
15+
var_dump(toPHP($bson));
16+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECT--
22+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
23+
===DONE===
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Binary type: subtype 0x02 length 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+
$bson = hex2bin('13000000057800060000000203000000FFFF00');
13+
14+
throws(function() use ($bson) {
15+
var_dump(toPHP($bson));
16+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECT--
22+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
23+
===DONE===

0 commit comments

Comments
 (0)