Merge pull request #6556 from lcobucci/fix/command-list
Update ConsoleRunner's command list
This commit is contained in:
commit
1d8c7f9bac
@ -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`
|
||||
|
@ -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,36 +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\RunSqlCommand(),
|
||||
new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),
|
||||
new DBALConsole\Command\ImportCommand(),
|
||||
new DBALConsole\Command\ReservedWordsCommand(),
|
||||
new DBALConsole\Command\RunSqlCommand(),
|
||||
|
||||
// ORM Commands
|
||||
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\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
|
||||
@ -135,6 +139,5 @@ $entityManager = GetEntityManager();
|
||||
return ConsoleRunner::createHelperSet($entityManager);
|
||||
|
||||
HELP;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user