Skip to content

Commit

Permalink
Merge pull request #911 from cakephp/issue-909
Browse files Browse the repository at this point in the history
Fix error when trying to bake with non-existent plugins directory.
  • Loading branch information
dereuromark authored Feb 21, 2023
2 parents e7e795c + 63acf52 commit 4e1ac8f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Command/PluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
])->addOption('theme', [
'short' => 't',
'help' => 'The theme to use when baking code.',
'default' => Configure::read('Bake.theme') ?? '',
'default' => Configure::read('Bake.theme') ?: null,
'choices' => $this->_getBakeThemes(),
]);

Expand Down
21 changes: 16 additions & 5 deletions tests/TestCase/Command/PluginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class PluginCommandTest extends TestCase
{
protected $testAppFile = APP . 'Application.php';

protected $pluginsPath = TMP . 'plugin_task' . DS;

/**
* setUp method
*
Expand All @@ -47,11 +49,10 @@ public function setUp(): void
$this->useCommandRunner();

// Output into a safe place.
$path = TMP . 'plugin_task' . DS;
Configure::write('App.paths.plugins', [$path]);
Configure::write('App.paths.plugins', [$this->pluginsPath]);

// Create the test output path
mkdir($path, 0777, true);
mkdir($this->pluginsPath, 0777, true);

if (file_exists(APP . 'Application.php.bak')) {
rename(APP . 'Application.php.bak', APP . 'Application.php');
Expand All @@ -68,7 +69,7 @@ public function setUp(): void
public function tearDown(): void
{
$fs = new Filesystem();
$fs->deleteDir(TMP . 'plugin_task');
$fs->deleteDir($this->pluginsPath);

if (file_exists(APP . 'Application.php.bak')) {
rename(APP . 'Application.php.bak', APP . 'Application.php');
Expand All @@ -89,6 +90,16 @@ public function testMainBakePluginContents()
$this->assertPluginContents('SimpleExample');
}

public function testBakingWithNonExistentPluginsDir()
{
$fs = new Filesystem();
$fs->deleteDir($this->pluginsPath);

$this->exec('bake plugin SimpleExample', ['y', 'n']);
$this->assertExitCode(CommandInterface::CODE_SUCCESS);
$this->assertPluginContents('SimpleExample');
}

/**
* test creating a plugin with a custom app namespace.
*
Expand Down Expand Up @@ -211,7 +222,7 @@ public function testFindPathNonExistent()
$result = $command->findPath($paths, $io);

$this->assertNull($result, 'no return');
$this->assertSame(TMP . 'plugin_task' . DS, $command->path);
$this->assertSame($this->pluginsPath, $command->path);
}

/**
Expand Down

0 comments on commit 4e1ac8f

Please sign in to comment.