Skip to content

Commit 2824214

Browse files
committed
PHPC-331: Tests for BSON deserialization errors
1 parent 7fb6ab8 commit 2824214

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

tests/bson/bson-toPHP_error-001.phpt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
--TEST--
2+
BSON\toPHP(): Type map class must be both instantiatable and Unserializable
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
use MongoDB\BSON as BSON;
8+
9+
require_once __DIR__ . "/../utils/basic.inc";
10+
11+
abstract class MyAbstractDocument implements BSON\Unserializable
12+
{
13+
}
14+
15+
class MyDocument
16+
{
17+
}
18+
19+
$bson = fromJSON('{ "list" : [ 1, 2, 3 ], "map" : { "foo" : "bar" } }');
20+
$types = array('array', 'document', 'root');
21+
$classNames = array(
22+
'MissingClass',
23+
'MyAbstractDocument',
24+
'MyDocument',
25+
BSON_NAMESPACE . '\Unserializable'
26+
);
27+
28+
foreach ($types as $type) {
29+
foreach ($classNames as $className) {
30+
printf("Test typeMap: { \"%s\" : \"%s\" }\n", $type, $className);
31+
try {
32+
var_dump(toPHP($bson, array($type => $className)));
33+
} catch (MongoDB\Driver\Exception\InvalidArgumentException $e) {
34+
echo $e->getMessage(), "\n";
35+
}
36+
echo "\n";
37+
}
38+
}
39+
40+
?>
41+
===DONE===
42+
<?php exit(0); ?>
43+
--EXPECTF--
44+
Test typeMap: { "array" : "MissingClass" }
45+
Class MissingClass does not exist
46+
47+
Test typeMap: { "array" : "MyAbstractDocument" }
48+
Class MyAbstractDocument is not instantiatable
49+
50+
Test typeMap: { "array" : "MyDocument" }
51+
Class MyDocument does not implement %SBSON\Unserializable
52+
53+
Test typeMap: { "array" : "%SBSON\Unserializable" }
54+
Class %SBSON\Unserializable is not instantiatable
55+
56+
Test typeMap: { "document" : "MissingClass" }
57+
Class MissingClass does not exist
58+
59+
Test typeMap: { "document" : "MyAbstractDocument" }
60+
Class MyAbstractDocument is not instantiatable
61+
62+
Test typeMap: { "document" : "MyDocument" }
63+
Class MyDocument does not implement %SBSON\Unserializable
64+
65+
Test typeMap: { "document" : "%SBSON\Unserializable" }
66+
Class %SBSON\Unserializable is not instantiatable
67+
68+
Test typeMap: { "root" : "MissingClass" }
69+
Class MissingClass does not exist
70+
71+
Test typeMap: { "root" : "MyAbstractDocument" }
72+
Class MyAbstractDocument is not instantiatable
73+
74+
Test typeMap: { "root" : "MyDocument" }
75+
Class MyDocument does not implement %SBSON\Unserializable
76+
77+
Test typeMap: { "root" : "%SBSON\Unserializable" }
78+
Class %SBSON\Unserializable is not instantiatable
79+
80+
===DONE===

0 commit comments

Comments
 (0)