|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Reflection\Doctrine; |
| 4 | + |
| 5 | +final class EntityRepositoryClassReflectionExtensionTest extends \PHPStan\Testing\TestCase |
| 6 | +{ |
| 7 | + |
| 8 | + /** @var \PHPStan\Broker\Broker */ |
| 9 | + private $broker; |
| 10 | + |
| 11 | + /** @var \PHPStan\Reflection\Doctrine\EntityRepositoryClassReflectionExtension */ |
| 12 | + private $extension; |
| 13 | + |
| 14 | + protected function setUp(): void |
| 15 | + { |
| 16 | + $this->broker = $this->createBroker(); |
| 17 | + $this->extension = new EntityRepositoryClassReflectionExtension(); |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * @return mixed[] |
| 22 | + */ |
| 23 | + public function dataHasMethod(): array |
| 24 | + { |
| 25 | + return [ |
| 26 | + [\Doctrine\ORM\EntityRepository::class, 'findBy', true], |
| 27 | + [\Doctrine\ORM\EntityRepository::class, 'findByString', true], |
| 28 | + [\Doctrine\ORM\EntityRepository::class, 'findOneByString', true], |
| 29 | + [\Doctrine\ORM\EntityRepository::class, 'count', false], |
| 30 | + [\Doctrine\ORM\EntityRepository::class, 'find', false], |
| 31 | + [\Doctrine\ORM\EntityRepository::class, 'findAll', false], |
| 32 | + ]; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @dataProvider dataHasMethod |
| 37 | + * |
| 38 | + * @param string $className |
| 39 | + * @param string $method |
| 40 | + * @param bool $expectedResult |
| 41 | + */ |
| 42 | + public function testHasMethod(string $className, string $method, bool $expectedResult): void |
| 43 | + { |
| 44 | + $classReflection = $this->broker->getClass($className); |
| 45 | + |
| 46 | + self::assertSame($expectedResult, $this->extension->hasMethod($classReflection, $method)); |
| 47 | + } |
| 48 | + |
| 49 | + public function testGetMethod(): void |
| 50 | + { |
| 51 | + $methodName = 'findOneByString'; |
| 52 | + |
| 53 | + $classReflection = $this->broker->getClass(\Doctrine\ORM\EntityRepository::class); |
| 54 | + $methodReflection = $this->extension->getMethod($classReflection, $methodName); |
| 55 | + |
| 56 | + self::assertSame($methodName, $methodReflection->getName()); |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments