diff --git a/Command/Proxy/ClearMetadataCacheDoctrineCommand.php b/Command/Proxy/ClearMetadataCacheDoctrineCommand.php index a0a8f924a..fa2679b3f 100644 --- a/Command/Proxy/ClearMetadataCacheDoctrineCommand.php +++ b/Command/Proxy/ClearMetadataCacheDoctrineCommand.php @@ -28,8 +28,13 @@ protected function configure() $this ->setName('doctrine:cache:clear-metadata') - ->setDescription('Clears all metadata cache for an entity manager') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setDescription('Clears all metadata cache for an entity manager'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/ClearQueryCacheDoctrineCommand.php b/Command/Proxy/ClearQueryCacheDoctrineCommand.php index 0c9bed837..0fcd00f7b 100644 --- a/Command/Proxy/ClearQueryCacheDoctrineCommand.php +++ b/Command/Proxy/ClearQueryCacheDoctrineCommand.php @@ -21,8 +21,13 @@ protected function configure() $this ->setName('doctrine:cache:clear-query') - ->setDescription('Clears all query cache for an entity manager') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setDescription('Clears all query cache for an entity manager'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/ClearResultCacheDoctrineCommand.php b/Command/Proxy/ClearResultCacheDoctrineCommand.php index 985b1b887..7371ecf54 100644 --- a/Command/Proxy/ClearResultCacheDoctrineCommand.php +++ b/Command/Proxy/ClearResultCacheDoctrineCommand.php @@ -21,8 +21,13 @@ protected function configure() $this ->setName('doctrine:cache:clear-result') - ->setDescription('Clears result cache for an entity manager') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setDescription('Clears result cache for an entity manager'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/CollectionRegionDoctrineCommand.php b/Command/Proxy/CollectionRegionDoctrineCommand.php index fbacd8eb8..5bd0a16eb 100644 --- a/Command/Proxy/CollectionRegionDoctrineCommand.php +++ b/Command/Proxy/CollectionRegionDoctrineCommand.php @@ -20,8 +20,13 @@ protected function configure() parent::configure(); $this - ->setName('doctrine:cache:clear-collection-region') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setName('doctrine:cache:clear-collection-region'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/ConvertMappingDoctrineCommand.php b/Command/Proxy/ConvertMappingDoctrineCommand.php index 2fa65c4dc..35d6e51f1 100644 --- a/Command/Proxy/ConvertMappingDoctrineCommand.php +++ b/Command/Proxy/ConvertMappingDoctrineCommand.php @@ -25,8 +25,13 @@ protected function configure() { parent::configure(); $this - ->setName('doctrine:mapping:convert') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setName('doctrine:mapping:convert'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/CreateSchemaDoctrineCommand.php b/Command/Proxy/CreateSchemaDoctrineCommand.php index 937ffea94..7736e92e7 100644 --- a/Command/Proxy/CreateSchemaDoctrineCommand.php +++ b/Command/Proxy/CreateSchemaDoctrineCommand.php @@ -22,8 +22,13 @@ protected function configure() $this ->setName('doctrine:schema:create') - ->setDescription('Executes (or dumps) the SQL needed to generate the database schema') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setDescription('Executes (or dumps) the SQL needed to generate the database schema'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/DropSchemaDoctrineCommand.php b/Command/Proxy/DropSchemaDoctrineCommand.php index 6ef60c2e0..0eb44f383 100644 --- a/Command/Proxy/DropSchemaDoctrineCommand.php +++ b/Command/Proxy/DropSchemaDoctrineCommand.php @@ -21,8 +21,13 @@ protected function configure() $this ->setName('doctrine:schema:drop') - ->setDescription('Executes (or dumps) the SQL needed to drop the current database schema') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setDescription('Executes (or dumps) the SQL needed to drop the current database schema'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/EnsureProductionSettingsDoctrineCommand.php b/Command/Proxy/EnsureProductionSettingsDoctrineCommand.php index f173d01ff..d7a63610b 100644 --- a/Command/Proxy/EnsureProductionSettingsDoctrineCommand.php +++ b/Command/Proxy/EnsureProductionSettingsDoctrineCommand.php @@ -20,8 +20,13 @@ protected function configure() parent::configure(); $this - ->setName('doctrine:ensure-production-settings') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setName('doctrine:ensure-production-settings'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/EntityRegionCacheDoctrineCommand.php b/Command/Proxy/EntityRegionCacheDoctrineCommand.php index ae7a7b6de..0e04e3842 100644 --- a/Command/Proxy/EntityRegionCacheDoctrineCommand.php +++ b/Command/Proxy/EntityRegionCacheDoctrineCommand.php @@ -20,8 +20,13 @@ protected function configure() parent::configure(); $this - ->setName('doctrine:cache:clear-entity-region') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setName('doctrine:cache:clear-entity-region'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/InfoDoctrineCommand.php b/Command/Proxy/InfoDoctrineCommand.php index efc60b84e..ae00b6c9f 100644 --- a/Command/Proxy/InfoDoctrineCommand.php +++ b/Command/Proxy/InfoDoctrineCommand.php @@ -18,8 +18,13 @@ class InfoDoctrineCommand extends InfoCommand protected function configure() { $this - ->setName('doctrine:mapping:info') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setName('doctrine:mapping:info'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/QueryRegionCacheDoctrineCommand.php b/Command/Proxy/QueryRegionCacheDoctrineCommand.php index 6adb3aa50..016c8fa4a 100644 --- a/Command/Proxy/QueryRegionCacheDoctrineCommand.php +++ b/Command/Proxy/QueryRegionCacheDoctrineCommand.php @@ -20,8 +20,13 @@ protected function configure() parent::configure(); $this - ->setName('doctrine:cache:clear-query-region') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setName('doctrine:cache:clear-query-region'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/RunDqlDoctrineCommand.php b/Command/Proxy/RunDqlDoctrineCommand.php index dc7d71d4b..099d87179 100644 --- a/Command/Proxy/RunDqlDoctrineCommand.php +++ b/Command/Proxy/RunDqlDoctrineCommand.php @@ -21,7 +21,6 @@ protected function configure() $this ->setName('doctrine:query:dql') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command') ->setHelp(<<%command.name% command executes the given DQL query and outputs the results: @@ -39,6 +38,12 @@ protected function configure() php %command.full_name% "SELECT u FROM UserBundle:User u" --first-result=0 --max-result=30 EOT ); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/UpdateSchemaDoctrineCommand.php b/Command/Proxy/UpdateSchemaDoctrineCommand.php index 98f80cdf6..0f1f96970 100644 --- a/Command/Proxy/UpdateSchemaDoctrineCommand.php +++ b/Command/Proxy/UpdateSchemaDoctrineCommand.php @@ -21,8 +21,13 @@ protected function configure() parent::configure(); $this - ->setName('doctrine:schema:update') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setName('doctrine:schema:update'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Command/Proxy/ValidateSchemaCommand.php b/Command/Proxy/ValidateSchemaCommand.php index 801dd74da..0c0e21365 100644 --- a/Command/Proxy/ValidateSchemaCommand.php +++ b/Command/Proxy/ValidateSchemaCommand.php @@ -20,8 +20,13 @@ protected function configure() parent::configure(); $this - ->setName('doctrine:schema:validate') - ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); + ->setName('doctrine:schema:validate'); + + if ($this->getDefinition()->hasOption('em')) { + return; + } + + $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } /** diff --git a/Tests/Command/Proxy/InfoDoctrineCommandTest.php b/Tests/Command/Proxy/InfoDoctrineCommandTest.php new file mode 100644 index 000000000..5cb69e1ae --- /dev/null +++ b/Tests/Command/Proxy/InfoDoctrineCommandTest.php @@ -0,0 +1,70 @@ +setupKernelMocks(); + + $application = new Application($kernel); + $application->add(new InfoDoctrineCommand()); + + $command = $application->find('doctrine:mapping:info'); + + $commandTester = new CommandTester($command); + $commandTester->execute( + array_merge(['command' => $command->getName()]) + ); + + $this->assertStringContainsString( + 'You do not have any mapped Doctrine ORM entities', + $commandTester->getDisplay() + ); + } + + /** + * @return MockObject&Kernel + */ + private function setupKernelMocks(): MockObject + { + $configuration = new Configuration(); + $configuration->setMetadataDriverImpl(new MappingDriverChain()); + + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); + + $manager = $this->getMockBuilder(EntityManagerInterface::class)->getMock(); + $manager->method('getConnection')->willReturn($connection); + $manager->method('getConfiguration')->willReturn($configuration); + + $registry = $this->getMockBuilder(ManagerRegistry::class)->disableOriginalConstructor()->getMock(); + $registry->method('getManager')->willReturn($manager); + + $container = $this->getMockBuilder(ContainerInterface::class)->getMock(); + $container->method('get')->willReturn($registry); + + $kernel = $this->getMockBuilder(Kernel::class); + $kernel->disableOriginalConstructor(); + $kernel = $kernel->getMock(); + $kernel->method('getBundles')->willReturn([]); + $kernel->method('getContainer')->willReturn($container); + + return $kernel; + } +} diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index 992cb6cb3..fa4832f2e 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests; +use Doctrine\Bundle\DoctrineBundle\Command\Proxy\InfoDoctrineCommand; +use Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand; use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\DbalTestKernel; use Doctrine\Common\Annotations\Reader; use Doctrine\Common\EventManager; @@ -72,6 +74,8 @@ public function testContainer(): void $this->assertInstanceOf(ProxyCacheWarmer::class, $container->get('doctrine.orm.proxy_cache_warmer')); $this->assertInstanceOf(ManagerRegistry::class, $container->get('doctrine')); $this->assertInstanceOf(UniqueEntityValidator::class, $container->get('doctrine.orm.validator.unique')); + $this->assertInstanceOf(InfoDoctrineCommand::class, $container->get('doctrine.mapping_info_command')); + $this->assertInstanceOf(UpdateSchemaDoctrineCommand::class, $container->get('doctrine.schema_update_command')); $this->assertSame($container->get('my.platform'), $container->get('doctrine.dbal.default_connection')->getDatabasePlatform());