mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Add Shell::$plugin and update getOptionParser()
Adding a plugin property allows the correct usage/help information to be generated. Fixes #2359
This commit is contained in:
parent
47b2f3e70c
commit
205bfb506f
4 changed files with 26 additions and 1 deletions
|
@ -79,6 +79,14 @@ class Shell extends Object {
|
|||
*/
|
||||
public $name = null;
|
||||
|
||||
/**
|
||||
* The name of the plugin the shell belongs to.
|
||||
* Is automatically set by ShellDispatcher when a shell is constructed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $plugin = null;
|
||||
|
||||
/**
|
||||
* Contains tasks to load and instantiate
|
||||
*
|
||||
|
@ -409,7 +417,8 @@ class Shell extends Object {
|
|||
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::getOptionParser
|
||||
*/
|
||||
public function getOptionParser() {
|
||||
$parser = new ConsoleOptionParser($this->name);
|
||||
$name = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
|
||||
$parser = new ConsoleOptionParser($name);
|
||||
return $parser;
|
||||
}
|
||||
|
||||
|
|
|
@ -219,6 +219,7 @@ class ShellDispatcher {
|
|||
));
|
||||
}
|
||||
$Shell = new $class();
|
||||
$Shell->plugin = trim($plugin, '.');
|
||||
return $Shell;
|
||||
}
|
||||
|
||||
|
|
|
@ -422,6 +422,8 @@ class ShellDispatcherTest extends CakeTestCase {
|
|||
$Dispatcher = new TestShellDispatcher();
|
||||
$result = $Dispatcher->getShell('test_plugin.example');
|
||||
$this->assertInstanceOf('ExampleShell', $result);
|
||||
$this->assertEquals('TestPlugin', $result->plugin);
|
||||
$this->assertEquals('Example', $result->name);
|
||||
|
||||
$Dispatcher = new TestShellDispatcher();
|
||||
$result = $Dispatcher->getShell('TestPlugin.example');
|
||||
|
|
|
@ -841,4 +841,17 @@ TEXT;
|
|||
$expected = 'TestApple';
|
||||
$this->assertEquals($expected, $this->Shell->TestApple->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that option parsers are created with the correct name/command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetOptionParser() {
|
||||
$this->Shell->name = 'test';
|
||||
$this->Shell->plugin = 'plugin';
|
||||
$parser = $this->Shell->getOptionParser();
|
||||
|
||||
$this->assertEquals('plugin.test', $parser->command());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue