Skip to content

Commit

Permalink
Plugin classes should discover their own shell commands.
Browse files Browse the repository at this point in the history
Containing plugin command loading to the plugin makes it easier for
plugin developers to modify/replace the conventions/default behavior.
  • Loading branch information
markstory committed Mar 9, 2018
1 parent d96c600 commit dbccf7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Core/BasePlugin.php
Expand Up @@ -246,7 +246,7 @@ public function bootstrap(PluginApplicationInterface $app)
*/
public function console($commands)
{
return $commands;
return $commands->addMany($commands->discoverPlugin($this->getName()));
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Core/Plugin.php
Expand Up @@ -126,6 +126,7 @@ public static function load($plugin, array $config = [])
'autoload' => false,
'bootstrap' => false,
'routes' => false,
'console' => true,
'classBase' => 'src',
'ignoreMissing' => false,
'name' => $plugin
Expand Down
16 changes: 15 additions & 1 deletion tests/TestCase/Core/BasePluginTest.php
Expand Up @@ -81,13 +81,27 @@ public function testMiddleware()
$this->assertSame($middleware, $plugin->middleware($middleware));
}

public function testConsole()
public function testConsoleNoop()
{
$plugin = new BasePlugin();
$commands = new CommandCollection();
$this->assertSame($commands, $plugin->console($commands));
}

public function testConsoleFind()
{
$plugin = new TestPlugin();
Plugin::getCollection()->add($plugin);

$result = $plugin->console(new CommandCollection());

$this->assertTrue($result->has('widget'), 'Should have plugin command added');
$this->assertTrue($result->has('test_plugin.widget'), 'Should have long plugin name');

$this->assertTrue($result->has('example'), 'Should have plugin shell added');
$this->assertTrue($result->has('test_plugin.example'), 'Should have long plugin name');
}

public function testBootstrap()
{
$app = $this->createMock(PluginApplicationInterface::class);
Expand Down

0 comments on commit dbccf7d

Please sign in to comment.