Skip to content

Commit

Permalink
Add new commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jankonas authored and f3l1x committed Feb 4, 2022
1 parent da00c34 commit c456135
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
54 changes: 46 additions & 8 deletions src/DI/MigrationsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

}
4 changes: 2 additions & 2 deletions tests/cases/Unit/DI/MigrationsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c456135

Please sign in to comment.