Skip to content

Commit d957708

Browse files
committed
PHPC-1765 and PHPC-1821: DBRef and dot/dollar validation tests
Remove tests expecting client-side validation errors for dots/dollars in field names. Syncs BSON corpus tests with mongodb/specifications@a274fbf
1 parent a612c37 commit d957708

32 files changed

+367
-54
lines changed

tests/bson-corpus/binary-parseError-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
77
--FILE--
88
<?php
99

10-
require_once __DIR__ . '/../utils/tools.php';
10+
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
throws(function() {
1313
fromJSON('{"x" : { "$uuid" : { "data" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4"}}}');

tests/bson-corpus/binary-parseError-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
77
--FILE--
88
<?php
99

10-
require_once __DIR__ . '/../utils/tools.php';
10+
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
throws(function() {
1313
fromJSON('{"x" : { "$uuid" : "73ffd264-44b3-90e8-e7d1dfc035d4"}}');

tests/bson-corpus/binary-parseError-003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
77
--FILE--
88
<?php
99

10-
require_once __DIR__ . '/../utils/tools.php';
10+
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
throws(function() {
1313
fromJSON('{"x" : { "$uuid" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4"}}');

tests/bson-corpus/binary-parseError-004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
77
--FILE--
88
<?php
99

10-
require_once __DIR__ . '/../utils/tools.php';
10+
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
throws(function() {
1313
fromJSON('{"x" : { "$uuid" : "73ff-d26444b-34c6-990e8e-7d1dfc035d4"}}');

tests/bson-corpus/binary-parseError-005.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
77
--FILE--
88
<?php
99

10-
require_once __DIR__ . '/../utils/tools.php';
10+
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
throws(function() {
1313
fromJSON('{"x" : { "$uuid" : "----d264-44b3-4--9-90e8-e7d1dfc0----"}}');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
77
--FILE--
88
<?php
99

10-
require_once __DIR__ . '/../utils/tools.php';
10+
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
$canonicalBson = hex2bin('180000000378001000000010247479706500020000000000');
1313
$canonicalExtJson = '{"x" : { "$type" : {"$numberInt": "2"}}}';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
DBRef: DBRef
2+
Document type (DBRef sub-documents): DBRef
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
DBRef: DBRef with database
2+
Document type (DBRef sub-documents): DBRef with database
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

tests/bson-corpus/dbref-valid-003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
DBRef: DBRef with database and additional fields
2+
Document type (DBRef sub-documents): DBRef with database and additional fields
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

tests/bson-corpus/dbref-valid-004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
DBRef: DBRef with additional fields
2+
Document type (DBRef sub-documents): DBRef with additional fields
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
DBRef: Document with key names similar to those of a DBRef
2+
Document type (DBRef sub-documents): Document with key names similar to those of a DBRef
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Document type (DBRef sub-documents): DBRef with additional dollar-prefixed and dotted fields
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/basic.inc';
11+
12+
$canonicalBson = hex2bin('48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000');
13+
$canonicalExtJson = '{"dbref": {"$ref": "collection", "$id": {"$oid": "58921b3e6e32ab156a22b59e"}, "a.b": {"$numberInt": "1"}, "$c": {"$numberInt": "1"}}}';
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+
48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000
29+
{"dbref":{"$ref":"collection","$id":{"$oid":"58921b3e6e32ab156a22b59e"},"a.b":{"$numberInt":"1"},"$c":{"$numberInt":"1"}}}
30+
48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000
31+
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Document type (DBRef sub-documents): Sub-document resembles DBRef but $id is missing
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/basic.inc';
11+
12+
$canonicalBson = hex2bin('26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000');
13+
$canonicalExtJson = '{"dbref": {"$ref": "collection"}}';
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+
26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000
29+
{"dbref":{"$ref":"collection"}}
30+
26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000
31+
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Document type (DBRef sub-documents): Sub-document resembles DBRef but $ref is not a string
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/basic.inc';
11+
12+
$canonicalBson = hex2bin('2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000');
13+
$canonicalExtJson = '{"dbref": {"$ref": {"$numberInt": "1"}, "$id": {"$oid": "58921b3e6e32ab156a22b59e"}}}';
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+
2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000
29+
{"dbref":{"$ref":{"$numberInt":"1"},"$id":{"$oid":"58921b3e6e32ab156a22b59e"}}}
30+
2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000
31+
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Document type (DBRef sub-documents): Sub-document resembles DBRef but $db is not a string
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/basic.inc';
11+
12+
$canonicalBson = hex2bin('4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000');
13+
$canonicalExtJson = '{"dbref": {"$ref": "collection", "$id": {"$oid": "58921b3e6e32ab156a22b59e"}, "$db": {"$numberInt": "1"}}}';
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+
4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000
29+
{"dbref":{"$ref":"collection","$id":{"$oid":"58921b3e6e32ab156a22b59e"},"$db":{"$numberInt":"1"}}}
30+
4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000
31+
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Document type (sub-documents): Dollar-prefixed key in sub-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/basic.inc';
11+
12+
$canonicalBson = hex2bin('170000000378000F000000022461000200000062000000');
13+
$canonicalExtJson = '{"x" : {"$a" : "b"}}';
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+
170000000378000f000000022461000200000062000000
29+
{"x":{"$a":"b"}}
30+
170000000378000f000000022461000200000062000000
31+
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Document type (sub-documents): Dollar as key in sub-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/basic.inc';
11+
12+
$canonicalBson = hex2bin('160000000378000E0000000224000200000061000000');
13+
$canonicalExtJson = '{"x" : {"$" : "a"}}';
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+
160000000378000e0000000224000200000061000000
29+
{"x":{"$":"a"}}
30+
160000000378000e0000000224000200000061000000
31+
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Document type (sub-documents): Dotted key in sub-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/basic.inc';
11+
12+
$canonicalBson = hex2bin('180000000378001000000002612E62000200000063000000');
13+
$canonicalExtJson = '{"x" : {"a.b" : "c"}}';
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+
180000000378001000000002612e62000200000063000000
29+
{"x":{"a.b":"c"}}
30+
180000000378001000000002612e62000200000063000000
31+
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Document type (sub-documents): Dot as key in sub-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/basic.inc';
11+
12+
$canonicalBson = hex2bin('160000000378000E000000022E000200000061000000');
13+
$canonicalExtJson = '{"x" : {"." : "a"}}';
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+
160000000378000e000000022e000200000061000000
29+
{"x":{".":"a"}}
30+
160000000378000e000000022e000200000061000000
31+
===DONE===

tests/bson-corpus/top-parseError-034.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Top-level document validity: Bad DBRef (ref is number, not string)
2+
Top-level document validity: Bad $minKey (boolean, not integer)
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

@@ -10,7 +10,7 @@ DO NOT EDIT THIS FILE
1010
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
throws(function() {
13-
fromJSON('{"x" : {"$ref" : 42, "$id" : "abc"}}');
13+
fromJSON('{"a" : {"$minKey" : true}}');
1414
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
1515

1616
?>

tests/bson-corpus/top-parseError-035.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Top-level document validity: Bad DBRef (db is number, not string)
2+
Top-level document validity: Bad $minKey (wrong integer)
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

@@ -10,7 +10,7 @@ DO NOT EDIT THIS FILE
1010
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
throws(function() {
13-
fromJSON('{"x" : {"$ref" : "a", "$id" : "abc", "$db" : 42}}');
13+
fromJSON('{"a" : {"$minKey" : 0}}');
1414
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
1515

1616
?>

0 commit comments

Comments
 (0)