Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migrations create alias with new backend #704

Merged
merged 2 commits into from
Apr 4, 2024
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
3 changes: 2 additions & 1 deletion src/Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed>
* @return array<int|string, mixed>
*/
public static function extractArgs(Arguments $args): array
{
/** @var array<int|string, mixed> $newArgs */
$newArgs = [];
if ($args->getOption('connection')) {
$newArgs[] = '-c';
Expand Down
7 changes: 6 additions & 1 deletion src/MigrationsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase/Command/BakeMigrationCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading