Browse Source

Plugin classes should discover their own shell commands.

Containing plugin command loading to the plugin makes it easier for
plugin developers to modify/replace the conventions/default behavior.
Mark Story 8 years ago
parent
commit
dbccf7d677
3 changed files with 17 additions and 2 deletions
  1. 1 1
      src/Core/BasePlugin.php
  2. 1 0
      src/Core/Plugin.php
  3. 15 1
      tests/TestCase/Core/BasePluginTest.php

+ 1 - 1
src/Core/BasePlugin.php

@@ -246,7 +246,7 @@ class BasePlugin implements PluginInterface
      */
     public function console($commands)
     {
-        return $commands;
+        return $commands->addMany($commands->discoverPlugin($this->getName()));
     }
 
     /**

+ 1 - 0
src/Core/Plugin.php

@@ -126,6 +126,7 @@ class Plugin
             'autoload' => false,
             'bootstrap' => false,
             'routes' => false,
+            'console' => true,
             'classBase' => 'src',
             'ignoreMissing' => false,
             'name' => $plugin

+ 15 - 1
tests/TestCase/Core/BasePluginTest.php

@@ -81,13 +81,27 @@ class BasePluginTest extends TestCase
         $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);