Browse Source

Fix double error tags when option parsing fails.

When err() started adding formatting for us, we forgot to remove the
formatting added when handling option parser errors.

Refs #9394
Mark Story 9 years ago
parent
commit
8203e4ce6a
2 changed files with 31 additions and 1 deletions
  1. 1 1
      src/Console/Shell.php
  2. 30 0
      tests/TestCase/Console/ShellTest.php

+ 1 - 1
src/Console/Shell.php

@@ -417,7 +417,7 @@ class Shell
         try {
             list($this->params, $this->args) = $this->OptionParser->parse($argv);
         } catch (ConsoleException $e) {
-            $this->err('<error>Error: ' . $e->getMessage() . '</error>');
+            $this->err('Error: ' . $e->getMessage());
             $this->out($this->OptionParser->help($command));
 
             return false;

+ 30 - 0
tests/TestCase/Console/ShellTest.php

@@ -1174,6 +1174,36 @@ TEXT;
     }
 
     /**
+     * test run command missing parameters
+     *
+     * @return void
+     */
+    public function testRunCommandMainMissingArgument()
+    {
+        $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['main', 'startup', 'getOptionParser'])
+            ->setConstructorArgs([$io])
+            ->getMock();
+
+        $parser = new ConsoleOptionParser('test');
+        $parser->addArgument('filename', [
+            'required' => true,
+            'help' => 'a file',
+        ]);
+        $shell->expects($this->once())
+            ->method('getOptionParser')
+            ->will($this->returnValue($parser));
+        $shell->expects($this->never())->method('main');
+
+        $io->expects($this->once())
+            ->method('err')
+            ->with('<error>Error: Missing required arguments. filename is required.</error>');
+        $result = $shell->runCommand([]);
+        $this->assertFalse($result, 'Shell should fail');
+    }
+
+    /**
      * test wrapBlock wrapping text.
      *
      * @return void