Skip to content

Commit ecbab6d

Browse files
committed
Split exceptions in bson-fromPHP-006.phpt into separate error test
1 parent 58f432f commit ecbab6d

File tree

2 files changed

+47
-36
lines changed

2 files changed

+47
-36
lines changed

tests/bson/bson-fromPHP-006.phpt

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,22 @@ BSON\fromPHP(): PHP documents with null bytes in field name
55

66
require_once __DIR__ . '/../utils/tools.php';
77

8-
echo "\nTesting array with one leading null byte in field name\n";
9-
echo throws(function() {
10-
fromPHP(["\0" => 1]);
11-
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
12-
13-
echo "\nTesting array with one trailing null byte in field name\n";
14-
echo throws(function() {
15-
fromPHP(["a\0" => 1]);
16-
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
17-
18-
echo "\nTesting array with multiple null bytes in field name\n";
19-
echo throws(function() {
20-
fromPHP(["\0\0\0" => 1]);
21-
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
22-
238
/* Per PHPC-884, field names with a leading null byte are ignored when encoding
249
* a document from an object's property hash table, since PHP uses leading bytes
2510
* to denote protected and private properties. */
2611
echo "\nTesting object with one leading null byte in field name\n";
2712
hex_dump(fromPHP((object) ["\0" => 1]));
2813

29-
echo "\nTesting object with one trailing null byte in field name\n";
30-
echo throws(function() {
31-
fromPHP((object) ["a\0" => 1]);
32-
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
33-
3414
echo "\nTesting object with multiple null bytes in field name\n";
3515
hex_dump(fromPHP((object) ["\0\0\0" => 1]));
3616

3717
?>
3818
===DONE===
3919
<?php exit(0); ?>
4020
--EXPECT--
41-
Testing array with one leading null byte in field name
42-
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
43-
BSON keys cannot contain null bytes. Unexpected null byte after "".
44-
45-
Testing array with one trailing null byte in field name
46-
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
47-
BSON keys cannot contain null bytes. Unexpected null byte after "a".
48-
49-
Testing array with multiple null bytes in field name
50-
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
51-
BSON keys cannot contain null bytes. Unexpected null byte after "".
52-
5321
Testing object with one leading null byte in field name
5422
0 : 05 00 00 00 00 [.....]
5523

56-
Testing object with one trailing null byte in field name
57-
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
58-
BSON keys cannot contain null bytes. Unexpected null byte after "a".
59-
6024
Testing object with multiple null bytes in field name
6125
0 : 05 00 00 00 00 [.....]
6226
===DONE===
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
BSON\fromPHP(): PHP documents with null bytes in field name
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/tools.php';
7+
8+
echo "\nTesting array with one leading null byte in field name\n";
9+
echo throws(function() {
10+
fromPHP(["\0" => 1]);
11+
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
12+
13+
echo "\nTesting array with one trailing null byte in field name\n";
14+
echo throws(function() {
15+
fromPHP(["a\0" => 1]);
16+
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
17+
18+
echo "\nTesting array with multiple null bytes in field name\n";
19+
echo throws(function() {
20+
fromPHP(["\0\0\0" => 1]);
21+
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
22+
23+
echo "\nTesting object with one trailing null byte in field name\n";
24+
echo throws(function() {
25+
fromPHP((object) ["a\0" => 1]);
26+
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
27+
28+
?>
29+
===DONE===
30+
<?php exit(0); ?>
31+
--EXPECT--
32+
Testing array with one leading null byte in field name
33+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
34+
BSON keys cannot contain null bytes. Unexpected null byte after "".
35+
36+
Testing array with one trailing null byte in field name
37+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
38+
BSON keys cannot contain null bytes. Unexpected null byte after "a".
39+
40+
Testing array with multiple null bytes in field name
41+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
42+
BSON keys cannot contain null bytes. Unexpected null byte after "".
43+
44+
Testing object with one trailing null byte in field name
45+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
46+
BSON keys cannot contain null bytes. Unexpected null byte after "a".
47+
===DONE===

0 commit comments

Comments
 (0)