1
1
--TEST--
2
- MongoDB\BSON\toPHP(): Type classes must be instantiatable and implement Unserializable
2
+ MongoDB\BSON\toPHP(): Type map classes must be instantiatable and implement Unserializable
3
3
--FILE--
4
4
<?php
5
5
@@ -9,32 +9,30 @@ abstract class MyAbstractDocument implements MongoDB\BSON\Unserializable {}
9
9
10
10
class MyDocument {}
11
11
12
- $ types = [
13
- 'array ' ,
14
- 'document ' ,
15
- 'root ' ,
16
- ];
12
+ trait MyTrait {}
17
13
18
14
$ classes = [
19
15
'MissingClass ' ,
20
- 'MyAbstractDocument ' ,
21
- 'MyDocument ' ,
22
- 'MongoDB\BSON\Unserializable ' ,
16
+ MyAbstractDocument::class,
17
+ MyDocument::class,
18
+ MyTrait::class,
19
+ MongoDB \BSON \Unserializable::class,
23
20
];
24
21
25
- $ bson = pack ('Vx ' , 5 ); // Empty document
26
-
27
- foreach ($ types as $ type ) {
28
- foreach ($ classes as $ class ) {
29
- $ typeMap = [$ type => $ class ];
22
+ foreach ($ classes as $ class ) {
23
+ $ typeMaps = [
24
+ ['array ' => $ class ],
25
+ ['document ' => $ class ],
26
+ ['root ' => $ class ],
27
+ ['fieldPaths ' => ['x ' => $ class ]],
28
+ ];
30
29
30
+ foreach ($ typeMaps as $ typeMap ) {
31
31
printf ("Test typeMap: %s \n" , json_encode ($ typeMap ));
32
32
33
- echo throws (function () use ($ bson , $ typeMap ) {
34
- toPHP ($ bson , $ typeMap );
35
- }, 'MongoDB\Driver\Exception\InvalidArgumentException ' ), "\n" ;
36
-
37
- echo "\n" ;
33
+ echo throws (function () use ($ typeMap ) {
34
+ toPHP (fromJSON ('{} ' ), $ typeMap );
35
+ }, MongoDB \Driver \Exception \InvalidArgumentException::class), "\n\n" ;
38
36
}
39
37
}
40
38
@@ -46,48 +44,80 @@ Test typeMap: {"array":"MissingClass"}
46
44
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
47
45
Class MissingClass does not exist
48
46
49
- Test typeMap: {"array ":"MyAbstractDocument "}
47
+ Test typeMap: {"document ":"MissingClass "}
50
48
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
51
- Class MyAbstractDocument is not instantiatable
49
+ Class MissingClass does not exist
52
50
53
- Test typeMap: {"array ":"MyDocument "}
51
+ Test typeMap: {"root ":"MissingClass "}
54
52
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
55
- Class MyDocument does not implement MongoDB\BSON\Unserializable
53
+ Class MissingClass does not exist
56
54
57
- Test typeMap: {"array":"MongoDB\\BSON\\Unserializable" }
55
+ Test typeMap: {"fieldPaths":{"x":"MissingClass"} }
58
56
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
59
- Class MongoDB\BSON\Unserializable is not instantiatable
57
+ Class MissingClass does not exist
60
58
61
- Test typeMap: {"document ":"MissingClass "}
59
+ Test typeMap: {"array ":"MyAbstractDocument "}
62
60
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
63
- Class MissingClass does not exist
61
+ Class MyAbstractDocument is not instantiatable
64
62
65
63
Test typeMap: {"document":"MyAbstractDocument"}
66
64
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
67
65
Class MyAbstractDocument is not instantiatable
68
66
69
- Test typeMap: {"document ":"MyDocument "}
67
+ Test typeMap: {"root ":"MyAbstractDocument "}
70
68
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
71
- Class MyDocument does not implement MongoDB\BSON\Unserializable
69
+ Class MyAbstractDocument is not instantiatable
72
70
73
- Test typeMap: {"document":"MongoDB\\BSON\\Unserializable" }
71
+ Test typeMap: {"fieldPaths":{"x":"MyAbstractDocument"} }
74
72
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
75
- Class MongoDB\BSON\Unserializable is not instantiatable
73
+ Class MyAbstractDocument is not instantiatable
76
74
77
- Test typeMap: {"root ":"MissingClass "}
75
+ Test typeMap: {"array ":"MyDocument "}
78
76
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
79
- Class MissingClass does not exist
77
+ Class MyDocument does not implement MongoDB\BSON\Unserializable
80
78
81
- Test typeMap: {"root ":"MyAbstractDocument "}
79
+ Test typeMap: {"document ":"MyDocument "}
82
80
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
83
- Class MyAbstractDocument is not instantiatable
81
+ Class MyDocument does not implement MongoDB\BSON\Unserializable
84
82
85
83
Test typeMap: {"root":"MyDocument"}
86
84
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
87
85
Class MyDocument does not implement MongoDB\BSON\Unserializable
88
86
87
+ Test typeMap: {"fieldPaths":{"x":"MyDocument"}}
88
+ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
89
+ Class MyDocument does not implement MongoDB\BSON\Unserializable
90
+
91
+ Test typeMap: {"array":"MyTrait"}
92
+ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
93
+ Trait MyTrait is not instantiatable
94
+
95
+ Test typeMap: {"document":"MyTrait"}
96
+ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
97
+ Trait MyTrait is not instantiatable
98
+
99
+ Test typeMap: {"root":"MyTrait"}
100
+ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
101
+ Trait MyTrait is not instantiatable
102
+
103
+ Test typeMap: {"fieldPaths":{"x":"MyTrait"}}
104
+ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
105
+ Trait MyTrait is not instantiatable
106
+
107
+ Test typeMap: {"array":"MongoDB\\BSON\\Unserializable"}
108
+ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
109
+ Interface MongoDB\BSON\Unserializable is not instantiatable
110
+
111
+ Test typeMap: {"document":"MongoDB\\BSON\\Unserializable"}
112
+ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
113
+ Interface MongoDB\BSON\Unserializable is not instantiatable
114
+
89
115
Test typeMap: {"root":"MongoDB\\BSON\\Unserializable"}
90
116
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
91
- Class MongoDB\BSON\Unserializable is not instantiatable
117
+ Interface MongoDB\BSON\Unserializable is not instantiatable
118
+
119
+ Test typeMap: {"fieldPaths":{"x":"MongoDB\\BSON\\Unserializable"}}
120
+ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
121
+ Interface MongoDB\BSON\Unserializable is not instantiatable
92
122
93
123
===DONE===
0 commit comments