Skip to content

Commit

Permalink
check if bake is loaded in BakSimpleMigrationCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSimal committed Jan 19, 2025
1 parent 675b494 commit fa050b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Command/BakeSimpleMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\Core\Plugin;
use Cake\Utility\Inflector;
use Migrations\Util\Util;

Expand Down Expand Up @@ -105,6 +106,10 @@ public function getPath(Arguments $args): string
*/
public function execute(Arguments $args, ConsoleIo $io): ?int
{
if (!Plugin::isLoaded('Bake')) {
$io->err('Bake plugin is not loaded. Please load it first to generate a migration.');
$this->abort();
}
$this->extractCommonProperties($args);
$name = $args->getArgumentAt(0);
if (empty($name)) {
Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase/Command/BakeMigrationCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,16 @@ public function testActionWithoutValidPrefix()
$this->assertExitCode(BaseCommand::CODE_ERROR);
$this->assertErrorContains('When applying fields the migration name should start with one of the following prefixes: `Create`, `Drop`, `Add`, `Remove`, `Alter`.');
}

public function testBakeMigrationWithoutBake()
{
// Make sure to unload the Bake plugin
$this->createApp()->getEventManager()->on('Console.buildCommands', function ($event, $commands) {
Plugin::getCollection()->remove('Bake');
});

$this->exec('bake migration CreateUsers name:string --connection test');
$this->assertExitCode(BaseCommand::CODE_ERROR);
$this->assertErrorContains('Bake plugin is not loaded. Please load it first to generate a migration.');
}
}

0 comments on commit fa050b6

Please sign in to comment.