Browse Source

Remove --routes and --bootstrap options

In 4.x plugins define their default behavior so there isn't really
a need to enable the bootstrap/routes options unless you're turning
hooks off which isn't something the command supported historically.
Mark Story 6 years ago
parent
commit
fce5b993ea
2 changed files with 11 additions and 56 deletions
  1. 4 33
      src/Command/PluginLoadCommand.php
  2. 7 23
      tests/TestCase/Command/PluginLoadCommandTest.php

+ 4 - 33
src/Command/PluginLoadCommand.php

@@ -70,11 +70,9 @@ class PluginLoadCommand extends Command
             return static::CODE_ERROR;
         }
 
-        $options = $this->makeOptions($args);
-
         $app = APP . 'Application.php';
         if (file_exists($app)) {
-            $this->modifyApplication($app, $plugin, $options);
+            $this->modifyApplication($app, $plugin);
 
             return static::CODE_SUCCESS;
         }
@@ -83,33 +81,18 @@ class PluginLoadCommand extends Command
     }
 
     /**
-     * Create options string for the load call.
-     *
-     * @param \Cake\Console\Arguments $args The command arguments.
-     * @return string
-     */
-    protected function makeOptions(Arguments $args): string
-    {
-        $bootstrapString = $args->getOption('bootstrap') ? "'bootstrap' => true" : '';
-        $routesString = $args->getOption('routes') ? "'routes' => true" : '';
-
-        return implode(', ', array_filter([$bootstrapString, $routesString]));
-    }
-
-    /**
      * Modify the application class
      *
      * @param string $app The Application file to modify.
      * @param string $plugin The plugin name to add.
-     * @param string $options The plugin options to add
      * @return void
      */
-    protected function modifyApplication(string $app, string $plugin, string $options): void
+    protected function modifyApplication(string $app, string $plugin): void
     {
         $contents = file_get_contents($app);
 
-        $append = "\n        \$this->addPlugin('%s', [%s]);\n";
-        $insert = str_replace(', []', '', sprintf($append, $plugin, $options));
+        $append = "\n        \$this->addPlugin('%s');\n";
+        $insert = str_replace(', []', '', sprintf($append, $plugin));
 
         if (!preg_match('/function bootstrap\(\)(?:\s*)\:(?:\s*)void/m', $contents)) {
             $this->io->err('Your Application class does not have a bootstrap() method. Please add one.');
@@ -138,18 +121,6 @@ class PluginLoadCommand extends Command
         $parser->setDescription([
             'Command for loading plugins.',
         ])
-        ->addOption('bootstrap', [
-            'short' => 'b',
-            'help' => 'Will load bootstrap.php from plugin.',
-            'boolean' => true,
-            'default' => false,
-        ])
-        ->addOption('routes', [
-            'short' => 'r',
-            'help' => 'Will load routes.php from plugin.',
-            'boolean' => true,
-            'default' => false,
-        ])
         ->addArgument('plugin', [
             'help' => 'Name of the plugin to load.',
         ]);

+ 7 - 23
tests/TestCase/Command/PluginLoadCommandTest.php

@@ -69,31 +69,15 @@ class PluginLoadCommandTest extends TestCase
     }
 
     /**
-     * Test loading the app
-     *
-     * @return void
-     */
-    public function testLoadApp()
-    {
-        $this->exec('plugin load TestPlugin');
-        $this->assertExitCode(Command::CODE_SUCCESS);
-
-        $contents = file_get_contents($this->app);
-        $this->assertStringContainsString("\$this->addPlugin('TestPlugin');", $contents);
-    }
-
-    /**
-     * Test loading the app
+     * Test generating help succeeds
      *
      * @return void
      */
-    public function testLoadAppBootstrap()
+    public function testHelp()
     {
-        $this->exec('plugin load --bootstrap TestPlugin');
+        $this->exec('plugin load --help');
         $this->assertExitCode(Command::CODE_SUCCESS);
-
-        $contents = file_get_contents($this->app);
-        $this->assertStringContainsString("\$this->addPlugin('TestPlugin', ['bootstrap' => true]);", $contents);
+        $this->assertOutputContains('plugin load');
     }
 
     /**
@@ -101,12 +85,12 @@ class PluginLoadCommandTest extends TestCase
      *
      * @return void
      */
-    public function testLoadAppRoutes()
+    public function testLoadApp()
     {
-        $this->exec('plugin load --routes TestPlugin');
+        $this->exec('plugin load TestPlugin');
         $this->assertExitCode(Command::CODE_SUCCESS);
 
         $contents = file_get_contents($this->app);
-        $this->assertStringContainsString("\$this->addPlugin('TestPlugin', ['routes' => true]);", $contents);
+        $this->assertStringContainsString("\$this->addPlugin('TestPlugin');", $contents);
     }
 }