Skip to content
Permalink
Browse files

Fix XML output of HelpFormatter

Backport from #10339
  • Loading branch information...
chinpei215 committed Mar 10, 2017
1 parent 23080c4 commit 70926fbb7f9ed13739cc5abc84d5fa312d44ac09
@@ -159,7 +159,7 @@ public function xml(SimpleXmlElement $parent) {
$option = $parent->addChild('argument');
$option->addAttribute('name', $this->_name);
$option->addAttribute('help', $this->_help);
$option->addAttribute('required', $this->isRequired());
$option->addAttribute('required', (int)$this->isRequired());
$choices = $option->addChild('choices');
foreach ($this->_choices as $valid) {
$choices->addChild('choice', $valid);
@@ -205,10 +205,11 @@ public function xml(SimpleXmlElement $parent) {
$option->addAttribute('name', '--' . $this->_name);
$short = '';
if (strlen($this->_short)) {
$short = $this->_short;
$short = '-' . $this->_short;
}
$option->addAttribute('short', '-' . $short);
$option->addAttribute('boolean', $this->_boolean);
$option->addAttribute('short', $short);
$option->addAttribute('help', $this->_help);
$option->addAttribute('boolean', (int)$this->_boolean);
$option->addChild('default', $this->_default);
$choices = $option->addChild('choices');
foreach ($this->_choices as $valid) {
@@ -182,7 +182,6 @@ public function xml($string = true) {
$xml->addChild('command', $parser->command());
$xml->addChild('description', $parser->description());
$xml->addChild('epilog', $parser->epilog());
$subcommands = $xml->addChild('subcommands');
foreach ($parser->subcommands() as $command) {
$command->xml($subcommands);
@@ -195,6 +194,7 @@ public function xml($string = true) {
foreach ($parser->arguments() as $argument) {
$argument->xml($arguments);
}
$xml->addChild('epilog', $parser->epilog());
return $string ? $xml->asXml() : $xml;
}
@@ -299,8 +299,8 @@ public function testXmlHelpWithChoices() {
$expected = <<<TEXT
<?xml version="1.0"?>
<shell>
<name>mycommand</name>
<description>Description text</description>
<command>mycommand</command>
<description />
<subcommands />
<options>
<option name="--help" short="-h" help="Display this help." boolean="1">
@@ -322,11 +322,14 @@ public function testXmlHelpWithChoices() {
<choice>aro</choice>
</choices>
</argument>
<argument help="Another argument." name="other_longer" required="0">
<choices/>
</argument>
</arguments>
<epilog>epilog text</epilog>
<epilog />
</shell>
TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match');
$this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
}
/**
@@ -346,7 +349,7 @@ public function testXmlHelpDescriptionAndEpilog() {
$expected = <<<TEXT
<?xml version="1.0"?>
<shell>
<name>mycommand</name>
<command>mycommand</command>
<description>Description text</description>
<subcommands />
<options>
@@ -367,7 +370,7 @@ public function testXmlHelpDescriptionAndEpilog() {
<epilog>epilog text</epilog>
</shell>
TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match');
$this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
}
/**
@@ -385,7 +388,7 @@ public function testXmlHelpSubcommand() {
$expected = <<<TEXT
<?xml version="1.0"?>
<shell>
<name>mycommand</name>
<command>mycommand</command>
<description/>
<subcommands>
<command name="method" help="This is another command" />
@@ -404,7 +407,7 @@ public function testXmlHelpSubcommand() {
<epilog/>
</shell>
TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match');
$this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
}
/**
@@ -424,7 +427,7 @@ public function testXmlHelpWithOptions() {
$expected = <<<TEXT
<?xml version="1.0"?>
<shell>
<name>mycommand</name>
<command>mycommand</command>
<description/>
<subcommands/>
<options>
@@ -445,7 +448,7 @@ public function testXmlHelpWithOptions() {
<epilog/>
</shell>
TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match');
$this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
}
/**
@@ -464,7 +467,7 @@ public function testXmlHelpWithOptionsAndArguments() {
$expected = <<<TEXT
<?xml version="1.0"?>
<shell>
<name>mycommand</name>
<command>mycommand</command>
<description/>
<subcommands/>
<options>
@@ -488,7 +491,7 @@ public function testXmlHelpWithOptionsAndArguments() {
<epilog/>
</shell>
TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match');
$this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
}
/**

0 comments on commit 70926fb

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