From c71a252deefdc1194b26dfa1801841a61bea682f Mon Sep 17 00:00:00 2001 From: robchett Date: Sat, 7 Oct 2023 16:04:48 +0100 Subject: [PATCH] Add tests for callable docblock parsing --- tests/TypeAnnotationTest.php | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index 8cd1fb218..459cc8034 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -679,6 +679,56 @@ class TypeAnnotationTest extends TestCase '$output===' => 'callable():int', ], ], + 'callableFormats' => [ + 'code' => '): array + * @psalm-type H callable(array $e): array + * @psalm-type I \Closure(int, int): string + * + * @method ma(): A + * @method mb(): B + * @method mc(): C + * @method md(): D + * @method me(): E + * @method mf(): F + * @method mg(): G + * @method mh(): H + * @method mi(): I + */ + class Foo { + public function __call(string $method, array $params) { return 1; } + } + + $foo = new \Foo(); + $output_ma = $foo->ma(); + $output_mb = $foo->mb(); + $output_mc = $foo->mc(); + $output_md = $foo->md(); + $output_me = $foo->me(); + $output_mf = $foo->mf(); + $output_mg = $foo->mg(); + $output_mh = $foo->mh(); + $output_mi = $foo->mi(); + ', + 'assertions' => [ + '$output_ma===' => 'callable(int, int):string', + '$output_mb===' => 'callable(int, int=):string', + '$output_mc===' => 'callable(int, string):void', + '$output_md===' => 'callable(string):mixed', + '$output_me===' => 'callable(float...):(int|null)', + '$output_mf===' => 'callable(float...):(int|null)', + '$output_mg===' => 'callable(array):array', + '$output_mh===' => 'callable(array):array', + '$output_mi===' => 'Closure(int, int):string', + ], + ], 'unionOfStringsContainingBraceChar' => [ 'code' => '