Adding return of xml object to xml() method.

This commit is contained in:
mark_story 2010-10-19 22:47:07 -04:00
parent ad62e0e3af
commit 8f9adc7b15
2 changed files with 18 additions and 2 deletions

View file

@ -152,7 +152,7 @@ class HelpFormatter {
* @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());
@ -171,6 +171,6 @@ class HelpFormatter {
foreach ($parser->arguments() as $argument) {
$argument->xml($arguments);
}
return $xml->asXml();
return $string ? $xml->asXml() : $xml;
}
}

View file

@ -421,4 +421,20 @@ TEXT;
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);
}
}