Skip to content

Commit efb563a

Browse files
authored
Merge pull request #808 from cakephp/4.x-require-bake-for-baking
check if bake is loaded in BakeSimpleMigrationCommand
2 parents 675b494 + ea6d12f commit efb563a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Command/BakeSimpleMigrationCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Cake\Console\Arguments;
2121
use Cake\Console\ConsoleIo;
2222
use Cake\Console\ConsoleOptionParser;
23+
use Cake\Core\Plugin;
2324
use Cake\Utility\Inflector;
2425
use Migrations\Util\Util;
2526

@@ -105,6 +106,10 @@ public function getPath(Arguments $args): string
105106
*/
106107
public function execute(Arguments $args, ConsoleIo $io): ?int
107108
{
109+
if (!Plugin::isLoaded('Bake')) {
110+
$io->err('Bake plugin is not loaded. Please load it first to generate a migration.');
111+
$this->abort();
112+
}
108113
$this->extractCommonProperties($args);
109114
$name = $args->getArgumentAt(0);
110115
if (empty($name)) {

tests/TestCase/Command/BakeMigrationCommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,16 @@ public function testActionWithoutValidPrefix()
386386
$this->assertExitCode(BaseCommand::CODE_ERROR);
387387
$this->assertErrorContains('When applying fields the migration name should start with one of the following prefixes: `Create`, `Drop`, `Add`, `Remove`, `Alter`.');
388388
}
389+
390+
public function testBakeMigrationWithoutBake()
391+
{
392+
// Make sure to unload the Bake plugin
393+
$this->createApp()->getEventManager()->on('Console.buildCommands', function ($event, $commands) {
394+
Plugin::getCollection()->remove('Bake');
395+
});
396+
397+
$this->exec('bake migration CreateUsers name:string --connection test');
398+
$this->assertExitCode(BaseCommand::CODE_ERROR);
399+
$this->assertErrorContains('Bake plugin is not loaded. Please load it first to generate a migration.');
400+
}
389401
}

0 commit comments

Comments
 (0)