diff --git a/tests/RobotLoaderClassFinderTest.php b/tests/RobotLoaderClassFinderTest.php index 6b1d246..59156a4 100644 --- a/tests/RobotLoaderClassFinderTest.php +++ b/tests/RobotLoaderClassFinderTest.php @@ -4,54 +4,63 @@ namespace Consistence\ClassFinder\RobotLoader; +use Generator; use Nette\Loaders\RobotLoader; use PHPUnit\Framework\Assert; class RobotLoaderClassFinderTest extends \PHPUnit\Framework\TestCase { - public function testFindClass(): void + /** + * @return mixed[][]|\Generator + */ + public function findByInterfaceDataProvider(): Generator { - $classList = array_values($this->getRobotLoaderClassFinder()->findByInterface(ExtendingClass::class)); - - Assert::assertContains(ExtendingClass::class, $classList); - Assert::assertCount(1, $classList); - } - - public function testFindClassAndChildren(): void - { - $classList = array_values($this->getRobotLoaderClassFinder()->findByInterface(BaseClass::class)); - sort($classList); - - $expected = [ - BaseClass::class, - ExtendingClass::class, + yield 'class' => [ + 'interfaceName' => ExtendingClass::class, + 'expectedClassList' => [ + ExtendingClass::class, + ], + ]; + yield 'class and children' => [ + 'interfaceName' => BaseClass::class, + 'expectedClassList' => [ + BaseClass::class, + ExtendingClass::class, + ], + ]; + yield 'not implemented interface' => [ + 'interfaceName' => NotImplementedInterface::class, + 'expectedClassList' => [ + NotImplementedInterface::class, + ], + ]; + yield 'interface and implementations' => [ + 'interfaceName' => BaseInterface::class, + 'expectedClassList' => [ + BaseClass::class, + BaseInterface::class, + ExtendingClass::class, + ExtendingInterface::class, + ], ]; - - Assert::assertEquals($expected, $classList); - } - - public function testFindInterface(): void - { - $classList = array_values($this->getRobotLoaderClassFinder()->findByInterface(NotImplementedInterface::class)); - - Assert::assertContains(NotImplementedInterface::class, $classList); - Assert::assertCount(1, $classList); } - public function testFindInterfaceAndImplementations(): void + /** + * @dataProvider findByInterfaceDataProvider + * + * @param string $interfaceName + * @param string[] $expectedClassList + */ + public function testFindByInterface( + string $interfaceName, + array $expectedClassList + ): void { - $classList = array_values($this->getRobotLoaderClassFinder()->findByInterface(BaseInterface::class)); + $classList = array_values($this->getRobotLoaderClassFinder()->findByInterface($interfaceName)); sort($classList); - $expected = [ - BaseClass::class, - BaseInterface::class, - ExtendingClass::class, - ExtendingInterface::class, - ]; - - Assert::assertEquals($expected, $classList); + Assert::assertEquals($expectedClassList, $classList); } private function getRobotLoaderClassFinder(): RobotLoaderClassFinder