15
15
use Symfony \Component \TypeInfo \Exception \LogicException ;
16
16
use Symfony \Component \TypeInfo \Tests \Fixtures \AbstractDummy ;
17
17
use Symfony \Component \TypeInfo \Tests \Fixtures \Dummy ;
18
+ use Symfony \Component \TypeInfo \Tests \Fixtures \DummyWithInvalidTypeAlias ;
18
19
use Symfony \Component \TypeInfo \Tests \Fixtures \DummyWithInvalidTypeAliasImport ;
20
+ use Symfony \Component \TypeInfo \Tests \Fixtures \DummyWithRecursiveTypeAliases ;
19
21
use Symfony \Component \TypeInfo \Tests \Fixtures \DummyWithTemplates ;
20
22
use Symfony \Component \TypeInfo \Tests \Fixtures \DummyWithTypeAliases ;
23
+ use Symfony \Component \TypeInfo \Tests \Fixtures \DummyWithTypeAliasImportedFromInvalidClassName ;
21
24
use Symfony \Component \TypeInfo \Tests \Fixtures \DummyWithUses ;
22
25
use Symfony \Component \TypeInfo \Type ;
23
26
use Symfony \Component \TypeInfo \TypeContext \TypeContextFactory ;
@@ -128,27 +131,33 @@ public function testCollectTypeAliases()
128
131
$ this ->assertEquals ([
129
132
'CustomString ' => Type::string (),
130
133
'CustomInt ' => Type::int (),
134
+ 'CustomArray ' => Type::arrayShape ([0 => Type::int (), 1 => Type::string (), 2 => Type::bool ()]),
131
135
'AliasedCustomInt ' => Type::int (),
132
136
'PsalmCustomString ' => Type::string (),
133
137
'PsalmCustomInt ' => Type::int (),
138
+ 'PsalmCustomArray ' => Type::arrayShape ([0 => Type::int (), 1 => Type::string (), 2 => Type::bool ()]),
134
139
'PsalmAliasedCustomInt ' => Type::int (),
135
140
], $ this ->typeContextFactory ->createFromClassName (DummyWithTypeAliases::class)->typeAliases );
136
141
137
142
$ this ->assertEquals ([
138
143
'CustomString ' => Type::string (),
139
144
'CustomInt ' => Type::int (),
145
+ 'CustomArray ' => Type::arrayShape ([0 => Type::int (), 1 => Type::string (), 2 => Type::bool ()]),
140
146
'AliasedCustomInt ' => Type::int (),
141
147
'PsalmCustomString ' => Type::string (),
142
148
'PsalmCustomInt ' => Type::int (),
149
+ 'PsalmCustomArray ' => Type::arrayShape ([0 => Type::int (), 1 => Type::string (), 2 => Type::bool ()]),
143
150
'PsalmAliasedCustomInt ' => Type::int (),
144
151
], $ this ->typeContextFactory ->createFromReflection (new \ReflectionClass (DummyWithTypeAliases::class))->typeAliases );
145
152
146
153
$ this ->assertEquals ([
147
154
'CustomString ' => Type::string (),
148
155
'CustomInt ' => Type::int (),
156
+ 'CustomArray ' => Type::arrayShape ([0 => Type::int (), 1 => Type::string (), 2 => Type::bool ()]),
149
157
'AliasedCustomInt ' => Type::int (),
150
158
'PsalmCustomString ' => Type::string (),
151
159
'PsalmCustomInt ' => Type::int (),
160
+ 'PsalmCustomArray ' => Type::arrayShape ([0 => Type::int (), 1 => Type::string (), 2 => Type::bool ()]),
152
161
'PsalmAliasedCustomInt ' => Type::int (),
153
162
], $ this ->typeContextFactory ->createFromReflection (new \ReflectionProperty (DummyWithTypeAliases::class, 'localAlias ' ))->typeAliases );
154
163
}
@@ -167,4 +176,28 @@ public function testThrowWhenImportingInvalidAlias()
167
176
168
177
$ this ->typeContextFactory ->createFromClassName (DummyWithInvalidTypeAliasImport::class);
169
178
}
179
+
180
+ public function testThrowWhenCannotResolveTypeAlias ()
181
+ {
182
+ $ this ->expectException (LogicException::class);
183
+ $ this ->expectExceptionMessage ('Cannot resolve "Invalid" type alias. ' );
184
+
185
+ $ this ->typeContextFactory ->createFromClassName (DummyWithInvalidTypeAlias::class);
186
+ }
187
+
188
+ public function testThrowWhenTypeAliasNotImportedFromValidClassName ()
189
+ {
190
+ $ this ->expectException (LogicException::class);
191
+ $ this ->expectExceptionMessage ('Type alias "Invalid" is not imported from a valid class name. ' );
192
+
193
+ $ this ->typeContextFactory ->createFromClassName (DummyWithTypeAliasImportedFromInvalidClassName::class);
194
+ }
195
+
196
+ public function testThrowWhenImportingRecursiveTypeAliases ()
197
+ {
198
+ $ this ->expectException (LogicException::class);
199
+ $ this ->expectExceptionMessage ('Cannot resolve "Bar" type alias. ' );
200
+
201
+ $ this ->typeContextFactory ->createFromClassName (DummyWithRecursiveTypeAliases::class)->typeAliases ;
202
+ }
170
203
}
0 commit comments