diff --git a/src/Command/ExecuteFixturesCommand.php b/src/Command/ExecuteFixturesCommand.php index c854478..99d9306 100644 --- a/src/Command/ExecuteFixturesCommand.php +++ b/src/Command/ExecuteFixturesCommand.php @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->purger->setEntityManager($this->entityManager); $this->executor->setPurger($this->purger); - if (empty($input->getOptions())) { + if ($input->getOption('class') === false) { $this->loader->loadFromDirectory($this->path); } else { $this->loader->loadFromFile($this->path . DIRECTORY_SEPARATOR . $input->getOption('class') . '.php'); diff --git a/src/Command/ListFixturesCommand.php b/src/Command/ListFixturesCommand.php index 9273609..3c90e5f 100644 --- a/src/Command/ListFixturesCommand.php +++ b/src/Command/ListFixturesCommand.php @@ -5,9 +5,7 @@ namespace Dot\DataFixtures\Command; use DateTimeImmutable; -use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Loader; -use Doctrine\Common\DataFixtures\Purger\ORMPurger; use ReflectionClass; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; @@ -22,18 +20,13 @@ class ListFixturesCommand extends Command protected static $defaultName = 'fixtures:list'; protected Loader $loader; - protected ORMPurger $purger; - protected ORMExecutor $executor; private string $path; - public function __construct(Loader $loader, ORMPurger $purger, ORMExecutor $executor, string $path) + public function __construct(Loader $loader, string $path) { parent::__construct(self::$defaultName); - - $this->loader = $loader; - $this->purger = $purger; - $this->executor = $executor; - $this->path = $path; + $this->loader = $loader; + $this->path = $path; } protected function configure(): void diff --git a/src/Factory/ExecuteFixturesCommandFactory.php b/src/Factory/ExecuteFixturesCommandFactory.php index a0ff327..f524275 100644 --- a/src/Factory/ExecuteFixturesCommandFactory.php +++ b/src/Factory/ExecuteFixturesCommandFactory.php @@ -29,18 +29,6 @@ public function __invoke(ContainerInterface $container): ExecuteFixturesCommand throw new NotFoundException('EntityManager not found.'); } - if (! $container->has(ORMPurger::class)) { - throw new NotFoundException('ORMPurger not found. '); - } - - if (! $container->has(Loader::class)) { - throw new NotFoundException('Loader not found. '); - } - - if (! $container->has(ORMExecutor::class)) { - throw new NotFoundException('ORMExecutor not found. '); - } - $path = $container->get('config')['doctrine']['fixtures'] ?? null; if (! is_string($path)) { throw new NotFoundException('Key `fixtures` not found in doctrine configuration.'); @@ -48,9 +36,9 @@ public function __invoke(ContainerInterface $container): ExecuteFixturesCommand return new ExecuteFixturesCommand( $container->get(EntityManager::class), - $container->get(Loader::class), - $container->get(ORMPurger::class), - $container->get(ORMExecutor::class), + new Loader(), + new ORMPurger(), + new ORMExecutor($container->get(EntityManager::class)), $path ); } diff --git a/src/Factory/ListFixturesCommandFactory.php b/src/Factory/ListFixturesCommandFactory.php index e696de7..b3ecf96 100644 --- a/src/Factory/ListFixturesCommandFactory.php +++ b/src/Factory/ListFixturesCommandFactory.php @@ -4,9 +4,7 @@ namespace Dot\DataFixtures\Factory; -use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Loader; -use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Dot\DataFixtures\Command\ListFixturesCommand; use Dot\DataFixtures\Exception\NotFoundException; use Psr\Container\ContainerExceptionInterface; @@ -30,9 +28,7 @@ public function __invoke(ContainerInterface $container): ListFixturesCommand } return new ListFixturesCommand( - $container->get(Loader::class), - $container->get(ORMPurger::class), - $container->get(ORMExecutor::class), + new Loader(), $path ); } diff --git a/test/Command/ExecuteFixturesCommandTest.php b/test/Command/ExecuteFixturesCommandTest.php index 7390990..561a2b3 100644 --- a/test/Command/ExecuteFixturesCommandTest.php +++ b/test/Command/ExecuteFixturesCommandTest.php @@ -64,7 +64,7 @@ public function testWillExecuteCommand(): void $command = new ExecuteFixturesCommand($entityManager, $loader, $purger, $executor, $path); $reflection = new ReflectionMethod(ExecuteFixturesCommand::class, 'execute'); - $result = $reflection->invoke($command, new ArgvInput(), new BufferedOutput()); + $result = $reflection->invoke($command, new ArgvInput([], $command->getDefinition()), new BufferedOutput()); $this->assertSame($result, Command::SUCCESS); } diff --git a/test/Command/ListFixturesCommandTest.php b/test/Command/ListFixturesCommandTest.php index 2f07a61..00ab579 100644 --- a/test/Command/ListFixturesCommandTest.php +++ b/test/Command/ListFixturesCommandTest.php @@ -4,13 +4,7 @@ namespace DotTest\DataFixtures\Command; -use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Loader; -use Doctrine\Common\DataFixtures\Purger\ORMPurger; -use Doctrine\Common\EventManager; -use Doctrine\DBAL\Configuration; -use Doctrine\DBAL\Connection; -use Doctrine\ORM\EntityManager; use Dot\DataFixtures\Command\ListFixturesCommand; use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\TestCase; @@ -29,11 +23,9 @@ class ListFixturesCommandTest extends TestCase */ public function testWillCreateCommand(): void { - $loader = $this->createMock(Loader::class); - $purger = $this->createMock(ORMPurger::class); - $executor = $this->createMock(ORMExecutor::class); - $path = getcwd() . '/data/doctrine/fixtures'; - $command = new ListFixturesCommand($loader, $purger, $executor, $path); + $loader = $this->createMock(Loader::class); + $path = getcwd() . '/data/doctrine/fixtures'; + $command = new ListFixturesCommand($loader, $path); $this->assertInstanceOf(ListFixturesCommand::class, $command); } @@ -43,23 +35,15 @@ public function testWillCreateCommand(): void */ public function testWillExecuteCommand(): void { - $configuration = $this->createMock(Configuration::class); - $connection = $this->createMock(Connection::class); - $entityManager = $this->createMock(EntityManager::class); - $eventManager = $this->createMock(EventManager::class); - $loader = $this->createMock(Loader::class); - $purger = $this->createMock(ORMPurger::class); - $executor = $this->createMock(ORMExecutor::class); - $connection->method('getConfiguration')->willReturn($configuration); - $entityManager->method('getConnection')->willReturn($connection); - $entityManager->method('getEventManager')->willReturn($eventManager); - $purger->method('getObjectManager')->willReturn($entityManager); + $loader = $this->createMock(Loader::class); $loader->method('getFixtures')->willReturnMap([ - [0 => []], + [ + [], + ], ]); $path = getcwd() . '/data/doctrine/fixtures'; - $command = new ListFixturesCommand($loader, $purger, $executor, $path); + $command = new ListFixturesCommand($loader, $path); $reflection = new ReflectionMethod(ListFixturesCommand::class, 'execute'); $result = $reflection->invoke( @@ -76,10 +60,8 @@ public function testWillExecuteCommand(): void public function testFunctions(): void { $loader = $this->createMock(Loader::class); - $purger = $this->createMock(ORMPurger::class); - $executor = $this->createMock(ORMExecutor::class); $path = getcwd() . '/data/doctrine/fixtures'; - $command = new ListFixturesCommand($loader, $purger, $executor, $path); + $command = new ListFixturesCommand($loader, $path); $defaultName = $command->getName(); $description = $command->getDescription(); $this->assertSame('fixtures:list', $defaultName); diff --git a/test/Exception/NotFoundExceptionTest.php b/test/Exception/NotFoundExceptionTest.php index 4c6cf3f..558062a 100644 --- a/test/Exception/NotFoundExceptionTest.php +++ b/test/Exception/NotFoundExceptionTest.php @@ -10,7 +10,7 @@ class NotFoundExceptionTest extends TestCase { - public function testCreate() + public function testCreate(): void { $exception = new NotFoundException(); $this->assertInstanceOf(NotFoundException::class, $exception); diff --git a/test/Factory/ExecuteFixturesCommandFactoryTest.php b/test/Factory/ExecuteFixturesCommandFactoryTest.php index aef442a..c9244bf 100644 --- a/test/Factory/ExecuteFixturesCommandFactoryTest.php +++ b/test/Factory/ExecuteFixturesCommandFactoryTest.php @@ -4,9 +4,6 @@ namespace DotTest\DataFixtures\Factory; -use Doctrine\Common\DataFixtures\Executor\ORMExecutor; -use Doctrine\Common\DataFixtures\Loader; -use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; @@ -52,60 +49,6 @@ public function testWillNotCreateServiceWithoutEntityManager(): void (new ExecuteFixturesCommandFactory())($this->container); } - /** - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - public function testWillNotCreateServiceWithoutLoader(): void - { - $this->container->method('has')->willReturnMap([ - [EntityManager::class, true], - [Loader::class, false], - [ORMPurger::class, true], - [ORMExecutor::class, true], - ['config', true], - ]); - $this->expectException(NotFoundException::class); - $this->expectExceptionMessage('Loader not found.'); - (new ExecuteFixturesCommandFactory())($this->container); - } - - /** - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - public function testWillNotCreateServiceWithoutPurger(): void - { - $this->container->method('has')->willReturnMap([ - [EntityManager::class, true], - [Loader::class, true], - [ORMPurger::class, false], - [ORMExecutor::class, true], - ['config', true], - ]); - $this->expectException(NotFoundException::class); - $this->expectExceptionMessage('ORMPurger not found.'); - (new ExecuteFixturesCommandFactory())($this->container); - } - - /** - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - public function testWillNotCreateServiceWithoutExecutor(): void - { - $this->container->method('has')->willReturnMap([ - [EntityManager::class, true], - [Loader::class, true], - [ORMPurger::class, true], - [ORMExecutor::class, false], - ['config', true], - ]); - $this->expectException(NotFoundException::class); - $this->expectExceptionMessage('ORMExecutor not found.'); - (new ExecuteFixturesCommandFactory())($this->container); - } - /** * @throws ContainerExceptionInterface * @throws NotFoundException @@ -115,9 +58,6 @@ public function testWillNotCreateServiceWithoutPath(): void { $this->container->method('has')->willReturnMap([ [EntityManager::class, true], - [Loader::class, true], - [ORMPurger::class, true], - [ORMExecutor::class, true], ['config', true], ]); $this->container->method('get') @@ -140,36 +80,20 @@ public function testPath(): void $connection = $this->createMock(Connection::class); $entityManager = $this->createMock(EntityManager::class); $eventManager = $this->createMock(EventManager::class); - $loader = $this->createMock(Loader::class); - $purger = $this->createMock(ORMPurger::class); - $executor = $this->createMock(ORMExecutor::class); $connection->method('getConfiguration')->willReturn($configuration); $entityManager->method('getConnection')->willReturn($connection); $entityManager->method('getEventManager')->willReturn($eventManager); - $purger->method('getObjectManager')->willReturn($entityManager); - $loader->method('getFixtures')->willReturnMap([ - [ - [], - ], - ]); + $this->container->method('has')->willReturnMap([ [EntityManager::class, true], - [Loader::class, true], - [ORMPurger::class, true], - [ORMExecutor::class, true], ['config', true], ]); $this->container->method('get')->willReturnMap([ [EntityManager::class, $entityManager], - [Loader::class, $loader], - [ORMPurger::class, $purger], - [ORMExecutor::class, $executor], ['config', ['doctrine' => ['fixtures' => getcwd() . '/data/doctrine/fixtures']]], ]); - $entityManager->method('getConnection')->willReturn($connection); - $connection->method('getConfiguration')->willReturn($configuration); $factory = (new ExecuteFixturesCommandFactory())($this->container); $this->assertInstanceOf(ExecuteFixturesCommand::class, $factory); $path = $this->container->get('config')['doctrine']['fixtures']; diff --git a/test/Factory/ListFixturesCommandFactoryTest.php b/test/Factory/ListFixturesCommandFactoryTest.php index 667b7d5..bdc53b4 100644 --- a/test/Factory/ListFixturesCommandFactoryTest.php +++ b/test/Factory/ListFixturesCommandFactoryTest.php @@ -4,10 +4,6 @@ namespace DotTest\DataFixtures\Factory; -use Doctrine\Common\DataFixtures\Executor\ORMExecutor; -use Doctrine\Common\DataFixtures\Loader; -use Doctrine\Common\DataFixtures\Purger\ORMPurger; -use Doctrine\ORM\EntityManager; use Dot\DataFixtures\Command\ListFixturesCommand; use Dot\DataFixtures\Exception\NotFoundException; use Dot\DataFixtures\Factory\ListFixturesCommandFactory; @@ -51,22 +47,12 @@ public function testWithoutConfig(): void /** * @throws ContainerExceptionInterface - * @throws Exception * @throws NotFoundException * @throws NotFoundExceptionInterface */ public function testPathWithConfig(): void { - $entityManager = $this->createMock(EntityManager::class); - $loader = $this->createMock(Loader::class); - $purger = $this->createMock(ORMPurger::class); - $executor = $this->createMock(ORMExecutor::class); - $this->container->method('get')->willReturnMap([ - [EntityManager::class, $entityManager], - [Loader::class, $loader], - [ORMPurger::class, $purger], - [ORMExecutor::class, $executor], ['config', ['doctrine' => ['fixtures' => getcwd() . '/data/doctrine/fixtures']]], ]); $factory = (new ListFixturesCommandFactory())($this->container);