1
+ <?php
2
+
3
+ require ('_utils.php ' );
4
+
5
+ const TYPES = [
6
+ 'test_str ' => [['string ' ], 'string ' ],
7
+ 'test_string ' => [['string ' ], 'string ' ],
8
+ 'test_bool ' => [['bool ' ], 'bool ' ],
9
+ 'test_number_signed ' => [['int ' ], 'int ' ],
10
+ 'test_number_unsigned ' => [['int ' ], 'int ' ],
11
+ 'test_number_float ' => [['float ' ], 'float ' ],
12
+ 'test_array ' => [['array ' ], 'array ' ],
13
+ 'test_array ' => [['array ' ], 'array ' ],
14
+ 'test_array_assoc ' => [['array ' ], 'array ' ],
15
+ 'test_binary ' => [['string ' ], 'string ' ],
16
+ 'test_nullable ' => [['?string ' ], '?string ' ],
17
+ 'test_object ' => [['object ' ], 'object ' ],
18
+ 'test_closure ' => [[], 'RustClosure ' ],
19
+ 'test_closure_once ' => [['string ' ], 'RustClosure ' ],
20
+ 'test_callable ' => [['callable ' , 'string ' ], 'mixed ' ]
21
+ ];
22
+
23
+ function toStr (ReflectionNamedType |ReflectionUnionType |ReflectionIntersectionType |null $ v ): string {
24
+ if ($ v === null ) {
25
+ return '<null> ' ;
26
+ }
27
+ return match (true ) {
28
+ $ v instanceof ReflectionNamedType => $ v ->allowsNull () ? '? ' .$ v ->getName () : $ v ->getName (),
29
+ $ v instanceof ReflectionUnionType => $ v ->getName (),
30
+ $ v instanceof ReflectionIntersectionType => $ v ->getName (),
31
+ };
32
+ }
33
+
34
+ foreach (TYPES as $ func => [$ args , $ return ]) {
35
+ $ f = new ReflectionFunction ($ func );
36
+ assert (toStr ($ f ->getReturnType ()) === $ return , "Wrong return type of $ func, expected $ return, got " .((string )$ f ->getReturnType ()));
37
+ foreach ($ f ->getParameters () as $ idx => $ param ) {
38
+ assert (toStr ($ param ->getType ()) === $ args [$ idx ], "Wrong arg type $ idx of $ func, expected {$ args [$ idx ]}, got " .((string )$ param ->getType ()));
39
+ }
40
+ }
0 commit comments