@@ -88,4 +88,41 @@ public function testToString()
88
88
$ type = new CollectionType (new GenericType (Type::builtin (TypeIdentifier::ARRAY ), Type::string (), Type::bool ()));
89
89
$ this ->assertEquals ('array<string,bool> ' , (string ) $ type );
90
90
}
91
+
92
+ public function testAccept ()
93
+ {
94
+ $ type = new CollectionType (Type::generic (Type::builtin (TypeIdentifier::ARRAY ), Type::string (), Type::bool ()));
95
+
96
+ $ this ->assertFalse ($ type ->accept (new \ArrayObject (['foo ' => true , 'bar ' => true ])));
97
+
98
+ $ this ->assertTrue ($ type ->accept (['foo ' => true , 'bar ' => true ]));
99
+ $ this ->assertFalse ($ type ->accept (['foo ' => true , 'bar ' => 123 ]));
100
+ $ this ->assertFalse ($ type ->accept ([1 => true ]));
101
+
102
+ $ type = new CollectionType (Type::generic (Type::builtin (TypeIdentifier::ARRAY ), Type::int (), Type::bool ()));
103
+
104
+ $ this ->assertTrue ($ type ->accept ([1 => true ]));
105
+ $ this ->assertFalse ($ type ->accept (['foo ' => true ]));
106
+
107
+ $ type = new CollectionType (Type::generic (Type::builtin (TypeIdentifier::ARRAY ), Type::int (), Type::bool ()), isList: true );
108
+
109
+ $ this ->assertTrue ($ type ->accept ([0 => true , 1 => false ]));
110
+ $ this ->assertFalse ($ type ->accept ([0 => true , 2 => false ]));
111
+
112
+ $ type = new CollectionType (Type::generic (Type::builtin (TypeIdentifier::ITERABLE ), Type::string (), Type::bool ()));
113
+
114
+ $ this ->assertTrue ($ type ->accept (new \ArrayObject (['foo ' => true , 'bar ' => true ])));
115
+ $ this ->assertFalse ($ type ->accept (new \ArrayObject (['foo ' => true , 'bar ' => 123 ])));
116
+ $ this ->assertFalse ($ type ->accept (new \ArrayObject ([1 => true ])));
117
+
118
+ $ type = new CollectionType (Type::generic (Type::builtin (TypeIdentifier::ITERABLE ), Type::int (), Type::bool ()));
119
+
120
+ $ this ->assertTrue ($ type ->accept (new \ArrayObject ([1 => true ])));
121
+ $ this ->assertFalse ($ type ->accept (new \ArrayObject (['foo ' => true ])));
122
+
123
+ $ type = new CollectionType (Type::generic (Type::builtin (TypeIdentifier::ITERABLE ), Type::int (), Type::bool ()), isList: true );
124
+
125
+ $ this ->assertTrue ($ type ->accept (new \ArrayObject ([0 => true , 1 => false ])));
126
+ $ this ->assertFalse ($ type ->accept (new \ArrayObject ([0 => true , 2 => false ])));
127
+ }
91
128
}
0 commit comments