Skip to content

Commit

Permalink
Merge pull request #306 from FriendsOfCake/issue-305
Browse files Browse the repository at this point in the history
Fix error when bake plugin is not loaded.
  • Loading branch information
ADmad authored Nov 26, 2020
2 parents 3313f1c + 3fb8f65 commit 64b400e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"require-dev": {
"cakephp/twig-view": "^1.1.1",
"cakephp/bake": "^2.2.0",
"cakephp/bake": "^2.3",
"phpunit/phpunit": "~8.5.0",
"cakephp/cakephp-codesniffer": "^4.0",
"muffin/webservice": "^3.0@beta"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Search\Command;
namespace Search\Command\Bake;

use Bake\Command\BakeCommand;
use Bake\Utility\TemplateRenderer;
Expand All @@ -19,7 +19,7 @@
* src/Model/Filter/MyCustomFilterCollection.php
* src/Model/Filter/Admin/UsersFilterCollection.php
*/
class BakeFilterCollectionCommand extends BakeCommand
class FilterCollectionCommand extends BakeCommand
{
/**
* Task name used in path generation.
Expand Down
14 changes: 14 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Search;

use Cake\Console\CommandCollection;
use Cake\Core\BasePlugin;

class Plugin extends BasePlugin
Expand All @@ -27,4 +28,17 @@ class Plugin extends BasePlugin
* @var bool
*/
protected $routesEnabled = false;

/**
* Add console commands for the plugin.
*
* @param \Cake\Console\CommandCollection $commands The command collection to update
* @return \Cake\Console\CommandCollection
*/
public function console(CommandCollection $commands): CommandCollection
{
// Bake plugin handles discovery of bake commands itself.
// Since we currently only have a command class for bake command, we don't need to to anything here.
return $commands;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?php
declare(strict_types=1);

namespace Search\Test\TestCase\Command;
namespace Search\Test\TestCase\Command\Bake;

use Cake\Console\BaseCommand;
use Cake\Console\CommandCollection;
use Cake\Console\ConsoleInput;
use Cake\Core\Plugin;
use Cake\Filesystem\Folder;
use Cake\Event\EventManager;
use Cake\Filesystem\Filesystem;
use Cake\TestSuite\ConsoleIntegrationTestTrait;
use Cake\TestSuite\StringCompareTrait;
use Cake\TestSuite\TestCase;
use Search\Command\Bake\FilterCollectionCommand;

class BakeFilterCollectionCommandTest extends TestCase
class FilterCollectionCommandTest extends TestCase
{
use StringCompareTrait;
use ConsoleIntegrationTestTrait;
Expand Down Expand Up @@ -41,12 +44,17 @@ public function setUp(): void

$this->_in = $this->getMockBuilder(ConsoleInput::class)->getMock();

$files = (new Folder($this->_generatedBasePath))->findRecursive();
foreach ($files as $file) {
unlink($file);
}
$fs = new Filesystem();
$fs->deleteDir($this->_generatedBasePath);

$this->useCommandRunner();

EventManager::instance()->on(
'Console.buildCommands',
function ($event, CommandCollection $commands) {
$commands->add(FilterCollectionCommand::defaultName(), FilterCollectionCommand::class);
}
);
}

/**
Expand Down

0 comments on commit 64b400e

Please sign in to comment.