Merge branch '2.6-remove-subcommand' into 2.6

Merge changes from cakephp/cakephp#4039 into 2.6. This will effectively
backports the changes to 2.6, and allows them to be merged into 3.0 at
the same time.

Closes #4039
This commit is contained in:
mark_story 2014-07-21 23:56:26 -04:00
commit 7a14ed7490
2 changed files with 26 additions and 0 deletions

View file

@ -410,6 +410,17 @@ class ConsoleOptionParser {
return $this; return $this;
} }
/**
* Remove a subcommand from the option parser.
*
* @param string $name The subcommand name to remove.
* @return $this
*/
public function removeSubcommand($name) {
unset($this->_subcommands[$name]);
return $this;
}
/** /**
* Add multiple subcommands at once. * Add multiple subcommands at once.
* *

View file

@ -476,6 +476,21 @@ class ConsoleOptionParserTest extends CakeTestCase {
$this->assertEquals('test', $result['test']->name()); $this->assertEquals('test', $result['test']->name());
} }
/**
* test removeSubcommand with an object.
*
* @return void
*/
public function testRemoveSubcommand() {
$parser = new ConsoleOptionParser('test', false);
$parser->addSubcommand(new ConsoleInputSubcommand('test'));
$result = $parser->subcommands();
$this->assertEquals(1, count($result));
$parser->removeSubcommand('test');
$result = $parser->subcommands();
$this->assertEquals(0, count($result), 'Remove a subcommand does not work');
}
/** /**
* test adding multiple subcommands * test adding multiple subcommands
* *