Browse Source

Merge pull request #10339 from chinpei215/help-formatter-tests

Fix XML output of Cake\Console\HelpFormatter
Mark Story 9 years ago
parent
commit
4befc288cb

+ 1 - 1
src/Console/ConsoleInputArgument.php

@@ -186,7 +186,7 @@ class ConsoleInputArgument
         $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);

+ 4 - 3
src/Console/ConsoleInputOption.php

@@ -249,10 +249,11 @@ class ConsoleInputOption
         $option->addAttribute('name', '--' . $this->_name);
         $short = '';
         if (strlen($this->_short) > 0) {
-            $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) {

+ 1 - 1
src/Console/HelpFormatter.php

@@ -196,7 +196,6 @@ class HelpFormatter
         $xml->addChild('command', $parser->getCommand());
         $xml->addChild('description', $parser->getDescription());
 
-        $xml->addChild('epilog', $parser->getEpilog());
         $subcommands = $xml->addChild('subcommands');
         foreach ($parser->subcommands() as $command) {
             $command->xml($subcommands);
@@ -209,6 +208,7 @@ class HelpFormatter
         foreach ($parser->arguments() as $argument) {
             $argument->xml($arguments);
         }
+        $xml->addChild('epilog', $parser->getEpilog());
 
         return $string ? $xml->asXML() : $xml;
     }

+ 19 - 16
tests/TestCase/Console/HelpFormatterTest.php

@@ -314,8 +314,8 @@ xml;
         $expected = <<<xml
 <?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">
@@ -337,11 +337,14 @@ xml;
 			<choice>aro</choice>
 		</choices>
 	</argument>
+	<argument name="other_longer" help="Another argument." required="0">
+		<choices></choices>
+	</argument>
 </arguments>
-<epilog>epilog text</epilog>
+<epilog />
 </shell>
 xml;
-        $this->assertXmlStringNotEqualsXmlString($expected, $result, 'Help does not match');
+        $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
     }
 
     /**
@@ -362,7 +365,7 @@ xml;
         $expected = <<<xml
 <?xml version="1.0"?>
 <shell>
-<name>mycommand</name>
+<command>mycommand</command>
 <description>Description text</description>
 <subcommands />
 <options>
@@ -383,7 +386,7 @@ xml;
 <epilog>epilog text</epilog>
 </shell>
 xml;
-        $this->assertXmlStringNotEqualsXmlString($expected, $result, 'Help does not match');
+        $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
     }
 
     /**
@@ -402,7 +405,7 @@ xml;
         $expected = <<<xml
 <?xml version="1.0"?>
 <shell>
-<name>mycommand</name>
+<command>mycommand</command>
 <description/>
 <subcommands>
 	<command name="method" help="This is another command" />
@@ -421,7 +424,7 @@ xml;
 <epilog/>
 </shell>
 xml;
-        $this->assertXmlStringNotEqualsXmlString($expected, $result, 'Help does not match');
+        $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
     }
 
     /**
@@ -442,10 +445,14 @@ xml;
         $expected = <<<xml
 <?xml version="1.0"?>
 <shell>
-<name>mycommand</name>
+<command>mycommand</command>
 <description/>
 <subcommands/>
 <options>
+	<option name="--connection" short="-c" help="The connection to use." boolean="0">
+		<default>default</default>
+		<choices></choices>
+	</option>
 	<option name="--help" short="-h" help="Display this help." boolean="1">
 		<default></default>
 		<choices></choices>
@@ -454,16 +461,12 @@ xml;
 		<default></default>
 		<choices></choices>
 	</option>
-	<option name="--connection" short="-c" help="The connection to use." boolean="0">
-		<default>default</default>
-		<choices></choices>
-	</option>
 </options>
 <arguments/>
 <epilog/>
 </shell>
 xml;
-        $this->assertXmlStringNotEqualsXmlString($expected, $result, 'Help does not match');
+        $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
     }
 
     /**
@@ -483,7 +486,7 @@ xml;
         $expected = <<<xml
 <?xml version="1.0"?>
 <shell>
-	<name>mycommand</name>
+	<command>mycommand</command>
 	<description/>
 	<subcommands/>
 	<options>
@@ -507,7 +510,7 @@ xml;
 	<epilog/>
 </shell>
 xml;
-        $this->assertXmlStringNotEqualsXmlString($expected, $result, 'Help does not match');
+        $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
     }
 
     /**