Browse Source

Moving Console\Error to Console\Exception.

Also fixed risky test
Jose Lorenzo Rodriguez 11 years ago
parent
commit
af7ec03738

+ 4 - 2
src/Console/ConsoleInputArgument.php

@@ -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 @@ class ConsoleInputArgument {
  *
  * @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)
 			));

+ 6 - 4
src/Console/ConsoleInputOption.php

@@ -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 @@ class ConsoleInputOption {
 			$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 @@ class ConsoleInputOption {
  *
  * @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)
 			));

+ 9 - 8
src/Console/ConsoleOptionParser.php

@@ -14,6 +14,7 @@
  */
 namespace Cake\Console;
 
+use Cake\Console\Exception\ConsoleException;
 use Cake\Utility\Inflector;
 
 /**
@@ -470,7 +471,7 @@ class ConsoleOptionParser {
  *
  * @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 @@ class ConsoleOptionParser {
 		}
 		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 @@ class ConsoleOptionParser {
  * @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 @@ class ConsoleOptionParser {
 			}
 		}
 		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 @@ class ConsoleOptionParser {
  * @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 @@ class ConsoleOptionParser {
  * @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 @@ class ConsoleOptionParser {
 		}
 		$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)) {

+ 1 - 1
src/Console/Error/ConsoleException.php

@@ -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;
 

+ 1 - 1
src/Console/Error/MissingShellException.php

@@ -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;
 

+ 1 - 1
src/Console/Error/MissingShellMethodException.php

@@ -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;
 

+ 1 - 1
src/Console/Error/MissingTaskException.php

@@ -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;
 

+ 2 - 1
src/Console/Shell.php

@@ -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 @@ class Shell {
 		$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;

+ 4 - 3
src/Console/ShellDispatcher.php

@@ -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 @@ class ShellDispatcher {
  * 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 @@ class ShellDispatcher {
  *
  * @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 @@ class ShellDispatcher {
 			$instance->plugin = Inflector::camelize(trim($plugin, '.'));
 			return $instance;
 		}
-		throw new Error\MissingShellException([
+		throw new MissingShellException([
 			'class' => $shell,
 		]);
 	}

+ 3 - 2
src/Console/TaskRegistry.php

@@ -14,6 +14,7 @@
  */
 namespace Cake\Console;
 
+use Cake\Console\Exception\MissingTaskException;
 use Cake\Core\App;
 use Cake\Core\ObjectRegistry;
 
@@ -59,10 +60,10 @@ class TaskRegistry extends ObjectRegistry {
  * @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
 		]);

+ 1 - 0
tests/TestCase/Console/ConsoleErrorHandlerTest.php

@@ -76,6 +76,7 @@ class ConsoleErrorHandlerTest extends TestCase {
 			->with($this->stringContains($content));
 
 		$this->Error->handleError(E_USER_ERROR, 'This is a fatal error', '/some/file', 275);
+		ob_end_clean();
 	}
 
 /**

+ 7 - 7
tests/TestCase/Console/ConsoleOptionParserTest.php

@@ -174,7 +174,7 @@ class ConsoleOptionParserTest extends TestCase {
  * 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 @@ class ConsoleOptionParserTest extends TestCase {
 /**
  * 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 @@ class ConsoleOptionParserTest extends TestCase {
 /**
  * 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 @@ class ConsoleOptionParserTest extends TestCase {
 /**
  * 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 @@ class ConsoleOptionParserTest extends TestCase {
 /**
  * test parsing arguments.
  *
- * @expectedException \Cake\Console\Error\ConsoleException
+ * @expectedException \Cake\Console\Exception\ConsoleException
  * @return void
  */
 	public function testParseArgumentTooMany() {
@@ -418,7 +418,7 @@ class ConsoleOptionParserTest extends TestCase {
 /**
  * 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 @@ class ConsoleOptionParserTest extends TestCase {
 /**
  * test that arguments with choices enforce them.
  *
- * @expectedException \Cake\Console\Error\ConsoleException
+ * @expectedException \Cake\Console\Exception\ConsoleException
  * @return void
  */
 	public function testPositionalArgWithChoices() {

+ 2 - 2
tests/TestCase/Console/ShellDispatcherTest.php

@@ -51,7 +51,7 @@ class ShellDispatcherTest extends TestCase {
 /**
  * Test error on missing shell
  *
- * @expectedException Cake\Console\Error\MissingShellException
+ * @expectedException Cake\Console\Exception\MissingShellException
  * @return void
  */
 	public function testFindShellMissing() {
@@ -61,7 +61,7 @@ class ShellDispatcherTest extends TestCase {
 /**
  * Test error on missing plugin shell
  *
- * @expectedException Cake\Console\Error\MissingShellException
+ * @expectedException Cake\Console\Exception\MissingShellException
  * @return void
  */
 	public function testFindShellMissingPlugin() {

+ 1 - 1
tests/TestCase/Console/TaskRegistryTest.php

@@ -63,7 +63,7 @@ class TaskRegistryTest extends TestCase {
 /**
  * test missingtask exception
  *
- * @expectedException \Cake\Console\Error\MissingTaskException
+ * @expectedException \Cake\Console\Exception\MissingTaskException
  * @return void
  */
 	public function testLoadMissingTask() {