Skip to content
Permalink
Browse files

Add tests to the changes made to the CompletionShell and adjusts some…

… code to better deal with plugins having multiple shells
  • Loading branch information...
HavokInspiration committed Dec 3, 2015
1 parent e7639ff commit 82e315aea1029da2b8732f85ff477733d9b2e013
@@ -116,12 +116,16 @@ public function commands()
$options = [];
foreach ($shellList as $type => $commands) {
$prefix = '';
if (!in_array(strtolower($type), ['app', 'core']) && isset($duplicates[$type])) {
$prefix = $type . '.';
}
foreach ($commands as $shell) {
$prefix = '';
if (
!in_array(strtolower($type), ['app', 'core']) &&
isset($duplicates[$type]) &&
in_array($shell, $duplicates[$type])
) {
$prefix = $type . '.';
}
$options[] = $prefix . $shell;
}
}
@@ -192,6 +196,7 @@ public function getShell($commandName)
foreach ($shellList as $plugin => $commands) {
if (in_array($commandName, $commands)) {
$pluginDot = $plugin . '.';
break;
}
}
}
@@ -81,7 +81,7 @@ public function testMain()
$expected = "/\[.*TestPlugin.*\] example/";
$this->assertRegExp($expected, $output);
$expected = "/\[.*TestPluginTwo.*\] example, welcome/";
$expected = "/\[.*TestPluginTwo.*\] example, unique, welcome/";
$this->assertRegExp($expected, $output);
$expected = "/\[.*CORE.*\] i18n, orm_cache, plugin, routes, server/";
@@ -119,7 +119,7 @@ public function testCommands()
$this->Shell->runCommand(['commands']);
$output = $this->out->output;
$expected = "TestPlugin.example TestPlugin.sample TestPluginTwo.example TestPluginTwo.welcome " .
$expected = "TestPlugin.example TestPlugin.sample TestPluginTwo.example unique welcome " .
"i18n orm_cache plugin routes server i18m sample testing_dispatch\n";
$this->assertTextEquals($expected, $output);
}
@@ -195,13 +195,28 @@ public function testSubCommandsAppPlugin()
}
/**
* test that subCommands with a existing plugin command returns the proper sub commands
* test that subCommands with an existing plugin command returns the proper sub commands
* when the Shell name is unique and the dot notation not mandatory
*
* @return void
*/
public function testSubCommandsPlugin()
{
$this->Shell->runCommand(['subcommands', 'TestPluginTwo.welcome']);
$this->Shell->runCommand(['subcommands', 'welcome']);
$output = $this->out->output;
$expected = "say_hello\n";
$this->assertTextEquals($expected, $output);
}
/**
* test that subCommands with an existing plugin command returns the proper sub commands
*
* @return void
*/
public function testSubCommandsPluginDotNotation()
{
$this->Shell->runCommand(['subcommands', 'TestPluginTwo.example']);
$output = $this->out->output;
$expected = "say_hello\n";
@@ -33,4 +33,8 @@ public function main()
{
$this->out('This is the main method called from TestPluginTwo.ExampleShell');
}
public function say_hello() {
$this->out('Hello from the TestPluginTwo.ExampleShell');
}
}
@@ -0,0 +1,36 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* 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://cakephp.org CakePHP(tm) Project
* @since 1.2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Class UniqueShell
*
*/
namespace TestPluginTwo\Shell;
use Cake\Console\Shell;
class UniqueShell extends Shell
{
/**
* main method
*
* @return void
*/
public function main()
{
$this->out('This is the main method called from TestPluginTwo.UniqueShell');
}
}

0 comments on commit 82e315a

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