Skip to content
Permalink
Browse files

Moving Console\Error to Console\Exception.

Also fixed risky test
  • Loading branch information...
lorenzo committed Aug 30, 2014
1 parent 62a5fca commit af7ec03738ed36e9289ad21c225974bb26e293b6
@@ -14,6 +14,8 @@
*/
namespace Cake\Console;
use Cake\Console\Exception\ConsoleException;
/**
* An object to represent a single argument used in the command line.
* ConsoleOptionParser creates these when you use addArgument()
@@ -132,14 +134,14 @@ public function isRequired() {
*
* @param string $value The choice to validate.
* @return bool
* @throws \Cake\Console\Error\ConsoleException
* @throws \Cake\Console\Exception\ConsoleException
*/
public function validChoice($value) {
if (empty($this->_choices)) {
return true;
}
if (!in_array($value, $this->_choices)) {
throw new Error\ConsoleException(
throw new ConsoleException(
sprintf('"%s" is not a valid value for %s. Please use one of "%s"',
$value, $this->_name, implode(', ', $this->_choices)
));
@@ -14,6 +14,8 @@
*/
namespace Cake\Console;
use Cake\Console\Exception\ConsoleException;
/**
* An object to represent a single option used in the command line.
* ConsoleOptionParser creates these when you use addOption()
@@ -73,7 +75,7 @@ class ConsoleInputOption {
* @param bool $boolean Whether this option is a boolean option. Boolean options don't consume extra tokens
* @param string $default The default value for this option.
* @param array $choices Valid choices for this option.
* @throws \Cake\Console\Error\ConsoleException
* @throws \Cake\Console\Exception\ConsoleException
*/
public function __construct($name, $short = null, $help = '', $boolean = false, $default = '', $choices = []) {
if (is_array($name) && isset($name['name'])) {
@@ -89,7 +91,7 @@ public function __construct($name, $short = null, $help = '', $boolean = false,
$this->_choices = $choices;
}
if (strlen($this->_short) > 1) {
throw new Error\ConsoleException(
throw new ConsoleException(
sprintf('Short option "%s" is invalid, short options must be one letter.', $this->_short)
);
}
@@ -177,14 +179,14 @@ public function isBoolean() {
*
* @param string $value The choice to validate.
* @return bool
* @throws \Cake\Console\Error\ConsoleException
* @throws \Cake\Console\Exception\ConsoleException
*/
public function validChoice($value) {
if (empty($this->_choices)) {
return true;
}
if (!in_array($value, $this->_choices)) {
throw new Error\ConsoleException(
throw new ConsoleException(
sprintf('"%s" is not a valid value for --%s. Please use one of "%s"',
$value, $this->_name, implode(', ', $this->_choices)
));
@@ -14,6 +14,7 @@
*/
namespace Cake\Console;
use Cake\Console\Exception\ConsoleException;
use Cake\Utility\Inflector;
/**
@@ -470,7 +471,7 @@ public function subcommands() {
*
* @param array $argv Array of args (argv) to parse.
* @return array [$params, $args]
* @throws \Cake\Console\Error\ConsoleException When an invalid parameter is encountered.
* @throws \Cake\Console\Exception\ConsoleException When an invalid parameter is encountered.
*/
public function parse($argv) {
$command = isset($argv[0]) ? $argv[0] : null;
@@ -495,7 +496,7 @@ public function parse($argv) {
}
foreach ($this->_args as $i => $arg) {
if ($arg->isRequired() && !isset($args[$i]) && empty($params['help'])) {
throw new Error\ConsoleException(
throw new ConsoleException(
sprintf('Missing required arguments. %s is required.', $arg->name())
);
}
@@ -568,7 +569,7 @@ protected function _parseLongOption($option, $params) {
* @param string $option The option to parse.
* @param array $params The params to append the parsed value into
* @return array Params with $option added in.
* @throws \Cake\Console\Error\ConsoleException When unknown short options are encountered.
* @throws \Cake\Console\Exception\ConsoleException When unknown short options are encountered.
*/
protected function _parseShortOption($option, $params) {
$key = substr($option, 1);
@@ -580,7 +581,7 @@ protected function _parseShortOption($option, $params) {
}
}
if (!isset($this->_shortOptions[$key])) {
throw new Error\ConsoleException(sprintf('Unknown short option `%s`', $key));
throw new ConsoleException(sprintf('Unknown short option `%s`', $key));
}
$name = $this->_shortOptions[$key];
return $this->_parseOption($name, $params);
@@ -592,11 +593,11 @@ protected function _parseShortOption($option, $params) {
* @param string $name The name to parse.
* @param array $params The params to append the parsed value into
* @return array Params with $option added in.
* @throws \Cake\Console\Error\ConsoleException
* @throws \Cake\Console\Exception\ConsoleException
*/
protected function _parseOption($name, $params) {
if (!isset($this->_options[$name])) {
throw new Error\ConsoleException(sprintf('Unknown option `%s`', $name));
throw new ConsoleException(sprintf('Unknown option `%s`', $name));
}
$option = $this->_options[$name];
$isBoolean = $option->isBoolean();
@@ -640,7 +641,7 @@ protected function _optionExists($name) {
* @param string $argument The argument to append
* @param array $args The array of parsed args to append to.
* @return array Args
* @throws \Cake\Console\Error\ConsoleException
* @throws \Cake\Console\Exception\ConsoleException
*/
protected function _parseArg($argument, $args) {
if (empty($this->_args)) {
@@ -649,7 +650,7 @@ protected function _parseArg($argument, $args) {
}
$next = count($args);
if (!isset($this->_args[$next])) {
throw new Error\ConsoleException('Too many arguments.');
throw new ConsoleException('Too many arguments.');
}
if ($this->_args[$next]->validChoice($argument)) {
@@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Console\Error;
namespace Cake\Console\Exception;
use Cake\Core\Exception\Exception;
@@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Console\Error;
namespace Cake\Console\Exception;
use Cake\Core\Exception\Exception;
@@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Console\Error;
namespace Cake\Console\Exception;
use Cake\Core\Exception\Exception;
@@ -11,7 +11,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Console\Error;
namespace Cake\Console\Exception;
use Cake\Core\Exception\Exception;
@@ -15,6 +15,7 @@
namespace Cake\Console;
use Cake\Console\ConsoleIo;
use Cake\Console\Exception\ConsoleException;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Log\LogTrait;
@@ -328,7 +329,7 @@ public function runCommand($argv, $autoMethod = false) {
$this->OptionParser = $this->getOptionParser();
try {
list($this->params, $this->args) = $this->OptionParser->parse($argv);
} catch (Error\ConsoleException $e) {
} catch (ConsoleException $e) {
$this->err('<error>Error: ' . $e->getMessage() . '</error>');
$this->out($this->OptionParser->help($command));
return false;
@@ -14,6 +14,7 @@
*/
namespace Cake\Console;
use Cake\Console\Exception\MissingShellException;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Exception\Exception;
@@ -143,7 +144,7 @@ public function dispatch() {
* Dispatch a request.
*
* @return bool
* @throws \Cake\Console\Error\MissingShellMethodException
* @throws \Cake\Console\Exception\MissingShellMethodException
*/
protected function _dispatch() {
$shell = $this->shiftArgs();
@@ -170,7 +171,7 @@ protected function _dispatch() {
*
* @param string $shell Optionally the name of a plugin
* @return \Cake\Console\Shell A shell instance.
* @throws \Cake\Console\Error\MissingShellException when errors are encountered.
* @throws \Cake\Console\Exception\MissingShellException when errors are encountered.
*/
public function findShell($shell) {
$className = $this->_shellExists($shell);
@@ -184,7 +185,7 @@ public function findShell($shell) {
$instance->plugin = Inflector::camelize(trim($plugin, '.'));
return $instance;
}
throw new Error\MissingShellException([
throw new MissingShellException([
'class' => $shell,
]);
}
@@ -14,6 +14,7 @@
*/
namespace Cake\Console;
use Cake\Console\Exception\MissingTaskException;
use Cake\Core\App;
use Cake\Core\ObjectRegistry;
@@ -59,10 +60,10 @@ protected function _resolveClassName($class) {
* @param string $class The classname that is missing.
* @param string $plugin The plugin the task is missing in.
* @return void
* @throws \Cake\Console\Error\MissingTaskException
* @throws \Cake\Console\Exception\MissingTaskException
*/
protected function _throwMissingClassError($class, $plugin) {
throw new Error\MissingTaskException([
throw new MissingTaskException([
'class' => $class,
'plugin' => $plugin
]);
@@ -76,6 +76,7 @@ public function testHandleFatalError() {
->with($this->stringContains($content));
$this->Error->handleError(E_USER_ERROR, 'This is a fatal error', '/some/file', 275);
ob_end_clean();
}
/**
@@ -174,7 +174,7 @@ public function testAddOptionShort() {
* Test that adding an option using a two letter short value causes an exception.
* As they will not parse correctly.
*
* @expectedException \Cake\Console\Error\ConsoleException
* @expectedException \Cake\Console\Exception\ConsoleException
* @return void
*/
public function testAddOptionShortOneLetter() {
@@ -272,7 +272,7 @@ public function testOptionWithBooleanParam() {
/**
* test parsing options that do not exist.
*
* @expectedException \Cake\Console\Error\ConsoleException
* @expectedException \Cake\Console\Exception\ConsoleException
* @return void
*/
public function testOptionThatDoesNotExist() {
@@ -285,7 +285,7 @@ public function testOptionThatDoesNotExist() {
/**
* test parsing short options that do not exist.
*
* @expectedException \Cake\Console\Error\ConsoleException
* @expectedException \Cake\Console\Exception\ConsoleException
* @return void
*/
public function testShortOptionThatDoesNotExist() {
@@ -298,7 +298,7 @@ public function testShortOptionThatDoesNotExist() {
/**
* test that options with choices enforce them.
*
* @expectedException \Cake\Console\Error\ConsoleException
* @expectedException \Cake\Console\Exception\ConsoleException
* @return void
*/
public function testOptionWithChoices() {
@@ -387,7 +387,7 @@ public function testPositionalArgOverwrite() {
/**
* test parsing arguments.
*
* @expectedException \Cake\Console\Error\ConsoleException
* @expectedException \Cake\Console\Exception\ConsoleException
* @return void
*/
public function testParseArgumentTooMany() {
@@ -418,7 +418,7 @@ public function testParseArgumentZero() {
/**
* test that when there are not enough arguments an exception is raised
*
* @expectedException \Cake\Console\Error\ConsoleException
* @expectedException \Cake\Console\Exception\ConsoleException
* @return void
*/
public function testPositionalArgNotEnough() {
@@ -432,7 +432,7 @@ public function testPositionalArgNotEnough() {
/**
* test that arguments with choices enforce them.
*
* @expectedException \Cake\Console\Error\ConsoleException
* @expectedException \Cake\Console\Exception\ConsoleException
* @return void
*/
public function testPositionalArgWithChoices() {
@@ -51,7 +51,7 @@ public function tearDown() {
/**
* Test error on missing shell
*
* @expectedException Cake\Console\Error\MissingShellException
* @expectedException Cake\Console\Exception\MissingShellException
* @return void
*/
public function testFindShellMissing() {
@@ -61,7 +61,7 @@ public function testFindShellMissing() {
/**
* Test error on missing plugin shell
*
* @expectedException Cake\Console\Error\MissingShellException
* @expectedException Cake\Console\Exception\MissingShellException
* @return void
*/
public function testFindShellMissingPlugin() {
@@ -63,7 +63,7 @@ public function testLoad() {
/**
* test missingtask exception
*
* @expectedException \Cake\Console\Error\MissingTaskException
* @expectedException \Cake\Console\Exception\MissingTaskException
* @return void
*/
public function testLoadMissingTask() {

0 comments on commit af7ec03

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