diff --git a/src/DI/MigrationsExtension.php b/src/DI/MigrationsExtension.php index daa7c7e..f896d30 100644 --- a/src/DI/MigrationsExtension.php +++ b/src/DI/MigrationsExtension.php @@ -4,12 +4,17 @@ use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration; +use Doctrine\Migrations\Tools\Console\Command\CurrentCommand; use Doctrine\Migrations\Tools\Console\Command\DiffCommand; +use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand; use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand; use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; use Doctrine\Migrations\Tools\Console\Command\LatestCommand; +use Doctrine\Migrations\Tools\Console\Command\ListCommand; use Doctrine\Migrations\Tools\Console\Command\MigrateCommand; +use Doctrine\Migrations\Tools\Console\Command\RollupCommand; use Doctrine\Migrations\Tools\Console\Command\StatusCommand; +use Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand; use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand; use Doctrine\Migrations\Tools\Console\Command\VersionCommand; use Nette\DI\CompilerExtension; @@ -76,38 +81,71 @@ public function loadConfiguration(): void ->setFactory($this->prefix('@nettrineDependencyFactory') . '::createDependencyFactory'); // Register commands + + $builder->addDefinition($this->prefix('currentCommand')) + ->setFactory(CurrentCommand::class) + ->setAutowired(false) + ->addTag('console.command', CurrentCommand::getDefaultName()); + $builder->addDefinition($this->prefix('diffCommand')) ->setFactory(DiffCommand::class) ->setAutowired(false) - ->addTag('console.command', 'migrations:diff'); + ->addTag('console.command', DiffCommand::getDefaultName()); + + $builder->addDefinition($this->prefix('dumpSchemaCommand')) + ->setFactory(DumpSchemaCommand::class) + ->setAutowired(false) + ->addTag('console.command', DumpSchemaCommand::getDefaultName()); + $builder->addDefinition($this->prefix('executeCommand')) ->setFactory(ExecuteCommand::class) ->setAutowired(false) - ->addTag('console.command', 'migrations:execute'); + ->addTag('console.command', ExecuteCommand::getDefaultName()); + $builder->addDefinition($this->prefix('generateCommand')) ->setFactory(GenerateCommand::class) ->setAutowired(false) - ->addTag('console.command', 'migrations:generate'); + ->addTag('console.command', GenerateCommand::getDefaultName()); + $builder->addDefinition($this->prefix('latestCommand')) ->setFactory(LatestCommand::class) ->setAutowired(false) - ->addTag('console.command', 'migrations:latest'); + ->addTag('console.command', LatestCommand::getDefaultName()); + + $builder->addDefinition($this->prefix('listCommand')) + ->setFactory(ListCommand::class) + ->setAutowired(false) + ->addTag('console.command', ListCommand::getDefaultName()); + $builder->addDefinition($this->prefix('migrateCommand')) ->setFactory(MigrateCommand::class) ->setAutowired(false) - ->addTag('console.command', 'migrations:migrate'); + ->addTag('console.command', MigrateCommand::getDefaultName()); + + $builder->addDefinition($this->prefix('rollupCommand')) + ->setFactory(RollupCommand::class) + ->setAutowired(false) + ->addTag('console.command', RollupCommand::getDefaultName()); + $builder->addDefinition($this->prefix('statusCommand')) ->setFactory(StatusCommand::class) ->setAutowired(false) - ->addTag('console.command', 'migrations:status'); + ->addTag('console.command', StatusCommand::getDefaultName()); + + $builder->addDefinition($this->prefix('syncMetadataCommand')) + ->setFactory(SyncMetadataCommand::class) + ->setAutowired(false) + ->addTag('console.command', SyncMetadataCommand::getDefaultName()); + $builder->addDefinition($this->prefix('upToDateCommand')) ->setFactory(UpToDateCommand::class) ->setAutowired(false) - ->addTag('console.command', 'migrations:up-to-date'); + ->addTag('console.command', UpToDateCommand::getDefaultName()); + $builder->addDefinition($this->prefix('versionCommand')) ->setFactory(VersionCommand::class) ->setAutowired(false) - ->addTag('console.command', 'migrations:version'); + ->addTag('console.command', VersionCommand::getDefaultName()); } } diff --git a/tests/cases/Unit/DI/MigrationsExtensionTest.php b/tests/cases/Unit/DI/MigrationsExtensionTest.php index 889d56b..7b0685f 100644 --- a/tests/cases/Unit/DI/MigrationsExtensionTest.php +++ b/tests/cases/Unit/DI/MigrationsExtensionTest.php @@ -44,7 +44,7 @@ public function testDefault(): void /** @var Configuration $configuration */ $configuration = $container->getByType(Configuration::class); Assert::equal(['Migrations' => '/root/migrations'], $configuration->getMigrationDirectories()); - Assert::count(8, $container->findByType(DoctrineCommand::class)); + Assert::count(13, $container->findByType(DoctrineCommand::class)); // 4 default helpers Assert::count(4, iterator_to_array($container->getByType(Application::class)->getHelperSet())); } @@ -94,7 +94,7 @@ public function testWithoutConsole(): void /** @var Configuration $configuration */ $configuration = $container->getByType(Configuration::class); Assert::equal(['Migrations' => '/root/migrations'], $configuration->getMigrationDirectories()); - Assert::count(8, $container->findByType(DoctrineCommand::class)); + Assert::count(13, $container->findByType(DoctrineCommand::class)); } public function testDependencyFactory(): void