|
6 | 6 | use PHPStan\PhpDocParser\Parser\PhpDocParser;
|
7 | 7 | use PHPStan\Rules\Rule;
|
8 | 8 | use PHPStan\Testing\RuleTestCase;
|
| 9 | +use function array_merge; |
9 | 10 |
|
10 | 11 | /**
|
11 | 12 | * @extends RuleTestCase<InvalidPhpDocTagValueRule>
|
12 | 13 | */
|
13 | 14 | class InvalidPhpDocTagValueRuleTest extends RuleTestCase
|
14 | 15 | {
|
15 | 16 |
|
| 17 | + private bool $checkAllInvalidPhpDocs; |
| 18 | + |
16 | 19 | protected function getRule(): Rule
|
17 | 20 | {
|
18 | 21 | return new InvalidPhpDocTagValueRule(
|
19 | 22 | self::getContainer()->getByType(Lexer::class),
|
20 | 23 | self::getContainer()->getByType(PhpDocParser::class),
|
| 24 | + $this->checkAllInvalidPhpDocs, |
21 | 25 | );
|
22 | 26 | }
|
23 | 27 |
|
24 |
| - public function testRule(): void |
| 28 | + public function dataRule(): iterable |
25 | 29 | {
|
26 |
| - $this->analyse([__DIR__ . '/data/invalid-phpdoc.php'], [ |
| 30 | + $errors = [ |
27 | 31 | [
|
28 | 32 | 'PHPDoc tag @param has invalid value (): Unexpected token "\n * ", expected type at offset 13',
|
29 | 33 | 25,
|
@@ -84,16 +88,44 @@ public function testRule(): void
|
84 | 88 | 'PHPDoc tag @var has invalid value ((Foo|Bar): Unexpected token "*/", expected \')\' at offset 18',
|
85 | 89 | 81,
|
86 | 90 | ],
|
87 |
| - ]); |
| 91 | + [ |
| 92 | + 'PHPDoc tag @var has invalid value ((Foo&): Unexpected token "*/", expected type at offset 15', |
| 93 | + 89, |
| 94 | + ], |
| 95 | + [ |
| 96 | + 'PHPDoc tag @var has invalid value ((Foo&): Unexpected token "*/", expected type at offset 15', |
| 97 | + 92, |
| 98 | + ], |
| 99 | + ]; |
| 100 | + |
| 101 | + yield [false, $errors]; |
| 102 | + yield [true, array_merge($errors, [ |
| 103 | + [ |
| 104 | + 'PHPDoc tag @var has invalid value ((Foo&): Unexpected token "*/", expected type at offset 15', |
| 105 | + 102, |
| 106 | + ], |
| 107 | + ])]; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * @dataProvider dataRule |
| 112 | + * @param list<array{0: string, 1: int, 2?: string}> $expectedErrors |
| 113 | + */ |
| 114 | + public function testRule(bool $checkAllInvalidPhpDocs, array $expectedErrors): void |
| 115 | + { |
| 116 | + $this->checkAllInvalidPhpDocs = $checkAllInvalidPhpDocs; |
| 117 | + $this->analyse([__DIR__ . '/data/invalid-phpdoc.php'], $expectedErrors); |
88 | 118 | }
|
89 | 119 |
|
90 | 120 | public function testBug4731(): void
|
91 | 121 | {
|
| 122 | + $this->checkAllInvalidPhpDocs = true; |
92 | 123 | $this->analyse([__DIR__ . '/data/bug-4731.php'], []);
|
93 | 124 | }
|
94 | 125 |
|
95 | 126 | public function testBug4731WithoutFirstTag(): void
|
96 | 127 | {
|
| 128 | + $this->checkAllInvalidPhpDocs = true; |
97 | 129 | $this->analyse([__DIR__ . '/data/bug-4731-no-first-tag.php'], []);
|
98 | 130 | }
|
99 | 131 |
|
|
0 commit comments