|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Rules\Generics; |
| 4 | + |
| 5 | +use PHPStan\Rules\ClassCaseSensitivityCheck; |
| 6 | +use PHPStan\Rules\ClassForbiddenNameCheck; |
| 7 | +use PHPStan\Rules\ClassNameCheck; |
| 8 | +use PHPStan\Rules\Rule; |
| 9 | +use PHPStan\Testing\RuleTestCase; |
| 10 | +use PHPStan\Type\FileTypeMapper; |
| 11 | + |
| 12 | +/** |
| 13 | + * @extends RuleTestCase<MethodTagTemplateTypeTraitRule> |
| 14 | + */ |
| 15 | +class MethodTagTemplateTypeTraitRuleTest extends RuleTestCase |
| 16 | +{ |
| 17 | + |
| 18 | + protected function getRule(): Rule |
| 19 | + { |
| 20 | + $reflectionProvider = $this->createReflectionProvider(); |
| 21 | + $typeAliasResolver = $this->createTypeAliasResolver(['TypeAlias' => 'int'], $reflectionProvider); |
| 22 | + |
| 23 | + return new MethodTagTemplateTypeTraitRule( |
| 24 | + new MethodTagTemplateTypeCheck( |
| 25 | + self::getContainer()->getByType(FileTypeMapper::class), |
| 26 | + new TemplateTypeCheck( |
| 27 | + $reflectionProvider, |
| 28 | + new ClassNameCheck( |
| 29 | + new ClassCaseSensitivityCheck($reflectionProvider, true), |
| 30 | + new ClassForbiddenNameCheck(self::getContainer()), |
| 31 | + ), |
| 32 | + new GenericObjectTypeCheck(), |
| 33 | + $typeAliasResolver, |
| 34 | + true, |
| 35 | + ), |
| 36 | + ), |
| 37 | + $reflectionProvider, |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + public function testRule(): void |
| 42 | + { |
| 43 | + $this->analyse([__DIR__ . '/data/method-tag-trait-template.php'], [ |
| 44 | + [ |
| 45 | + 'PHPDoc tag @method template U for method MethodTagTraitTemplate\HelloWorld::sayHello() has invalid bound type MethodTagTraitTemplate\Nonexisting.', |
| 46 | + 11, |
| 47 | + ], |
| 48 | + [ |
| 49 | + 'PHPDoc tag @method template for method MethodTagTraitTemplate\HelloWorld::sayHello() cannot have existing class stdClass as its name.', |
| 50 | + 11, |
| 51 | + ], |
| 52 | + [ |
| 53 | + 'PHPDoc tag @method template T for method MethodTagTraitTemplate\HelloWorld::sayHello() shadows @template T for class MethodTagTraitTemplate\HelloWorld.', |
| 54 | + 11, |
| 55 | + ], |
| 56 | + [ |
| 57 | + 'PHPDoc tag @method template for method MethodTagTraitTemplate\HelloWorld::typeAlias() cannot have existing type alias TypeAlias as its name.', |
| 58 | + 11, |
| 59 | + ], |
| 60 | + ]); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments