diff --git a/src/Command/DumpCommand.php b/src/Command/DumpCommand.php index 22594681..8309f7f3 100644 --- a/src/Command/DumpCommand.php +++ b/src/Command/DumpCommand.php @@ -48,10 +48,11 @@ public static function defaultName(): string * Extract options for the dump command from another migrations option parser. * * @param \Cake\Console\Arguments $args - * @return array + * @return array */ public static function extractArgs(Arguments $args): array { + /** @var array $newArgs */ $newArgs = []; if ($args->getOption('connection')) { $newArgs[] = '-c'; diff --git a/src/MigrationsPlugin.php b/src/MigrationsPlugin.php index 4cff3d27..cab596b0 100644 --- a/src/MigrationsPlugin.php +++ b/src/MigrationsPlugin.php @@ -103,7 +103,8 @@ public function console(CommandCollection $commands): CommandCollection SeedCommand::class, StatusCommand::class, ]; - if (class_exists(SimpleBakeCommand::class)) { + $hasBake = class_exists(SimpleBakeCommand::class); + if ($hasBake) { $classes[] = BakeMigrationCommand::class; $classes[] = BakeMigrationDiffCommand::class; $classes[] = BakeMigrationSnapshotCommand::class; @@ -120,6 +121,10 @@ public function console(CommandCollection $commands): CommandCollection } $found['migrations.' . $name] = $class; } + if ($hasBake) { + $found['migrations create'] = BakeMigrationCommand::class; + } + $commands->addMany($found); return $commands; diff --git a/tests/TestCase/Command/BakeMigrationCommandTest.php b/tests/TestCase/Command/BakeMigrationCommandTest.php index 5a122166..a9484f6a 100644 --- a/tests/TestCase/Command/BakeMigrationCommandTest.php +++ b/tests/TestCase/Command/BakeMigrationCommandTest.php @@ -14,6 +14,7 @@ namespace Migrations\Test\TestCase\Command; use Cake\Console\BaseCommand; +use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\TestSuite\StringCompareTrait; use Migrations\Command\BakeMigrationCommand; @@ -111,12 +112,21 @@ public function testCreateDuplicateName() $this->assertErrorContains('A migration with the name `CreateUsers` already exists. Please use a different name.'); } + public function testCreateBuiltinAlias() + { + Configure::write('Migrations.backend', 'builtin'); + $this->exec('migrations create CreateUsers --connection test'); + $this->assertExitCode(BaseCommand::CODE_SUCCESS); + $this->assertOutputRegExp('/Wrote.*?CreateUsers\.php/'); + } + /** * Tests that baking a migration with the "drop" string inside the name generates a valid drop migration. */ public function testCreateDropMigration() { $this->exec('bake migration DropUsers --connection test'); + $this->assertOutputRegExp('/Wrote.*?DropUsers\.php/'); $file = glob(ROOT . DS . 'config' . DS . 'Migrations' . DS . '*_DropUsers.php'); $filePath = current($file);