|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Rules\Doctrine\ORM; |
| 4 | + |
| 5 | +use Iterator; |
| 6 | +use PHPStan\Rules\Rule; |
| 7 | +use PHPStan\Testing\RuleTestCase; |
| 8 | +use PHPStan\Type\Doctrine\ObjectMetadataResolver; |
| 9 | + |
| 10 | +/** |
| 11 | + * @extends RuleTestCase<EntityNotFinalRule> |
| 12 | + */ |
| 13 | +class EntityNotFinalRuleTest extends RuleTestCase |
| 14 | +{ |
| 15 | + |
| 16 | + protected function getRule(): Rule |
| 17 | + { |
| 18 | + return new EntityNotFinalRule( |
| 19 | + new ObjectMetadataResolver($this->createReflectionProvider(), __DIR__ . '/entity-manager.php', null) |
| 20 | + ); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * @dataProvider ruleProvider |
| 25 | + * @param string $file |
| 26 | + * @param mixed[] $expectedErrors |
| 27 | + */ |
| 28 | + public function testRule(string $file, array $expectedErrors): void |
| 29 | + { |
| 30 | + $this->analyse([$file], $expectedErrors); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @return \Iterator<mixed[]> |
| 35 | + */ |
| 36 | + public function ruleProvider(): Iterator |
| 37 | + { |
| 38 | + yield 'final entity' => [ |
| 39 | + __DIR__ . '/data/FinalEntity.php', |
| 40 | + [ |
| 41 | + [ |
| 42 | + 'Entity class PHPStan\Rules\Doctrine\ORM\FinalEntity is final which can cause problems with proxies.', |
| 43 | + 10, |
| 44 | + ], |
| 45 | + ], |
| 46 | + ]; |
| 47 | + |
| 48 | + yield 'final non-entity' => [ |
| 49 | + __DIR__ . '/data/FinalNonEntity.php', |
| 50 | + [], |
| 51 | + ]; |
| 52 | + |
| 53 | + yield 'correct entity' => [ |
| 54 | + __DIR__ . '/data/MyEntity.php', |
| 55 | + [], |
| 56 | + ]; |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments