Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 12324c4

Browse files
arnaud-lbondrejmirtes
authored andcommitted
Add parse error test
1 parent 1e2a8ec commit 12324c4

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

‎tests/PHPStan/Parser/TypeParserTest.php‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,22 @@ protected function setUp(): void
3737

3838
/**
3939
* @dataProvider provideParseData
40-
* @param string $input
41-
* @param TypeNode $expectedType
42-
* @param int $nextTokenType
40+
* @param string $input
41+
* @param TypeNode|\Exception $expectedResult
42+
* @param int $nextTokenType
4343
*/
44-
public function testParse(string $input, TypeNode$expectedType, int $nextTokenType = Lexer::TOKEN_END): void
44+
public function testParse(string $input, $expectedResult, int $nextTokenType = Lexer::TOKEN_END): void
4545
{
46+
if ($expectedResult instanceof \Exception) {
47+
$this->expectException(get_class($expectedResult));
48+
$this->expectExceptionMessage($expectedResult->getMessage());
49+
}
50+
4651
$tokens = new TokenIterator($this->lexer->tokenize($input));
4752
$typeNode = $this->typeParser->parse($tokens);
4853

49-
$this->assertSame((string) $expectedType, (string) $typeNode);
50-
$this->assertEquals($expectedType, $typeNode);
54+
$this->assertSame((string) $expectedResult, (string) $typeNode);
55+
$this->assertEquals($expectedResult, $typeNode);
5156
$this->assertSame($nextTokenType, $tokens->currentTokenType());
5257
}
5358

@@ -410,6 +415,24 @@ public function provideParseData(): array
410415
])
411416
),
412417
],
418+
[
419+
'array{',
420+
new \PHPStan\PhpDocParser\Parser\ParserException(
421+
'',
422+
Lexer::TOKEN_END,
423+
6,
424+
Lexer::TOKEN_IDENTIFIER
425+
),
426+
],
427+
[
428+
'array{a => int}',
429+
new \PHPStan\PhpDocParser\Parser\ParserException(
430+
'=>',
431+
Lexer::TOKEN_OTHER,
432+
8,
433+
Lexer::TOKEN_CLOSE_CURLY_BRACKET
434+
),
435+
],
413436
[
414437
'callable(): Foo',
415438
new CallableTypeNode(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /