From 91b76a71ec75e88c7af73e2bbd6eff73ecd307f6 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 2 Apr 2024 23:57:52 -0400 Subject: [PATCH 1/2] Add `migrations create` alias with new backend --- src/MigrationsPlugin.php | 7 ++++++- tests/TestCase/Command/BakeMigrationCommandTest.php | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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); From 23efd4bceaccb15cf8093864631621c93c3b1e91 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 3 Apr 2024 00:54:39 -0400 Subject: [PATCH 2/2] Fix dump command phpstan --- src/Command/DumpCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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';