Browse Source

Fix failing tests and errors in php72.

Mark Story 6 years ago
parent
commit
8d896ac6e5

+ 3 - 3
src/Console/ConsoleOptionParser.php

@@ -777,14 +777,14 @@ class ConsoleOptionParser
         $message = sprintf(
             'Unable to find the `%s %s` subcommand. See `bin/%s %s --help`.',
             $rootCommand,
-            $command,
+            $subcommand,
             $this->rootName,
             $rootCommand
         );
         throw new InvalidOptionException(
             $message,
-            $command,
-            array_keys((array)$this->subcommands()),
+            $subcommand,
+            array_keys((array)$this->subcommands())
         );
     }
 

+ 5 - 1
src/Console/Shell.php

@@ -513,7 +513,11 @@ class Shell
         }
 
         $this->err('No subcommand provided. Choose one of the available subcommands.', 2);
-        $this->_io->err($this->OptionParser->help($command));
+        try {
+            $this->_io->err($this->OptionParser->help($command));
+        } catch (ConsoleException $e) {
+            $this->err('Error: ' . $e->getMessage());
+        }
 
         return false;
     }

+ 13 - 12
tests/TestCase/Console/ConsoleOptionParserTest.php

@@ -948,18 +948,19 @@ TEXT;
             ->addOption('test', ['help' => 'A test option.'])
             ->addSubcommand('unstash');
 
-        $result = $parser->help('unknown');
-        $expected = <<<TEXT
-Unable to find the `mycommand unknown` subcommand. See `bin/cake mycommand --help`.
-
-Did you mean : `mycommand unstash` ?
-
-Available subcommands for the `mycommand` command are : 
-
- - method
- - unstash
-TEXT;
-        $this->assertTextEquals($expected, $result, 'Help is not correct.');
+        try {
+            $result = $parser->help('unknown');
+        } catch (InvalidOptionException $e) {
+            $result = $e->getFullMessage();
+            $this->assertStringContainsString(
+                "Unable to find the `mycommand unknown` subcommand. See `bin/cake mycommand --help`.\n" .
+                "\n" .
+                "Other valid choices:\n" .
+                "\n" .
+                "- method",
+                $result,
+            );
+        }
     }
 
     /**