|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace test\PhpStaticAnalysis\PHPStanExtension; |
| 4 | + |
| 5 | +class DefineTypeAttributeTest extends BaseAttributeTestCase |
| 6 | +{ |
| 7 | + public function testClassDefineTypeAttribute(): void |
| 8 | + { |
| 9 | + $errors = $this->analyse(__DIR__ . '/data/DefineType/ClassDefineTypeAttribute.php'); |
| 10 | + $this->assertCount(0, $errors); |
| 11 | + } |
| 12 | + |
| 13 | + public function testInterfaceDefineTypeAttribute(): void |
| 14 | + { |
| 15 | + $errors = $this->analyse(__DIR__ . '/data/DefineType/InterfaceDefineTypeAttribute.php'); |
| 16 | + $this->assertCount(0, $errors); |
| 17 | + } |
| 18 | + |
| 19 | + public function testTraitDefineTypeAttribute(): void |
| 20 | + { |
| 21 | + $errors = $this->analyse(__DIR__ . '/data/DefineType/TraitDefineTypeAttribute.php'); |
| 22 | + $this->assertCount(0, $errors); |
| 23 | + } |
| 24 | + |
| 25 | + public function testInvalidClassDefineTypeAttribute(): void |
| 26 | + { |
| 27 | + $errors = $this->analyse(__DIR__ . '/data/DefineType/InvalidClassDefineTypeAttribute.php'); |
| 28 | + |
| 29 | + $expectedErrors = [ |
| 30 | + 'PHPDoc tag @phpstan-type has invalid value (): Unexpected token "\n * ", expected type at offset 20' => 7, |
| 31 | + 'PHPDoc tag @phpstan-type name has invalid value: Unexpected token "(", expected TOKEN_PHPDOC_EOL at offset 72' => 7, |
| 32 | + 'PHPDoc tag @phpstan-type string has invalid value: Unexpected token "\n * ", expected type at offset 44' => 7, |
| 33 | + 'Parameter #1 ...$types of attribute class PhpStaticAnalysis\Attributes\DefineType constructor expects string, int given.' => 7, |
| 34 | + 'Type alias has an invalid name: string.' => 7, |
| 35 | + 'Attribute class PhpStaticAnalysis\Attributes\DefineType does not have the method target.' => 12, |
| 36 | + ]; |
| 37 | + |
| 38 | + $this->checkExpectedErrors($errors, $expectedErrors); |
| 39 | + } |
| 40 | +} |
0 commit comments