Skip to content

Commit

Permalink
Fix available commands list if there is an app Shell with the same na…
Browse files Browse the repository at this point in the history
…me as a core one.
  • Loading branch information
HavokInspiration committed Jun 26, 2015
1 parent 25d6753 commit adcf9a8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Shell/Task/CommandTask.php
Expand Up @@ -43,15 +43,15 @@ public function getShellList()
$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);
Expand Down
24 changes: 23 additions & 1 deletion tests/TestCase/Shell/CommandListShellTest.php
Expand Up @@ -89,10 +89,32 @@ public function testMain()
$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.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/CompletionShellTest.php
Expand Up @@ -120,7 +120,7 @@ public function testCommands()
$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);
}

Expand Down
38 changes: 38 additions & 0 deletions 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');
}
}

0 comments on commit adcf9a8

Please sign in to comment.