From 2b824ea9dfa9e2aef6b2b8e202efd486430e81d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 16 Jul 2017 23:48:35 +0200 Subject: [PATCH 1/3] Update ConsoleRunner command list Adding L2C commands and DBAL reserved words command. --- lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php index 706d99d33..a6f198507 100644 --- a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php @@ -92,13 +92,17 @@ class ConsoleRunner $cli->addCommands( [ // DBAL Commands - new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), + new \Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand(), + new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), // ORM Commands + new \Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand(), + new \Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), + new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand(), + new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), From d4b94e097a54dc0f53f2186c9da5445f507a8fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 21:47:50 +0200 Subject: [PATCH 2/3] Ensure that ConsoleRunner has the right command list --- .../ORM/Tools/Console/ConsoleRunnerTest.php | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php index 9d1966534..a53ba514d 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Tools\Console; use Doctrine\ORM\Tools\Console\ConsoleRunner; use Doctrine\ORM\Version; use Doctrine\Tests\DoctrineTestCase; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\HelperSet; /** @@ -12,15 +13,50 @@ use Symfony\Component\Console\Helper\HelperSet; * * @covers \Doctrine\ORM\Tools\Console\ConsoleRunner */ -class ConsoleRunnerTest extends DoctrineTestCase +final class ConsoleRunnerTest extends DoctrineTestCase { - public function testCreateApplication() + public function testCreateApplicationShouldReturnAnApplicationWithTheCorrectCommands() : void { $helperSet = new HelperSet(); $app = ConsoleRunner::createApplication($helperSet); - $this->assertInstanceOf('Symfony\Component\Console\Application', $app); - $this->assertSame($helperSet, $app->getHelperSet()); - $this->assertEquals(Version::VERSION, $app->getVersion()); + self::assertSame($helperSet, $app->getHelperSet()); + self::assertEquals(Version::VERSION, $app->getVersion()); + + self::assertTrue($app->has('dbal:import')); + self::assertTrue($app->has('dbal:reserved-words')); + self::assertTrue($app->has('dbal:run-sql')); + self::assertTrue($app->has('orm:clear-cache:region:collection')); + self::assertTrue($app->has('orm:clear-cache:region:entity')); + self::assertTrue($app->has('orm:clear-cache:region:query')); + self::assertTrue($app->has('orm:clear-cache:metadata')); + self::assertTrue($app->has('orm:clear-cache:query')); + self::assertTrue($app->has('orm:clear-cache:result')); + self::assertTrue($app->has('orm:convert-d1-schema')); + self::assertTrue($app->has('orm:convert-mapping')); + self::assertTrue($app->has('orm:convert:d1-schema')); + self::assertTrue($app->has('orm:convert:mapping')); + self::assertTrue($app->has('orm:ensure-production-settings')); + self::assertTrue($app->has('orm:generate-entities')); + self::assertTrue($app->has('orm:generate-proxies')); + self::assertTrue($app->has('orm:generate-repositories')); + self::assertTrue($app->has('orm:generate:entities')); + self::assertTrue($app->has('orm:generate:proxies')); + self::assertTrue($app->has('orm:generate:repositories')); + self::assertTrue($app->has('orm:info')); + self::assertTrue($app->has('orm:mapping:describe')); + self::assertTrue($app->has('orm:run-dql')); + self::assertTrue($app->has('orm:schema-tool:create')); + self::assertTrue($app->has('orm:schema-tool:drop')); + self::assertTrue($app->has('orm:schema-tool:update')); + self::assertTrue($app->has('orm:validate-schema')); + } + + public function testCreateApplicationShouldAppendGivenCommands() : void + { + $command = 'my:lovely-command'; + $app = ConsoleRunner::createApplication(new HelperSet(), [new Command($command)]); + + self::assertTrue($app->has($command)); } } From 5109322f7d7bb1e804943954b821c6fa561dcaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 21:52:58 +0200 Subject: [PATCH 3/3] Make explicit the design decisions of ConsoleRunner --- UPGRADE.md | 4 + .../ORM/Tools/Console/ConsoleRunner.php | 73 +++++++++---------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index a502c872e..3132aef98 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.6 +## Minor BC BREAK: `Doctrine\ORM\Tools\Console\ConsoleRunner` is now final + +Since it's just an utilitarian class and should not be inherited. + ## Minor BC BREAK: removed `Doctrine\ORM\Query\Parser#isInternalFunction` Method `Doctrine\ORM\Query\QueryException::associationPathInverseSideNotSupported` diff --git a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php index a6f198507..c6a265cc0 100644 --- a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php @@ -19,44 +19,44 @@ namespace Doctrine\ORM\Tools\Console; +use Doctrine\DBAL\Tools\Console as DBALConsole; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; +use Doctrine\ORM\Version; use Symfony\Component\Console\Application; use Symfony\Component\Console\Helper\HelperSet; -use Doctrine\ORM\Version; -use Doctrine\ORM\EntityManagerInterface; - -use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; -use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; /** * Handles running the Console Tools inside Symfony Console context. */ -class ConsoleRunner +final class ConsoleRunner { /** * Create a Symfony Console HelperSet * * @param EntityManagerInterface $entityManager + * * @return HelperSet */ - public static function createHelperSet(EntityManagerInterface $entityManager) + public static function createHelperSet(EntityManagerInterface $entityManager) : HelperSet { return new HelperSet( [ - 'db' => new ConnectionHelper($entityManager->getConnection()), - 'em' => new EntityManagerHelper($entityManager) + 'db' => new DBALConsole\Helper\ConnectionHelper($entityManager->getConnection()), + 'em' => new EntityManagerHelper($entityManager), ] ); } /** - * Runs console with the given helperset. + * Runs console with the given helper set. * * @param \Symfony\Component\Console\Helper\HelperSet $helperSet * @param \Symfony\Component\Console\Command\Command[] $commands * * @return void */ - static public function run(HelperSet $helperSet, $commands = []) + public static function run(HelperSet $helperSet, array $commands = []) : void { $cli = self::createApplication($helperSet, $commands); $cli->run(); @@ -71,7 +71,7 @@ class ConsoleRunner * * @return \Symfony\Component\Console\Application */ - static public function createApplication(HelperSet $helperSet, $commands = []) + public static function createApplication(HelperSet $helperSet, array $commands = []) : Application { $cli = new Application('Doctrine Command Line Interface', Version::VERSION); $cli->setCatchExceptions(true); @@ -87,40 +87,40 @@ class ConsoleRunner * * @return void */ - static public function addCommands(Application $cli) + public static function addCommands(Application $cli) : void { $cli->addCommands( [ // DBAL Commands - new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), - new \Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand(), - new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), + new DBALConsole\Command\ImportCommand(), + new DBALConsole\Command\ReservedWordsCommand(), + new DBALConsole\Command\RunSqlCommand(), // ORM Commands - new \Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), - new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), - new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), - new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), - new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), - new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), - new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), - new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), - new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), - new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), - new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), - new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(), - new \Doctrine\ORM\Tools\Console\Command\InfoCommand(), - new \Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand(), + new Command\ClearCache\CollectionRegionCommand(), + new Command\ClearCache\EntityRegionCommand(), + new Command\ClearCache\MetadataCommand(), + new Command\ClearCache\QueryCommand(), + new Command\ClearCache\QueryRegionCommand(), + new Command\ClearCache\ResultCommand(), + new Command\SchemaTool\CreateCommand(), + new Command\SchemaTool\UpdateCommand(), + new Command\SchemaTool\DropCommand(), + new Command\EnsureProductionSettingsCommand(), + new Command\ConvertDoctrine1SchemaCommand(), + new Command\GenerateRepositoriesCommand(), + new Command\GenerateEntitiesCommand(), + new Command\GenerateProxiesCommand(), + new Command\ConvertMappingCommand(), + new Command\RunDqlCommand(), + new Command\ValidateSchemaCommand(), + new Command\InfoCommand(), + new Command\MappingDescribeCommand(), ] ); } - static public function printCliConfigTemplate() + public static function printCliConfigTemplate() : void { echo <<<'HELP' You are missing a "cli-config.php" or "config/cli-config.php" file in your @@ -139,6 +139,5 @@ $entityManager = GetEntityManager(); return ConsoleRunner::createHelperSet($entityManager); HELP; - } }