Browse Source

Merge pull request #6893 from HavokInspiration/shell-commands-list

Fix available commands list
Mark Story 10 years ago
parent
commit
6b6f2222a9

+ 5 - 5
src/Shell/Task/CommandTask.php

@@ -43,15 +43,15 @@ class CommandTask extends Shell
         $plugins = Plugin::loaded();
         $shellList = array_fill_keys($plugins, null) + ['CORE' => null, 'app' => null];
 
-        $shells = $this->_scanDir(dirname(__DIR__));
-        $shells = array_diff($shells, $skipFiles, $hiddenCommands);
-        $shellList = $this->_appendShells('CORE', $shells, $shellList);
-
         $appPath = App::path('Shell');
         $appShells = $this->_scanDir($appPath[0]);
-        $appShells = array_diff($appShells, $shells, $skipFiles);
+        $appShells = array_diff($appShells, $skipFiles);
         $shellList = $this->_appendShells('app', $appShells, $shellList);
 
+        $shells = $this->_scanDir(dirname(__DIR__));
+        $shells = array_diff($shells, $appShells, $skipFiles, $hiddenCommands);
+        $shellList = $this->_appendShells('CORE', $shells, $shellList);
+
         foreach ($plugins as $plugin) {
             $pluginPath = Plugin::classPath($plugin) . 'Shell';
             $pluginShells = $this->_scanDir($pluginPath);

+ 23 - 1
tests/TestCase/Shell/CommandListShellTest.php

@@ -89,11 +89,33 @@ class CommandListShellTest extends TestCase
         $expected = "/\[.*CORE.*\] i18n, orm_cache, plugin, server/";
         $this->assertRegExp($expected, $output);
 
-        $expected = "/\[.*app.*\] sample/";
+        $expected = "/\[.*app.*\] i18m, sample/";
         $this->assertRegExp($expected, $output);
     }
 
     /**
+     * If there is an app shell with the same name as a core shell,
+     * tests that the app shell is the one displayed and the core one is hidden.
+     *
+     * @return void
+     */
+    public function testMainAppPriority()
+    {
+        rename(APP . 'Shell' . DS . 'I18mShell.php', APP . 'Shell' . DS . 'I18nShell.php');
+        $this->Shell->main();
+        $output = $this->out->messages();
+        $output = implode("\n", $output);
+
+        $expected = "/\[.*CORE.*\] orm_cache, plugin, server/";
+        $this->assertRegExp($expected, $output);
+
+        $expected = "/\[.*app.*\] i18n, sample/";
+        $this->assertRegExp($expected, $output);
+
+        rename(APP . 'Shell' . DS . 'I18nShell.php', APP . 'Shell' . DS . 'I18mShell.php');
+    }
+
+    /**
      * test xml output.
      *
      * @return void

+ 1 - 1
tests/TestCase/Shell/CompletionShellTest.php

@@ -120,7 +120,7 @@ class CompletionShellTest extends TestCase
         $output = $this->out->output;
 
         $expected = "TestPlugin.example TestPlugin.sample " .
-            "TestPluginTwo.example TestPluginTwo.welcome i18n orm_cache plugin server sample testing_dispatch\n";
+            "TestPluginTwo.example TestPluginTwo.welcome i18n orm_cache plugin server i18m sample testing_dispatch\n";
         $this->assertTextEquals($expected, $output);
     }
 

+ 38 - 0
tests/test_app/TestApp/Shell/I18mShell.php

@@ -0,0 +1,38 @@
+<?php
+/**
+ * I18mShell file
+ *
+ * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
+ * @since         3.0.8
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+
+/**
+ * Class SampleShell
+ *
+ */
+namespace TestApp\Shell;
+
+use Cake\Console\Shell;
+
+class I18m extends Shell
+{
+
+    /**
+     * main method
+     *
+     * @return void
+     */
+    public function main()
+    {
+        $this->out('This is the main method called from I18mShell');
+    }
+}