diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index b7cb66c28b..df999d2435 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -38,6 +38,8 @@ use Symfony\Component\Console\Helper\TableHelper; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\Console\Event\ConsoleExceptionEvent; use Symfony\Component\Console\Event\ConsoleTerminateEvent; +use Symfony\Component\Console\Exception\CommandNotFoundException; +use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -392,7 +394,7 @@ class Application } if (null === $command->getDefinition()) { - throw new \LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command))); + throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command))); } $this->commands[$command->getName()] = $command; @@ -411,14 +413,14 @@ class Application * * @return Command A Command object * - * @throws \InvalidArgumentException When command name given does not exist + * @throws CommandNotFoundException When command name given does not exist * * @api */ public function get($name) { if (!isset($this->commands[$name])) { - throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name)); + throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name)); } $command = $this->commands[$name]; @@ -477,7 +479,7 @@ class Application * * @return string A registered namespace * - * @throws \InvalidArgumentException When namespace is incorrect or ambiguous + * @throws CommandNotFoundException When namespace is incorrect or ambiguous */ public function findNamespace($namespace) { @@ -498,12 +500,12 @@ class Application $message .= implode("\n ", $alternatives); } - throw new \InvalidArgumentException($message); + throw new CommandNotFoundException($message, $alternatives); } $exact = in_array($namespace, $namespaces, true); if (count($namespaces) > 1 && !$exact) { - throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces)))); + throw new CommandNotFoundException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces)); } return $exact ? $namespace : reset($namespaces); @@ -519,7 +521,7 @@ class Application * * @return Command A Command instance * - * @throws \InvalidArgumentException When command name is incorrect or ambiguous + * @throws CommandNotFoundException When command name is incorrect or ambiguous * * @api */ @@ -546,7 +548,7 @@ class Application $message .= implode("\n ", $alternatives); } - throw new \InvalidArgumentException($message); + throw new CommandNotFoundException($message, $alternatives); } // filter out aliases for commands which are already on the list @@ -563,7 +565,7 @@ class Application if (count($commands) > 1 && !$exact) { $suggestions = $this->getAbbreviationSuggestions(array_values($commands)); - throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions)); + throw new CommandNotFoundException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions), array_values($commands)); } return $this->get($exact ? $name : reset($commands)); diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index fd5e0daa34..5ff7ab9b97 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -21,6 +21,8 @@ use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\LogicException; /** * Base class for all commands. @@ -51,7 +53,7 @@ class Command * * @param string|null $name The name of the command; passing null means it must be set in configure() * - * @throws \LogicException When the command name is empty + * @throws LogicException When the command name is empty * * @api */ @@ -66,7 +68,7 @@ class Command $this->configure(); if (!$this->name) { - throw new \LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_class($this))); + throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_class($this))); } } @@ -162,13 +164,13 @@ class Command * * @return null|int null or 0 if everything went fine, or an error code * - * @throws \LogicException When this abstract method is not implemented + * @throws LogicException When this abstract method is not implemented * * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output) { - throw new \LogicException('You must override the execute() method in the concrete command class.'); + throw new LogicException('You must override the execute() method in the concrete command class.'); } /** @@ -272,7 +274,7 @@ class Command * * @return Command The current instance * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @see execute() * @@ -281,7 +283,7 @@ class Command public function setCode($code) { if (!is_callable($code)) { - throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.'); + throw new InvalidArgumentException('Invalid callable provided to Command::setCode.'); } if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) { @@ -423,7 +425,7 @@ class Command * * @return Command The current instance * - * @throws \InvalidArgumentException When the name is invalid + * @throws InvalidArgumentException When the name is invalid * * @api */ @@ -552,14 +554,14 @@ class Command * * @return Command The current instance * - * @throws \InvalidArgumentException When an alias is invalid + * @throws InvalidArgumentException When an alias is invalid * * @api */ public function setAliases($aliases) { if (!is_array($aliases) && !$aliases instanceof \Traversable) { - throw new \InvalidArgumentException('$aliases must be an array or an instance of \Traversable'); + throw new InvalidArgumentException('$aliases must be an array or an instance of \Traversable'); } foreach ($aliases as $alias) { @@ -634,7 +636,7 @@ class Command * * @return mixed The helper value * - * @throws \InvalidArgumentException if the helper is not defined + * @throws InvalidArgumentException if the helper is not defined * * @api */ @@ -693,12 +695,12 @@ class Command * * @param string $name * - * @throws \InvalidArgumentException When the name is invalid + * @throws InvalidArgumentException When the name is invalid */ private function validateName($name) { if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) { - throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name)); + throw new InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name)); } } } diff --git a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php index c481be4df5..199226a5a9 100644 --- a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php +++ b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Exception\CommandNotFoundException; /** * @author Jean-François Simon @@ -89,12 +90,12 @@ class ApplicationDescription * * @return Command * - * @throws \InvalidArgumentException + * @throws CommandNotFoundException */ public function getCommand($name) { if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { - throw new \InvalidArgumentException(sprintf('Command %s does not exist.', $name)); + throw new CommandNotFoundException(sprintf('Command %s does not exist.', $name)); } return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name]; diff --git a/src/Symfony/Component/Console/Descriptor/Descriptor.php b/src/Symfony/Component/Console/Descriptor/Descriptor.php index 49e21939f9..43a7a0a1fe 100644 --- a/src/Symfony/Component/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Descriptor.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Exception\InvalidArgumentException; /** * @author Jean-François Simon @@ -54,7 +55,7 @@ abstract class Descriptor implements DescriptorInterface $this->describeApplication($object, $options); break; default: - throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object))); + throw new InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object))); } } diff --git a/src/Symfony/Component/Console/Exception/CommandNotFoundException.php b/src/Symfony/Component/Console/Exception/CommandNotFoundException.php new file mode 100644 index 0000000000..ce6fefe34a --- /dev/null +++ b/src/Symfony/Component/Console/Exception/CommandNotFoundException.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Exception; + +/** + * Represents an incorrect command name typed in the console. + * + * @author Jérôme Tamarelle + */ +class CommandNotFoundException extends \InvalidArgumentException implements ExceptionInterface +{ + private $alternatives; + + /** + * @param string $message Exception message to throw. + * @param array $alternatives List of similar defined names. + * @param int $code Exception code. + * @param Exception $previous previous exception used for the exception chaining. + */ + public function __construct($message, array $alternatives = array(), $code = 0, \Exception $previous = null) + { + parent::__construct($message, $code, $previous); + + $this->alternatives = $alternatives; + } + + /** + * @return array A list of similar defined names. + */ + public function getAlternatives() + { + return $this->alternatives; + } +} diff --git a/src/Symfony/Component/Console/Exception/ExceptionInterface.php b/src/Symfony/Component/Console/Exception/ExceptionInterface.php new file mode 100644 index 0000000000..0e08197539 --- /dev/null +++ b/src/Symfony/Component/Console/Exception/ExceptionInterface.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Exception; + +/** + * ExceptionInterface. + * + * @author Jérôme Tamarelle + * + * @api + */ +interface ExceptionInterface +{ +} diff --git a/src/Symfony/Component/Console/Exception/InvalidArgumentException.php b/src/Symfony/Component/Console/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000..07cc0b61d6 --- /dev/null +++ b/src/Symfony/Component/Console/Exception/InvalidArgumentException.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Exception; + +/** + * @author Jérôme Tamarelle + */ +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/src/Symfony/Component/Console/Exception/InvalidOptionException.php b/src/Symfony/Component/Console/Exception/InvalidOptionException.php new file mode 100644 index 0000000000..b2eec61658 --- /dev/null +++ b/src/Symfony/Component/Console/Exception/InvalidOptionException.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Exception; + +/** + * Represents an incorrect option name typed in the console. + * + * @author Jérôme Tamarelle + */ +class InvalidOptionException extends \InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/src/Symfony/Component/Console/Exception/LogicException.php b/src/Symfony/Component/Console/Exception/LogicException.php new file mode 100644 index 0000000000..fc37b8d8ae --- /dev/null +++ b/src/Symfony/Component/Console/Exception/LogicException.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Exception; + +/** + * @author Jérôme Tamarelle + */ +class LogicException extends \LogicException implements ExceptionInterface +{ +} diff --git a/src/Symfony/Component/Console/Exception/RuntimeException.php b/src/Symfony/Component/Console/Exception/RuntimeException.php new file mode 100644 index 0000000000..51d7d80ac6 --- /dev/null +++ b/src/Symfony/Component/Console/Exception/RuntimeException.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Exception; + +/** + * @author Jérôme Tamarelle + */ +class RuntimeException extends \RuntimeException implements ExceptionInterface +{ +} diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php index 331b204fec..9eb0505854 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Formatter; +use Symfony\Component\Console\Exception\InvalidArgumentException; + /** * Formatter class for console output. * @@ -118,14 +120,14 @@ class OutputFormatter implements OutputFormatterInterface * * @return OutputFormatterStyleInterface * - * @throws \InvalidArgumentException When style isn't defined + * @throws InvalidArgumentException When style isn't defined * * @api */ public function getStyle($name) { if (!$this->hasStyle($name)) { - throw new \InvalidArgumentException(sprintf('Undefined style: %s', $name)); + throw new InvalidArgumentException(sprintf('Undefined style: %s', $name)); } return $this->styles[strtolower($name)]; diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php index ee62cdbd61..7de6622ee6 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Formatter; +use Symfony\Component\Console\Exception\InvalidArgumentException; + /** * Formatter style class for defining styles. * @@ -81,7 +83,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * * @param string|null $color The color name * - * @throws \InvalidArgumentException When the color name isn't defined + * @throws InvalidArgumentException When the color name isn't defined * * @api */ @@ -94,7 +96,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface } if (!isset(static::$availableForegroundColors[$color])) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'Invalid foreground color specified: "%s". Expected one of (%s)', $color, implode(', ', array_keys(static::$availableForegroundColors)) @@ -109,7 +111,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * * @param string|null $color The color name * - * @throws \InvalidArgumentException When the color name isn't defined + * @throws InvalidArgumentException When the color name isn't defined * * @api */ @@ -122,7 +124,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface } if (!isset(static::$availableBackgroundColors[$color])) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'Invalid background color specified: "%s". Expected one of (%s)', $color, implode(', ', array_keys(static::$availableBackgroundColors)) @@ -137,14 +139,14 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * * @param string $option The option name * - * @throws \InvalidArgumentException When the option name isn't defined + * @throws InvalidArgumentException When the option name isn't defined * * @api */ public function setOption($option) { if (!isset(static::$availableOptions[$option])) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'Invalid option specified: "%s". Expected one of (%s)', $option, implode(', ', array_keys(static::$availableOptions)) @@ -161,12 +163,12 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * * @param string $option The option name * - * @throws \InvalidArgumentException When the option name isn't defined + * @throws InvalidArgumentException When the option name isn't defined */ public function unsetOption($option) { if (!isset(static::$availableOptions[$option])) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'Invalid option specified: "%s". Expected one of (%s)', $option, implode(', ', array_keys(static::$availableOptions)) diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php index b64c87fa59..e5d14ea3fb 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Formatter; +use Symfony\Component\Console\Exception\InvalidArgumentException; + /** * @author Jean-François Simon */ @@ -62,7 +64,7 @@ class OutputFormatterStyleStack * * @return OutputFormatterStyleInterface * - * @throws \InvalidArgumentException When style tags incorrectly nested + * @throws InvalidArgumentException When style tags incorrectly nested */ public function pop(OutputFormatterStyleInterface $style = null) { @@ -82,7 +84,7 @@ class OutputFormatterStyleStack } } - throw new \InvalidArgumentException('Incorrectly nested style tag found.'); + throw new InvalidArgumentException('Incorrectly nested style tag found.'); } /** diff --git a/src/Symfony/Component/Console/Helper/DescriptorHelper.php b/src/Symfony/Component/Console/Helper/DescriptorHelper.php index c324c99454..a53b476b17 100644 --- a/src/Symfony/Component/Console/Helper/DescriptorHelper.php +++ b/src/Symfony/Component/Console/Helper/DescriptorHelper.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Descriptor\MarkdownDescriptor; use Symfony\Component\Console\Descriptor\TextDescriptor; use Symfony\Component\Console\Descriptor\XmlDescriptor; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Exception\InvalidArgumentException; /** * This class adds helper method to describe objects in various formats. @@ -54,7 +55,7 @@ class DescriptorHelper extends Helper * @param object $object * @param array $options * - * @throws \InvalidArgumentException when the given format is not supported + * @throws InvalidArgumentException when the given format is not supported */ public function describe(OutputInterface $output, $object, array $options = array()) { @@ -64,7 +65,7 @@ class DescriptorHelper extends Helper ), $options); if (!isset($this->descriptors[$options['format']])) { - throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format'])); + throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format'])); } $descriptor = $this->descriptors[$options['format']]; diff --git a/src/Symfony/Component/Console/Helper/DialogHelper.php b/src/Symfony/Component/Console/Helper/DialogHelper.php index dbadac2cbf..1c1d247d29 100644 --- a/src/Symfony/Component/Console/Helper/DialogHelper.php +++ b/src/Symfony/Component/Console/Helper/DialogHelper.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Helper; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Formatter\OutputFormatterStyle; @@ -48,7 +50,7 @@ class DialogHelper extends InputAwareHelper * * @return int|string|array The selected value or values (the key of the choices array) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function select(OutputInterface $output, $question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false) { @@ -68,7 +70,7 @@ class DialogHelper extends InputAwareHelper if ($multiselect) { // Check for a separated comma values if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) { - throw new \InvalidArgumentException(sprintf($errorMessage, $picked)); + throw new InvalidArgumentException(sprintf($errorMessage, $picked)); } $selectedChoices = explode(',', $selectedChoices); } else { @@ -79,7 +81,7 @@ class DialogHelper extends InputAwareHelper foreach ($selectedChoices as $value) { if (empty($choices[$value])) { - throw new \InvalidArgumentException(sprintf($errorMessage, $value)); + throw new InvalidArgumentException(sprintf($errorMessage, $value)); } $multiselectChoices[] = $value; } @@ -104,7 +106,7 @@ class DialogHelper extends InputAwareHelper * * @return string The user answer * - * @throws \RuntimeException If there is no data to read in the input stream + * @throws RuntimeException If there is no data to read in the input stream */ public function ask(OutputInterface $output, $question, $default = null, array $autocomplete = null) { @@ -119,7 +121,7 @@ class DialogHelper extends InputAwareHelper if (null === $autocomplete || !$this->hasSttyAvailable()) { $ret = fgets($inputStream, 4096); if (false === $ret) { - throw new \RuntimeException('Aborted'); + throw new RuntimeException('Aborted'); } $ret = trim($ret); } else { @@ -265,7 +267,7 @@ class DialogHelper extends InputAwareHelper * * @return string The answer * - * @throws \RuntimeException In case the fallback is deactivated and the response can not be hidden + * @throws RuntimeException In case the fallback is deactivated and the response can not be hidden */ public function askHiddenResponse(OutputInterface $output, $question, $fallback = true) { @@ -300,7 +302,7 @@ class DialogHelper extends InputAwareHelper shell_exec(sprintf('stty %s', $sttyMode)); if (false === $value) { - throw new \RuntimeException('Aborted'); + throw new RuntimeException('Aborted'); } $value = trim($value); @@ -323,7 +325,7 @@ class DialogHelper extends InputAwareHelper return $this->ask($output, $question); } - throw new \RuntimeException('Unable to hide the response'); + throw new RuntimeException('Unable to hide the response'); } /** @@ -370,8 +372,8 @@ class DialogHelper extends InputAwareHelper * * @return string The response * - * @throws \Exception When any of the validators return an error - * @throws \RuntimeException In case the fallback is deactivated and the response can not be hidden + * @throws \Exception When any of the validators return an error + * @throws RuntimeException In case the fallback is deactivated and the response can not be hidden */ public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true) { diff --git a/src/Symfony/Component/Console/Helper/HelperSet.php b/src/Symfony/Component/Console/Helper/HelperSet.php index 00354dd91f..27fedcf7b5 100644 --- a/src/Symfony/Component/Console/Helper/HelperSet.php +++ b/src/Symfony/Component/Console/Helper/HelperSet.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console\Helper; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Exception\InvalidArgumentException; /** * HelperSet represents a set of helpers to be used with a command. @@ -70,12 +71,12 @@ class HelperSet implements \IteratorAggregate * * @return HelperInterface The helper instance * - * @throws \InvalidArgumentException if the helper is not defined + * @throws InvalidArgumentException if the helper is not defined */ public function get($name) { if (!$this->has($name)) { - throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name)); + throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name)); } if ('dialog' === $name && $this->helpers[$name] instanceof DialogHelper) { diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index 7f4b2efb8d..951e4f9dae 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Helper; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Exception\LogicException; /** * The ProgressBar provides helpers to display progress output. @@ -355,7 +356,7 @@ class ProgressBar * * @param int $step Number of steps to advance * - * @throws \LogicException + * @throws LogicException */ public function advance($step = 1) { @@ -369,7 +370,7 @@ class ProgressBar * * @param int $step The current progress * - * @throws \LogicException + * @throws LogicException */ public function setCurrent($step) { @@ -393,13 +394,13 @@ class ProgressBar * * @param int $step The current progress * - * @throws \LogicException + * @throws LogicException */ public function setProgress($step) { $step = (int) $step; if ($step < $this->step) { - throw new \LogicException('You can\'t regress the progress bar.'); + throw new LogicException('You can\'t regress the progress bar.'); } if ($this->max && $step > $this->max) { @@ -562,7 +563,7 @@ class ProgressBar }, 'remaining' => function (ProgressBar $bar) { if (!$bar->getMaxSteps()) { - throw new \LogicException('Unable to display the remaining time if the maximum number of steps is not set.'); + throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.'); } if (!$bar->getProgress()) { @@ -575,7 +576,7 @@ class ProgressBar }, 'estimated' => function (ProgressBar $bar) { if (!$bar->getMaxSteps()) { - throw new \LogicException('Unable to display the estimated time if the maximum number of steps is not set.'); + throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.'); } if (!$bar->getProgress()) { diff --git a/src/Symfony/Component/Console/Helper/ProgressHelper.php b/src/Symfony/Component/Console/Helper/ProgressHelper.php index bd885662f4..e92f24c503 100644 --- a/src/Symfony/Component/Console/Helper/ProgressHelper.php +++ b/src/Symfony/Component/Console/Helper/ProgressHelper.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Helper; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Exception\LogicException; /** * The Progress class provides helpers to display progress output. @@ -236,7 +237,7 @@ class ProgressHelper extends Helper * @param int $step Number of steps to advance * @param bool $redraw Whether to redraw or not * - * @throws \LogicException + * @throws LogicException */ public function advance($step = 1, $redraw = false) { @@ -249,18 +250,18 @@ class ProgressHelper extends Helper * @param int $current The current progress * @param bool $redraw Whether to redraw or not * - * @throws \LogicException + * @throws LogicException */ public function setCurrent($current, $redraw = false) { if (null === $this->startTime) { - throw new \LogicException('You must start the progress bar before calling setCurrent().'); + throw new LogicException('You must start the progress bar before calling setCurrent().'); } $current = (int) $current; if ($current < $this->current) { - throw new \LogicException('You can\'t regress the progress bar'); + throw new LogicException('You can\'t regress the progress bar'); } if (0 === $this->current) { @@ -282,12 +283,12 @@ class ProgressHelper extends Helper * * @param bool $finish Forces the end result * - * @throws \LogicException + * @throws LogicException */ public function display($finish = false) { if (null === $this->startTime) { - throw new \LogicException('You must start the progress bar before calling display().'); + throw new LogicException('You must start the progress bar before calling display().'); } $message = $this->format; @@ -315,7 +316,7 @@ class ProgressHelper extends Helper public function finish() { if (null === $this->startTime) { - throw new \LogicException('You must start the progress bar before calling finish().'); + throw new LogicException('You must start the progress bar before calling finish().'); } if (null !== $this->startTime) { diff --git a/src/Symfony/Component/Console/Helper/QuestionHelper.php b/src/Symfony/Component/Console/Helper/QuestionHelper.php index bbbd826269..3707ffee08 100644 --- a/src/Symfony/Component/Console/Helper/QuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/QuestionHelper.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Helper; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -38,7 +40,7 @@ class QuestionHelper extends Helper * * @return string The user answer * - * @throws \RuntimeException If there is no data to read in the input stream + * @throws RuntimeException If there is no data to read in the input stream */ public function ask(InputInterface $input, OutputInterface $output, Question $question) { @@ -70,12 +72,12 @@ class QuestionHelper extends Helper * * @param resource $stream The input stream * - * @throws \InvalidArgumentException In case the stream is not a resource + * @throws InvalidArgumentException In case the stream is not a resource */ public function setInputStream($stream) { if (!is_resource($stream)) { - throw new \InvalidArgumentException('Input stream must be a valid resource.'); + throw new InvalidArgumentException('Input stream must be a valid resource.'); } $this->inputStream = $stream; @@ -315,7 +317,7 @@ class QuestionHelper extends Helper * * @return string The answer * - * @throws \RuntimeException In case the fallback is deactivated and the response cannot be hidden + * @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden */ private function getHiddenResponse(OutputInterface $output, $inputStream) { @@ -347,7 +349,7 @@ class QuestionHelper extends Helper shell_exec(sprintf('stty %s', $sttyMode)); if (false === $value) { - throw new \RuntimeException('Aborted'); + throw new RuntimeException('Aborted'); } $value = trim($value); @@ -365,7 +367,7 @@ class QuestionHelper extends Helper return $value; } - throw new \RuntimeException('Unable to hide the response.'); + throw new RuntimeException('Unable to hide the response.'); } /** @@ -431,7 +433,7 @@ class QuestionHelper extends Helper * * @return string User input * - * @throws \RuntimeException + * @throws RuntimeException */ private function readFromInput($stream) { @@ -442,7 +444,7 @@ class QuestionHelper extends Helper } if (false === $ret) { - throw new \RuntimeException('Aborted'); + throw new RuntimeException('Aborted'); } return trim($ret); diff --git a/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php b/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php index 77130f9776..487f0624d4 100644 --- a/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\Helper; +use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ChoiceQuestion; @@ -38,7 +39,7 @@ class SymfonyQuestionHelper extends QuestionHelper // make required if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) { - throw new \Exception('A value is required.'); + throw new LogicException('A value is required.'); } return $value; diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 4b134c6aee..fcb3b25a42 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console\Helper; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Exception\InvalidArgumentException; /** * Provides helpers to display a table. @@ -102,7 +103,7 @@ class Table } if (!self::$styles[$name]) { - throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); + throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); } return self::$styles[$name]; @@ -122,7 +123,7 @@ class Table } elseif (isset(self::$styles[$name])) { $this->style = self::$styles[$name]; } else { - throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); + throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); } return $this; @@ -175,7 +176,7 @@ class Table } if (!is_array($row)) { - throw new \InvalidArgumentException('A row must be an array or a TableSeparator instance.'); + throw new InvalidArgumentException('A row must be an array or a TableSeparator instance.'); } $this->rows[] = array_values($row); diff --git a/src/Symfony/Component/Console/Helper/TableCell.php b/src/Symfony/Component/Console/Helper/TableCell.php index aa0d318079..69442d4249 100644 --- a/src/Symfony/Component/Console/Helper/TableCell.php +++ b/src/Symfony/Component/Console/Helper/TableCell.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Helper; +use Symfony\Component\Console\Exception\InvalidArgumentException; + /** * @author Abdellatif Ait boudad */ @@ -39,7 +41,7 @@ class TableCell // check option names if ($diff = array_diff(array_keys($options), array_keys($this->options))) { - throw new \InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff))); + throw new InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff))); } $this->options = array_merge($this->options, $options); diff --git a/src/Symfony/Component/Console/Helper/TableHelper.php b/src/Symfony/Component/Console/Helper/TableHelper.php index 29535225a0..ebd6785157 100644 --- a/src/Symfony/Component/Console/Helper/TableHelper.php +++ b/src/Symfony/Component/Console/Helper/TableHelper.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Helper; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\NullOutput; +use Symfony\Component\Console\Exception\InvalidArgumentException; /** * Provides helpers to display table output. @@ -50,7 +51,7 @@ class TableHelper extends Helper * * @return TableHelper * - * @throws \InvalidArgumentException when the table layout is not known + * @throws InvalidArgumentException when the table layout is not known */ public function setLayout($layout) { @@ -68,7 +69,7 @@ class TableHelper extends Helper break; default: - throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout)); + throw new InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout)); }; return $this; diff --git a/src/Symfony/Component/Console/Helper/TableStyle.php b/src/Symfony/Component/Console/Helper/TableStyle.php index f0f46c71e3..d7e28ff2b4 100644 --- a/src/Symfony/Component/Console/Helper/TableStyle.php +++ b/src/Symfony/Component/Console/Helper/TableStyle.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Console\Helper; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\LogicException; + /** * Defines the styles for a Table. * @@ -39,7 +42,7 @@ class TableStyle public function setPaddingChar($paddingChar) { if (!$paddingChar) { - throw new \LogicException('The padding char must not be empty'); + throw new LogicException('The padding char must not be empty'); } $this->paddingChar = $paddingChar; @@ -235,7 +238,7 @@ class TableStyle public function setPadType($padType) { if (!in_array($padType, array(STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH), true)) { - throw new \InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).'); + throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).'); } $this->padType = $padType; diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index a6c2132797..0ef4f54f29 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Input; +use Symfony\Component\Console\Exception\RuntimeException; + /** * ArgvInput represents an input coming from the CLI arguments. * @@ -118,14 +120,14 @@ class ArgvInput extends Input * * @param string $name The current token * - * @throws \RuntimeException When option given doesn't exist + * @throws RuntimeException When option given doesn't exist */ private function parseShortOptionSet($name) { $len = strlen($name); for ($i = 0; $i < $len; ++$i) { if (!$this->definition->hasShortcut($name[$i])) { - throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i])); + throw new RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i])); } $option = $this->definition->getOptionForShortcut($name[$i]); @@ -160,7 +162,7 @@ class ArgvInput extends Input * * @param string $token The current token * - * @throws \RuntimeException When too many arguments are given + * @throws RuntimeException When too many arguments are given */ private function parseArgument($token) { @@ -178,7 +180,7 @@ class ArgvInput extends Input // unexpected argument } else { - throw new \RuntimeException('Too many arguments.'); + throw new RuntimeException('Too many arguments.'); } } @@ -188,12 +190,12 @@ class ArgvInput extends Input * @param string $shortcut The short option key * @param mixed $value The value for the option * - * @throws \RuntimeException When option given doesn't exist + * @throws RuntimeException When option given doesn't exist */ private function addShortOption($shortcut, $value) { if (!$this->definition->hasShortcut($shortcut)) { - throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut)); + throw new RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut)); } $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value); @@ -205,12 +207,12 @@ class ArgvInput extends Input * @param string $name The long option key * @param mixed $value The value for the option * - * @throws \RuntimeException When option given doesn't exist + * @throws RuntimeException When option given doesn't exist */ private function addLongOption($name, $value) { if (!$this->definition->hasOption($name)) { - throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name)); + throw new RuntimeException(sprintf('The "--%s" option does not exist.', $name)); } $option = $this->definition->getOption($name); @@ -221,7 +223,7 @@ class ArgvInput extends Input } if (null !== $value && !$option->acceptValue()) { - throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name)); + throw new RuntimeException(sprintf('The "--%s" option does not accept a value.', $name)); } if (null === $value && $option->acceptValue() && count($this->parsed)) { @@ -239,7 +241,7 @@ class ArgvInput extends Input if (null === $value) { if ($option->isValueRequired()) { - throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name)); + throw new RuntimeException(sprintf('The "--%s" option requires a value.', $name)); } if (!$option->isArray()) { diff --git a/src/Symfony/Component/Console/Input/ArrayInput.php b/src/Symfony/Component/Console/Input/ArrayInput.php index 5743bb8af1..fa58b2c95f 100644 --- a/src/Symfony/Component/Console/Input/ArrayInput.php +++ b/src/Symfony/Component/Console/Input/ArrayInput.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Console\Input; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\InvalidOptionException; + /** * ArrayInput represents an input provided as an array. * @@ -153,12 +156,12 @@ class ArrayInput extends Input * @param string $shortcut The short option key * @param mixed $value The value for the option * - * @throws \InvalidArgumentException When option given doesn't exist + * @throws InvalidOptionException When option given doesn't exist */ private function addShortOption($shortcut, $value) { if (!$this->definition->hasShortcut($shortcut)) { - throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut)); + throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut)); } $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value); @@ -170,20 +173,20 @@ class ArrayInput extends Input * @param string $name The long option key * @param mixed $value The value for the option * - * @throws \InvalidArgumentException When option given doesn't exist - * @throws \InvalidArgumentException When a required value is missing + * @throws InvalidOptionException When option given doesn't exist + * @throws InvalidOptionException When a required value is missing */ private function addLongOption($name, $value) { if (!$this->definition->hasOption($name)) { - throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name)); + throw new InvalidOptionException(sprintf('The "--%s" option does not exist.', $name)); } $option = $this->definition->getOption($name); if (null === $value) { if ($option->isValueRequired()) { - throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name)); + throw new InvalidOptionException(sprintf('The "--%s" option requires a value.', $name)); } $value = $option->isValueOptional() ? $option->getDefault() : true; @@ -198,12 +201,12 @@ class ArrayInput extends Input * @param string $name The argument name * @param mixed $value The value for the argument * - * @throws \InvalidArgumentException When argument given doesn't exist + * @throws InvalidArgumentException When argument given doesn't exist */ private function addArgument($name, $value) { if (!$this->definition->hasArgument($name)) { - throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); + throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } $this->arguments[$name] = $value; diff --git a/src/Symfony/Component/Console/Input/Input.php b/src/Symfony/Component/Console/Input/Input.php index 5e7c140875..7873a013ab 100644 --- a/src/Symfony/Component/Console/Input/Input.php +++ b/src/Symfony/Component/Console/Input/Input.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Console\Input; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\RuntimeException; + /** * Input is the base class for all concrete Input classes. * @@ -69,12 +72,12 @@ abstract class Input implements InputInterface /** * Validates the input. * - * @throws \RuntimeException When not enough arguments are given + * @throws RuntimeException When not enough arguments are given */ public function validate() { if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) { - throw new \RuntimeException('Not enough arguments.'); + throw new RuntimeException('Not enough arguments.'); } } @@ -115,12 +118,12 @@ abstract class Input implements InputInterface * * @return mixed The argument value * - * @throws \InvalidArgumentException When argument given doesn't exist + * @throws InvalidArgumentException When argument given doesn't exist */ public function getArgument($name) { if (!$this->definition->hasArgument($name)) { - throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); + throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault(); @@ -132,12 +135,12 @@ abstract class Input implements InputInterface * @param string $name The argument name * @param string $value The argument value * - * @throws \InvalidArgumentException When argument given doesn't exist + * @throws InvalidArgumentException When argument given doesn't exist */ public function setArgument($name, $value) { if (!$this->definition->hasArgument($name)) { - throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); + throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } $this->arguments[$name] = $value; @@ -172,12 +175,12 @@ abstract class Input implements InputInterface * * @return mixed The option value * - * @throws \InvalidArgumentException When option given doesn't exist + * @throws InvalidArgumentException When option given doesn't exist */ public function getOption($name) { if (!$this->definition->hasOption($name)) { - throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name)); + throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name)); } return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault(); @@ -189,12 +192,12 @@ abstract class Input implements InputInterface * @param string $name The option name * @param string|bool $value The option value * - * @throws \InvalidArgumentException When option given doesn't exist + * @throws InvalidArgumentException When option given doesn't exist */ public function setOption($name, $value) { if (!$this->definition->hasOption($name)) { - throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name)); + throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name)); } $this->options[$name] = $value; diff --git a/src/Symfony/Component/Console/Input/InputArgument.php b/src/Symfony/Component/Console/Input/InputArgument.php index 1167da9a50..24ebb77845 100644 --- a/src/Symfony/Component/Console/Input/InputArgument.php +++ b/src/Symfony/Component/Console/Input/InputArgument.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Console\Input; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\LogicException; + /** * Represents a command line argument. * @@ -37,7 +40,7 @@ class InputArgument * @param string $description A description text * @param mixed $default The default value (for self::OPTIONAL mode only) * - * @throws \InvalidArgumentException When argument mode is not valid + * @throws InvalidArgumentException When argument mode is not valid * * @api */ @@ -46,7 +49,7 @@ class InputArgument if (null === $mode) { $mode = self::OPTIONAL; } elseif (!is_int($mode) || $mode > 7 || $mode < 1) { - throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode)); + throw new InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode)); } $this->name = $name; @@ -91,19 +94,19 @@ class InputArgument * * @param mixed $default The default value * - * @throws \LogicException When incorrect default value is given + * @throws LogicException When incorrect default value is given */ public function setDefault($default = null) { if (self::REQUIRED === $this->mode && null !== $default) { - throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); + throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); } if ($this->isArray()) { if (null === $default) { $default = array(); } elseif (!is_array($default)) { - throw new \LogicException('A default value for an array argument must be an array.'); + throw new LogicException('A default value for an array argument must be an array.'); } } diff --git a/src/Symfony/Component/Console/Input/InputDefinition.php b/src/Symfony/Component/Console/Input/InputDefinition.php index 21ac832c3c..44dee14c31 100644 --- a/src/Symfony/Component/Console/Input/InputDefinition.php +++ b/src/Symfony/Component/Console/Input/InputDefinition.php @@ -14,6 +14,8 @@ namespace Symfony\Component\Console\Input; use Symfony\Component\Console\Descriptor\TextDescriptor; use Symfony\Component\Console\Descriptor\XmlDescriptor; use Symfony\Component\Console\Output\BufferedOutput; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\LogicException; /** * A InputDefinition represents a set of valid command line arguments and options. @@ -110,22 +112,22 @@ class InputDefinition * * @param InputArgument $argument An InputArgument object * - * @throws \LogicException When incorrect argument is given + * @throws LogicException When incorrect argument is given * * @api */ public function addArgument(InputArgument $argument) { if (isset($this->arguments[$argument->getName()])) { - throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName())); + throw new LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName())); } if ($this->hasAnArrayArgument) { - throw new \LogicException('Cannot add an argument after an array argument.'); + throw new LogicException('Cannot add an argument after an array argument.'); } if ($argument->isRequired() && $this->hasOptional) { - throw new \LogicException('Cannot add a required argument after an optional one.'); + throw new LogicException('Cannot add a required argument after an optional one.'); } if ($argument->isArray()) { @@ -148,14 +150,14 @@ class InputDefinition * * @return InputArgument An InputArgument object * - * @throws \InvalidArgumentException When argument given doesn't exist + * @throws InvalidArgumentException When argument given doesn't exist * * @api */ public function getArgument($name) { if (!$this->hasArgument($name)) { - throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); + throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments; @@ -259,20 +261,20 @@ class InputDefinition * * @param InputOption $option An InputOption object * - * @throws \LogicException When option given already exist + * @throws LogicException When option given already exist * * @api */ public function addOption(InputOption $option) { if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) { - throw new \LogicException(sprintf('An option named "%s" already exists.', $option->getName())); + throw new LogicException(sprintf('An option named "%s" already exists.', $option->getName())); } if ($option->getShortcut()) { foreach (explode('|', $option->getShortcut()) as $shortcut) { if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) { - throw new \LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut)); + throw new LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut)); } } } @@ -292,14 +294,14 @@ class InputDefinition * * @return InputOption A InputOption object * - * @throws \InvalidArgumentException When option given doesn't exist + * @throws InvalidArgumentException When option given doesn't exist * * @api */ public function getOption($name) { if (!$this->hasOption($name)) { - throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name)); + throw new InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name)); } return $this->options[$name]; @@ -377,12 +379,12 @@ class InputDefinition * * @return string The InputOption name * - * @throws \InvalidArgumentException When option given does not exist + * @throws InvalidArgumentException When option given does not exist */ private function shortcutToName($shortcut) { if (!isset($this->shortcuts[$shortcut])) { - throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut)); + throw new InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut)); } return $this->shortcuts[$shortcut]; diff --git a/src/Symfony/Component/Console/Input/InputInterface.php b/src/Symfony/Component/Console/Input/InputInterface.php index 6ef2f264fd..f83b88560d 100644 --- a/src/Symfony/Component/Console/Input/InputInterface.php +++ b/src/Symfony/Component/Console/Input/InputInterface.php @@ -88,7 +88,7 @@ interface InputInterface * @param string $name The argument name * @param string $value The argument value * - * @throws \InvalidArgumentException When argument given doesn't exist + * @throws InvalidArgumentException When argument given doesn't exist */ public function setArgument($name, $value); @@ -123,7 +123,7 @@ interface InputInterface * @param string $name The option name * @param string|bool $value The option value * - * @throws \InvalidArgumentException When option given doesn't exist + * @throws InvalidArgumentException When option given doesn't exist */ public function setOption($name, $value); diff --git a/src/Symfony/Component/Console/Input/InputOption.php b/src/Symfony/Component/Console/Input/InputOption.php index 3a48ca36d5..680bfc2c48 100644 --- a/src/Symfony/Component/Console/Input/InputOption.php +++ b/src/Symfony/Component/Console/Input/InputOption.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Console\Input; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\LogicException; + /** * Represents a command line option. * @@ -40,7 +43,7 @@ class InputOption * @param string $description A description text * @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE) * - * @throws \InvalidArgumentException If option mode is invalid or incompatible + * @throws InvalidArgumentException If option mode is invalid or incompatible * * @api */ @@ -51,7 +54,7 @@ class InputOption } if (empty($name)) { - throw new \InvalidArgumentException('An option name cannot be empty.'); + throw new InvalidArgumentException('An option name cannot be empty.'); } if (empty($shortcut)) { @@ -67,14 +70,14 @@ class InputOption $shortcut = implode('|', $shortcuts); if (empty($shortcut)) { - throw new \InvalidArgumentException('An option shortcut cannot be empty.'); + throw new InvalidArgumentException('An option shortcut cannot be empty.'); } } if (null === $mode) { $mode = self::VALUE_NONE; } elseif (!is_int($mode) || $mode > 15 || $mode < 1) { - throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode)); + throw new InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode)); } $this->name = $name; @@ -83,7 +86,7 @@ class InputOption $this->description = $description; if ($this->isArray() && !$this->acceptValue()) { - throw new \InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.'); + throw new InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.'); } $this->setDefault($default); @@ -154,19 +157,19 @@ class InputOption * * @param mixed $default The default value * - * @throws \LogicException When incorrect default value is given + * @throws LogicException When incorrect default value is given */ public function setDefault($default = null) { if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) { - throw new \LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.'); + throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.'); } if ($this->isArray()) { if (null === $default) { $default = array(); } elseif (!is_array($default)) { - throw new \LogicException('A default value for an array option must be an array.'); + throw new LogicException('A default value for an array option must be an array.'); } } diff --git a/src/Symfony/Component/Console/Input/StringInput.php b/src/Symfony/Component/Console/Input/StringInput.php index 40d1dfbc7d..711afb31ee 100644 --- a/src/Symfony/Component/Console/Input/StringInput.php +++ b/src/Symfony/Component/Console/Input/StringInput.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Input; +use Symfony\Component\Console\Exception\InvalidArgumentException; + /** * StringInput represents an input provided as a string. * @@ -59,7 +61,7 @@ class StringInput extends ArgvInput * * @return array An array of tokens * - * @throws \InvalidArgumentException When unable to parse input (should never happen) + * @throws InvalidArgumentException When unable to parse input (should never happen) */ private function tokenize($input) { @@ -76,7 +78,7 @@ class StringInput extends ArgvInput $tokens[] = stripcslashes($match[1]); } else { // should never happen - throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10))); + throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10))); } $cursor += strlen($match[0]); diff --git a/src/Symfony/Component/Console/Output/StreamOutput.php b/src/Symfony/Component/Console/Output/StreamOutput.php index ecf0bb8c1e..1d13ffe881 100644 --- a/src/Symfony/Component/Console/Output/StreamOutput.php +++ b/src/Symfony/Component/Console/Output/StreamOutput.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Output; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Formatter\OutputFormatterInterface; /** @@ -40,14 +42,14 @@ class StreamOutput extends Output * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) * - * @throws \InvalidArgumentException When first argument is not a real stream + * @throws InvalidArgumentException When first argument is not a real stream * * @api */ public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null) { if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) { - throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); + throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); } $this->stream = $stream; @@ -76,7 +78,7 @@ class StreamOutput extends Output { if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) { // should never happen - throw new \RuntimeException('Unable to write output.'); + throw new RuntimeException('Unable to write output.'); } fflush($this->stream); diff --git a/src/Symfony/Component/Console/Question/ChoiceQuestion.php b/src/Symfony/Component/Console/Question/ChoiceQuestion.php index a36c739e56..2c40638dc6 100644 --- a/src/Symfony/Component/Console/Question/ChoiceQuestion.php +++ b/src/Symfony/Component/Console/Question/ChoiceQuestion.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Question; +use Symfony\Component\Console\Exception\InvalidArgumentException; + /** * Represents a choice question. * @@ -126,7 +128,7 @@ class ChoiceQuestion extends Question if ($multiselect) { // Check for a separated comma values if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) { - throw new \InvalidArgumentException(sprintf($errorMessage, $selected)); + throw new InvalidArgumentException(sprintf($errorMessage, $selected)); } $selectedChoices = explode(',', $selectedChoices); } else { @@ -143,7 +145,7 @@ class ChoiceQuestion extends Question } if (count($results) > 1) { - throw new \InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of %s.', implode(' or ', $results))); + throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of %s.', implode(' or ', $results))); } $result = array_search($value, $choices); @@ -159,7 +161,7 @@ class ChoiceQuestion extends Question } if (false === $result) { - throw new \InvalidArgumentException(sprintf($errorMessage, $value)); + throw new InvalidArgumentException(sprintf($errorMessage, $value)); } $multiselectChoices[] = (string) $result; diff --git a/src/Symfony/Component/Console/Question/Question.php b/src/Symfony/Component/Console/Question/Question.php index 01702b208f..9aa4c69d27 100644 --- a/src/Symfony/Component/Console/Question/Question.php +++ b/src/Symfony/Component/Console/Question/Question.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Console\Question; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\LogicException; + /** * Represents a Question. * @@ -76,12 +79,12 @@ class Question * * @return Question The current instance * - * @throws \LogicException In case the autocompleter is also used + * @throws LogicException In case the autocompleter is also used */ public function setHidden($hidden) { if ($this->autocompleterValues) { - throw new \LogicException('A hidden question cannot use the autocompleter.'); + throw new LogicException('A hidden question cannot use the autocompleter.'); } $this->hidden = (bool) $hidden; @@ -130,8 +133,8 @@ class Question * * @return Question The current instance * - * @throws \InvalidArgumentException - * @throws \LogicException + * @throws InvalidArgumentException + * @throws LogicException */ public function setAutocompleterValues($values) { @@ -141,12 +144,12 @@ class Question if (null !== $values && !is_array($values)) { if (!$values instanceof \Traversable || $values instanceof \Countable) { - throw new \InvalidArgumentException('Autocompleter values can be either an array, `null` or an object implementing both `Countable` and `Traversable` interfaces.'); + throw new InvalidArgumentException('Autocompleter values can be either an array, `null` or an object implementing both `Countable` and `Traversable` interfaces.'); } } if ($this->hidden) { - throw new \LogicException('A hidden question cannot use the autocompleter.'); + throw new LogicException('A hidden question cannot use the autocompleter.'); } $this->autocompleterValues = $values; @@ -187,12 +190,12 @@ class Question * * @return Question The current instance * - * @throws \InvalidArgumentException In case the number of attempts is invalid. + * @throws InvalidArgumentException In case the number of attempts is invalid. */ public function setMaxAttempts($attempts) { if (null !== $attempts && $attempts < 1) { - throw new \InvalidArgumentException('Maximum number of attempts must be a positive value.'); + throw new InvalidArgumentException('Maximum number of attempts must be a positive value.'); } $this->attempts = $attempts; diff --git a/src/Symfony/Component/Console/Shell.php b/src/Symfony/Component/Console/Shell.php index eaaadfd8a8..9767a6e1a7 100644 --- a/src/Symfony/Component/Console/Shell.php +++ b/src/Symfony/Component/Console/Shell.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console; +use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Process\ProcessBuilder; @@ -222,7 +223,7 @@ EOF; $this->processIsolation = (bool) $processIsolation; if ($this->processIsolation && !class_exists('Symfony\\Component\\Process\\Process')) { - throw new \RuntimeException('Unable to isolate processes as the Symfony Process Component is not installed.'); + throw new RuntimeException('Unable to isolate processes as the Symfony Process Component is not installed.'); } } } diff --git a/src/Symfony/Component/Console/Style/SymfonyStyle.php b/src/Symfony/Component/Console/Style/SymfonyStyle.php index 0d366c7e89..014a2cb1d1 100644 --- a/src/Symfony/Component/Console/Style/SymfonyStyle.php +++ b/src/Symfony/Component/Console/Style/SymfonyStyle.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console\Style; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Helper\ProgressBar; @@ -361,7 +362,7 @@ class SymfonyStyle extends OutputStyle private function getProgressBar() { if (!$this->progressBar) { - throw new \RuntimeException('The ProgressBar is not started.'); + throw new RuntimeException('The ProgressBar is not started.'); } return $this->progressBar; diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index d33e5848bd..dc2651537a 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -176,7 +176,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Console\Exception\CommandNotFoundException * @expectedExceptionMessage The command "foofoo" does not exist. */ public function testGetInvalidCommand() @@ -212,7 +212,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Console\Exception\CommandNotFoundException * @expectedExceptionMessage The namespace "f" is ambiguous (foo, foo1). */ public function testFindAmbiguousNamespace() @@ -225,7 +225,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Console\Exception\CommandNotFoundException * @expectedExceptionMessage There are no commands defined in the "bar" namespace. */ public function testFindInvalidNamespace() @@ -235,7 +235,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Console\Exception\CommandNotFoundException * @expectedExceptionMessage Command "foo1" is not defined */ public function testFindUniqueNameButNamespaceName() @@ -265,7 +265,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase */ public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage) { - $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage); + $this->setExpectedException('Symfony\Component\Console\Exception\CommandNotFoundException', $expectedExceptionMessage); $application = new Application(); $application->add(new \FooCommand()); @@ -313,7 +313,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase /** * @dataProvider provideInvalidCommandNamesSingle - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Console\Exception\CommandNotFoundException * @expectedExceptionMessage Did you mean this */ public function testFindAlternativeExceptionMessageSingle($name) @@ -341,10 +341,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase // Command + plural try { $application->find('foo:baR'); - $this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives'); + $this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives'); - $this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives'); + $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); + $this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); $this->assertRegExp('/foo1:bar/', $e->getMessage()); $this->assertRegExp('/foo:bar/', $e->getMessage()); } @@ -352,10 +352,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase // Namespace + plural try { $application->find('foo2:bar'); - $this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives'); + $this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives'); - $this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives'); + $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); + $this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); $this->assertRegExp('/foo1/', $e->getMessage()); } @@ -365,9 +365,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase // Subnamespace + plural try { $a = $application->find('foo3:'); - $this->fail('->find() should throw an \InvalidArgumentException if a command is ambiguous because of a subnamespace, with alternatives'); + $this->fail('->find() should throw an Symfony\Component\Console\Exception\CommandNotFoundException if a command is ambiguous because of a subnamespace, with alternatives'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e); + $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e); $this->assertRegExp('/foo3:bar/', $e->getMessage()); $this->assertRegExp('/foo3:bar:toh/', $e->getMessage()); } @@ -383,23 +383,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase try { $application->find($commandName = 'Unknown command'); - $this->fail('->find() throws an \InvalidArgumentException if command does not exist'); + $this->fail('->find() throws a CommandNotFoundException if command does not exist'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist'); - $this->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, without alternatives'); + $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist'); + $this->assertSame(array(), $e->getAlternatives()); + $this->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without alternatives'); } - // Test if "bar1" command throw an "\InvalidArgumentException" and does not contain + // Test if "bar1" command throw a "CommandNotFoundException" and does not contain // "foo:bar" as alternative because "bar1" is too far from "foo:bar" try { $application->find($commandName = 'bar1'); - $this->fail('->find() throws an \InvalidArgumentException if command does not exist'); + $this->fail('->find() throws a CommandNotFoundException if command does not exist'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist'); - $this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives'); - $this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "afoobar1"'); - $this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo:bar1"'); - $this->assertNotRegExp('/foo:bar(?>!1)/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, without "foo:bar" alternative'); + $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist'); + $this->assertSame(array('afoobar1', 'foo:bar1'), $e->getAlternatives()); + $this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); + $this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"'); + $this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"'); + $this->assertNotRegExp('/foo:bar(?>!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative'); } } @@ -427,21 +429,23 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase try { $application->find('Unknown-namespace:Unknown-command'); - $this->fail('->find() throws an \InvalidArgumentException if namespace does not exist'); + $this->fail('->find() throws a CommandNotFoundException if namespace does not exist'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist'); - $this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, without alternatives'); + $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if namespace does not exist'); + $this->assertSame(array(), $e->getAlternatives()); + $this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, without alternatives'); } try { $application->find('foo2:command'); - $this->fail('->find() throws an \InvalidArgumentException if namespace does not exist'); + $this->fail('->find() throws a CommandNotFoundException if namespace does not exist'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist'); - $this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative'); - $this->assertRegExp('/foo/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo"'); - $this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo1"'); - $this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo3"'); + $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if namespace does not exist'); + $this->assertSame(array('foo3', 'foo1', 'foo'), $e->getAlternatives()); + $this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative'); + $this->assertRegExp('/foo/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo"'); + $this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo1"'); + $this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo3"'); } } @@ -456,7 +460,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Console\Exception\CommandNotFoundException * @expectedExceptionMessage Command "foo::bar" is not defined. */ public function testFindWithDoubleColonInNameThrowsException() diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 81221f355c..9d8efe87e0 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -243,7 +243,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Console\Exception\InvalidOptionException * @expectedExceptionMessage The "--bar" option does not exist. */ public function testRunWithInvalidOption() diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt index 4629345c1e..64b66375cb 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt @@ -1,8 +1,8 @@ - - [InvalidArgumentException] - Command "foo" is not defined. - + + [Symfony\Component\Console\Exception\CommandNotFoundException] + Command "foo" is not defined. + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt index 3d9d363b69..f8c998d48d 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt @@ -1,9 +1,9 @@ - - [InvalidArgumentException] - The "--foo" option does not exist. - + + [Symfony\Component\Console\Exception\InvalidOptionException] + The "--foo" option does not exist. + list [--xml] [--raw] [--format FORMAT] [--] [] diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt index 19f893b0c8..e0dbf29e4d 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt @@ -1,9 +1,9 @@ - - [InvalidArgumentException] - Command "foo" is not define - d. - + + [Symfony\Component\Console\Exception\CommandNotFoundException] + Command "foo" is not define + d. + diff --git a/src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php b/src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php index bf58a456ed..3cbe9bd7d2 100644 --- a/src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/HelperSetTest.php @@ -75,10 +75,11 @@ class HelperSetTest extends \PHPUnit_Framework_TestCase $helperset = new HelperSet(); try { $helperset->get('foo'); - $this->fail('->get() throws \InvalidArgumentException when helper not found'); + $this->fail('->get() throws InvalidArgumentException when helper not found'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws \InvalidArgumentException when helper not found'); - $this->assertContains('The helper "foo" is not defined.', $e->getMessage(), '->get() throws \InvalidArgumentException when helper not found'); + $this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws InvalidArgumentException when helper not found'); + $this->assertInstanceOf('Symfony\Component\Console\Exception\ExceptionInterface', $e, '->get() throws domain specific exception when helper not found'); + $this->assertContains('The helper "foo" is not defined.', $e->getMessage(), '->get() throws InvalidArgumentException when helper not found'); } } diff --git a/src/Symfony/Component/Console/Tests/Helper/LegacyDialogHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/LegacyDialogHelperTest.php index e130cdc6bc..df09ba7aa1 100644 --- a/src/Symfony/Component/Console/Tests/Helper/LegacyDialogHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/LegacyDialogHelperTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Helper\DialogHelper; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Output\StreamOutput; +use Symfony\Component\Console\Exception\InvalidArgumentException; /** * @group legacy @@ -141,7 +142,7 @@ class LegacyDialogHelperTest extends \PHPUnit_Framework_TestCase $error = 'This is not a color!'; $validator = function ($color) use ($error) { if (!in_array($color, array('white', 'black'))) { - throw new \InvalidArgumentException($error); + throw new InvalidArgumentException($error); } return $color;