Skip to content
Permalink
Browse files

Makes sure that App Shells and plugin Shells with the same name can c…

…o-exist

If an app shell and a plugin shell shares the same name, we have to make sure the correct subcommands will be returned for each one of them.
  • Loading branch information...
HavokInspiration committed Dec 3, 2015
1 parent 58ca430 commit c208e8841385242fcd02ebccdba0645af2b1e919
@@ -192,11 +192,14 @@ public function getShell($commandName)
if (empty($pluginDot)) {
$shellList = $this->getShellList();
unset($shellList['CORE'], $shellList['app']);
foreach ($shellList as $plugin => $commands) {
if (in_array($commandName, $commands)) {
$pluginDot = $plugin . '.';
break;
if (!in_array($commandName, $shellList['app']) && !in_array($commandName, $shellList['CORE'])) {
unset($shellList['CORE'], $shellList['app']);
foreach ($shellList as $plugin => $commands) {
if (in_array($commandName, $commands)) {
$pluginDot = $plugin . '.';
break;
}
}
}
}
@@ -17,6 +17,7 @@
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOutput;
use Cake\Console\Shell;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Shell\CompletionShell;
use Cake\Shell\Task\CommandTask;
@@ -51,6 +52,7 @@ class CompletionShellTest extends TestCase
public function setUp()
{
parent::setUp();
Configure::write('App.namespace', 'TestApp');
Plugin::load(['TestPlugin', 'TestPluginTwo']);
$this->out = new TestCompletionStringOutput();
@@ -78,6 +80,7 @@ public function tearDown()
{
parent::tearDown();
unset($this->Shell);
Configure::write('App.namespace', 'App');
Plugin::unload();
}
@@ -190,7 +193,7 @@ public function testSubCommandsAppPlugin()
$this->Shell->runCommand(['subcommands', 'app.sample']);
$output = $this->out->output;
$expected = '';
$expected = "derp\n";
$this->assertEquals($expected, $output);
}
@@ -237,6 +240,35 @@ public function testSubCommandsPluginDotNotation()
$this->assertTextEquals($expected, $output);
}
/**
* test that subCommands with an app shell that is also defined in a plugin and without the prefix "app."
* returns proper sub commands
*
* @return void
*/
public function testSubCommandsAppDuplicatePluginNoDot()
{
$this->Shell->runCommand(['subcommands', 'sample']);
$output = $this->out->output;
$expected = "derp\n";
$this->assertEquals($expected, $output);
}
/**
* test that subCommands with a plugin shell that is also defined in the returns proper sub commands
*
* @return void
*/
public function testSubCommandsPluginDuplicateApp()
{
$this->Shell->runCommand(['subcommands', 'TestPlugin.sample']);
$output = $this->out->output;
$expected = "example\n";
$this->assertEquals($expected, $output);
}
/**
* test that subcommands without arguments returns nothing
*
@@ -33,4 +33,14 @@ public function main()
{
$this->out('This is the main method called from SampleShell');
}
/**
* example method
*
* @return void
*/
public function example()
{
$this->out('This is the example method called from TestPlugin.SampleShell');
}
}
@@ -35,4 +35,14 @@ public function main()
{
$this->out('This is the main method called from SampleShell');
}
/**
* derp method
*
* @return void
*/
public function derp()
{
$this->out('This is the example method called from TestPlugin.SampleShell');
}
}

0 comments on commit c208e88

Please sign in to comment.
You can’t perform that action at this time.