Skip to content

Commit

Permalink
CallableTypeNode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 9, 2024
1 parent 4c9c7ab commit c3761a0
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,69 @@ public function provideReturnTagsData(): Iterator
),
]),
];

yield [
'valid CallableTypeNode without space after "callable"',
'/** @return callable(int, string): void */',
new PhpDocNode([
new PhpDocTagNode(
'@return',
new ReturnTagValueNode(
new CallableTypeNode(new IdentifierTypeNode('callable'), [
new CallableTypeParameterNode(new IdentifierTypeNode('int'), false, false, '', false),
new CallableTypeParameterNode(new IdentifierTypeNode('string'), false, false, '', false),
], new IdentifierTypeNode('void'), []),
'',
),
),
]),
];

yield [
'valid CallableTypeNode with space after "callable"',
'/** @return callable (int, string): void */',
new PhpDocNode([
new PhpDocTagNode(
'@return',
new ReturnTagValueNode(
new CallableTypeNode(new IdentifierTypeNode('callable'), [
new CallableTypeParameterNode(new IdentifierTypeNode('int'), false, false, '', false),
new CallableTypeParameterNode(new IdentifierTypeNode('string'), false, false, '', false),
], new IdentifierTypeNode('void'), []),
'',
),
),
]),
];

yield [
'valid IdentifierTypeNode with space after "callable" turns the rest to description',
'/** @return callable (int, string) */',
new PhpDocNode([
new PhpDocTagNode(
'@return',
new ReturnTagValueNode(new IdentifierTypeNode('callable'), '(int, string)'),
),
]),
];

yield [
'invalid CallableTypeNode without space after "callable"',
'/** @return callable(int, string) */',
new PhpDocNode([
new PhpDocTagNode(
'@return',
new InvalidTagValueNode('callable(int, string)', new ParserException(
'(',
4,
20,
27,
null,
1,
)),
),
]),
];
}


Expand Down

0 comments on commit c3761a0

Please sign in to comment.