Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/MigrationsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
53 changes: 53 additions & 0 deletions tests/TestCase/MigrationsPluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);

namespace Migrations\Test\TestCase;

use Cake\Console\CommandCollection;
use Cake\Core\Configure;
use Cake\TestSuite\TestCase;
use Migrations\Command\MigrationsRollbackCommand;
use Migrations\Command\RollbackCommand;
use Migrations\MigrationsPlugin;

class MigrationsPluginTest extends TestCase
{
protected function tearDown(): void
{
parent::tearDown();
Configure::delete('Migrations.backend');
}

/**
* Test that builtin backend uses RollbackCommand
*/
public function testConsoleBuiltinBackendUsesCorrectRollbackCommand(): void
{
Configure::write('Migrations.backend', 'builtin');

$plugin = new MigrationsPlugin();
$commands = new CommandCollection();
$commands = $plugin->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'));
}
}
Loading