diff --git a/src/MigrationsPlugin.php b/src/MigrationsPlugin.php index 0c677430..e01cb4d9 100644 --- a/src/MigrationsPlugin.php +++ b/src/MigrationsPlugin.php @@ -131,15 +131,16 @@ public function console(CommandCollection $commands): CommandCollection return $commands; } + $classes = $this->migrationCommandsList; if (class_exists(SimpleBakeCommand::class)) { - $found = $commands->discoverPlugin($this->getName()); - - return $commands->addMany($found); + $classes[] = BakeMigrationCommand::class; + $classes[] = BakeMigrationDiffCommand::class; + $classes[] = BakeMigrationSnapshotCommand::class; + $classes[] = BakeSeedCommand::class; } $found = []; - // Convert to a method and use config to toggle command names. - foreach ($this->migrationCommandsList as $class) { + foreach ($classes as $class) { $name = $class::defaultName(); // If the short name has been used, use the full name. // This allows app commands to have name preference. diff --git a/tests/TestCase/MigrationsPluginTest.php b/tests/TestCase/MigrationsPluginTest.php new file mode 100644 index 00000000..1dcd8a02 --- /dev/null +++ b/tests/TestCase/MigrationsPluginTest.php @@ -0,0 +1,53 @@ +console($commands); + + $this->assertTrue($commands->has('migrations rollback')); + $this->assertSame(RollbackCommand::class, $commands->get('migrations rollback')); + } + + /** + * Test that phinx backend uses MigrationsRollbackCommand + * + * This is the reported bug in https://github.com/cakephp/migrations/issues/990 + */ + public function testConsolePhinxBackendUsesCorrectRollbackCommand(): void + { + Configure::write('Migrations.backend', 'phinx'); + + $plugin = new MigrationsPlugin(); + $commands = new CommandCollection(); + $commands = $plugin->console($commands); + + $this->assertTrue($commands->has('migrations rollback')); + // Bug: RollbackCommand is loaded instead of MigrationsRollbackCommand + $this->assertSame(MigrationsRollbackCommand::class, $commands->get('migrations rollback')); + } +}