Skip to content

Commit

Permalink
Adding return of xml object to xml() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 20, 2010
1 parent ad62e0e commit 8f9adc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cake/console/libs/help_formatter.php
Expand Up @@ -152,7 +152,7 @@ protected function _getMaxLength($collection) {
* @param boolean $string Return the SimpleXml object or a string. Defaults to true.
* @return mixed. See $string
*/
public function xml($string = false) {
public function xml($string = true) {
$parser = $this->_parser;
$xml = new SimpleXmlElement('<shell></shell>');
$xml->addChild('commmand', $parser->command());
Expand All @@ -171,6 +171,6 @@ public function xml($string = false) {
foreach ($parser->arguments() as $argument) {
$argument->xml($arguments);
}
return $xml->asXml();
return $string ? $xml->asXml() : $xml;
}
}
16 changes: 16 additions & 0 deletions cake/tests/cases/console/libs/help_formatter.test.php
Expand Up @@ -421,4 +421,20 @@ function testXmlHelpWithOptionsAndArguments() {
TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match');
}

/**
* Test xml help as object
*
* @return void
*/
function testXmlHelpAsObject() {
$parser = new ConsoleOptionParser('mycommand', false);
$parser->addOption('test', array('help' => 'A test option.'))
->addArgument('model', array('help' => 'The model to make.', 'required' => true))
->addArgument('other_longer', array('help' => 'Another argument.'));

$formatter = new HelpFormatter($parser);
$result = $formatter->xml(false);
$this->assertType('SimpleXmlElement', $result);
}
}

0 comments on commit 8f9adc7

Please sign in to comment.