@@ -38,9 +38,10 @@ public function testConstraint($type, $value): void
38
38
39
39
public function provideTypes ()
40
40
{
41
- $ undefined = toPHP (fromJSON ('{ "undefined": {"$undefined": true} } ' ));
42
- $ symbol = toPHP (fromJSON ('{ "symbol": {"$symbol": "test"} } ' ));
43
- $ dbPointer = toPHP (fromJSON ('{ "dbPointer": {"$dbPointer": {"$ref": "phongo.test", "$id" : { "$oid" : "5a2e78accd485d55b405ac12" } }} } ' ));
41
+ $ undefined = toPHP (fromJSON ('{ "x": {"$undefined": true} } ' ))->x ;
42
+ $ symbol = toPHP (fromJSON ('{ "x": {"$symbol": "test"} } ' ))->x ;
43
+ $ dbPointer = toPHP (fromJSON ('{ "x": {"$dbPointer": {"$ref": "db.coll", "$id" : { "$oid" : "5a2e78accd485d55b405ac12" } }} } ' ))->x ;
44
+ $ long = PHP_INT_SIZE == 4 ? unserialize ('C:18:"MongoDB\BSON\Int64":38:{a:1:{s:7:"integer";s:10:"4294967296";}} ' ) : 4294967296 ;
44
45
45
46
return [
46
47
'double ' => ['double ' , 1.4 ],
@@ -52,22 +53,26 @@ public function provideTypes()
52
53
'array(indexed array) ' => ['array ' , ['foo ' ]],
53
54
'array(BSONArray) ' => ['array ' , new BSONArray ()],
54
55
'binData ' => ['binData ' , new Binary ('' , 0 )],
55
- 'undefined ' => ['undefined ' , $ undefined-> undefined ],
56
+ 'undefined ' => ['undefined ' , $ undefined ],
56
57
'objectId ' => ['objectId ' , new ObjectId ()],
57
58
'bool ' => ['bool ' , true ],
58
59
'date ' => ['date ' , new UTCDateTime ()],
59
60
'null ' => ['null ' , null ],
60
61
'regex ' => ['regex ' , new Regex ('.* ' )],
61
- 'dbPointer ' => ['dbPointer ' , $ dbPointer-> dbPointer ],
62
+ 'dbPointer ' => ['dbPointer ' , $ dbPointer ],
62
63
'javascript ' => ['javascript ' , new Javascript ('foo = 1; ' )],
63
- 'symbol ' => ['symbol ' , $ symbol-> symbol ],
64
+ 'symbol ' => ['symbol ' , $ symbol ],
64
65
'javascriptWithScope ' => ['javascriptWithScope ' , new Javascript ('foo = 1; ' , ['x ' => 1 ])],
65
66
'int ' => ['int ' , 1 ],
66
67
'timestamp ' => ['timestamp ' , new Timestamp (0 , 0 )],
67
- 'long ' => ['long ' , PHP_INT_SIZE == 4 ? unserialize ( ' C:18:"MongoDB\BSON\Int64":38:{a:1:{s:7:"integer";s:10:"4294967296";}} ' ) : 4294967296 ],
68
+ 'long ' => ['long ' , $ long ],
68
69
'decimal ' => ['decimal ' , new Decimal128 ('18446744073709551616 ' )],
69
70
'minKey ' => ['minKey ' , new MinKey ()],
70
71
'maxKey ' => ['maxKey ' , new MaxKey ()],
72
+ 'number(double) ' => ['number ' , 1.4 ],
73
+ 'number(decimal) ' => ['number ' , new Decimal128 ('18446744073709551616 ' )],
74
+ 'number(int) ' => ['number ' , 1 ],
75
+ 'number(long) ' => ['number ' , $ long ],
71
76
];
72
77
}
73
78
@@ -89,10 +94,20 @@ public function testAnyOf(): void
89
94
$ c = IsBsonType::anyOf ('double ' , 'int ' );
90
95
91
96
$ this ->assertResult (true , $ c , 1 , 'int is double or int ' );
92
- $ this ->assertResult (true , $ c , 1.4 , 'int is double or int ' );
97
+ $ this ->assertResult (true , $ c , 1.4 , 'double is double or int ' );
93
98
$ this ->assertResult (false , $ c , 'foo ' , 'string is not double or int ' );
94
99
}
95
100
101
+ public function testAnyOfWithNumberAlias (): void
102
+ {
103
+ $ c = IsBsonType::anyOf ('number ' , 'string ' );
104
+
105
+ $ this ->assertResult (true , $ c , 1 , 'int is number or string ' );
106
+ $ this ->assertResult (true , $ c , 1.4 , 'double is number or string ' );
107
+ $ this ->assertResult (true , $ c , 'foo ' , 'string is number or string ' );
108
+ $ this ->assertResult (false , $ c , true , 'bool is not number or string ' );
109
+ }
110
+
96
111
public function testErrorMessage (): void
97
112
{
98
113
$ c = new IsBsonType ('string ' );
0 commit comments