From c5e77930043a1e07ec08af6352bfa64e9afced35 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 30 Aug 2012 21:25:16 +0200 Subject: [PATCH] [Process] Normalize exceptions --- .../Exception/InvalidArgumentException.php | 21 +++++++++++++ .../Process/Exception/LogicException.php | 21 +++++++++++++ .../Exception/ProcessFailedException.php | 2 +- src/Symfony/Component/Process/PhpProcess.php | 4 ++- src/Symfony/Component/Process/Process.php | 31 ++++++++++--------- .../Component/Process/ProcessBuilder.php | 7 +++-- .../Process/Tests/ProcessBuilderTest.php | 2 +- .../Tests/ProcessFailedExceptionTest.php | 3 +- .../Component/Process/Tests/ProcessTest.php | 4 +-- 9 files changed, 72 insertions(+), 23 deletions(-) create mode 100644 src/Symfony/Component/Process/Exception/InvalidArgumentException.php create mode 100644 src/Symfony/Component/Process/Exception/LogicException.php diff --git a/src/Symfony/Component/Process/Exception/InvalidArgumentException.php b/src/Symfony/Component/Process/Exception/InvalidArgumentException.php new file mode 100644 index 000000000000..926ee2118b03 --- /dev/null +++ b/src/Symfony/Component/Process/Exception/InvalidArgumentException.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\Process\Exception; + +/** + * InvalidArgumentException for the Process Component. + * + * @author Romain Neutron + */ +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/src/Symfony/Component/Process/Exception/LogicException.php b/src/Symfony/Component/Process/Exception/LogicException.php new file mode 100644 index 000000000000..be3d490dde8c --- /dev/null +++ b/src/Symfony/Component/Process/Exception/LogicException.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\Process\Exception; + +/** + * LogicException for the Process Component. + * + * @author Romain Neutron + */ +class LogicException extends \LogicException implements ExceptionInterface +{ +} diff --git a/src/Symfony/Component/Process/Exception/ProcessFailedException.php b/src/Symfony/Component/Process/Exception/ProcessFailedException.php index a4540c065710..010789ddac41 100755 --- a/src/Symfony/Component/Process/Exception/ProcessFailedException.php +++ b/src/Symfony/Component/Process/Exception/ProcessFailedException.php @@ -25,7 +25,7 @@ class ProcessFailedException extends RuntimeException public function __construct(Process $process) { if ($process->isSuccessful()) { - throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.'); + throw new InvalidArgumentException('Expected a failed process, but the given process was successful.'); } parent::__construct( diff --git a/src/Symfony/Component/Process/PhpProcess.php b/src/Symfony/Component/Process/PhpProcess.php index 2bd560045156..956052d421aa 100644 --- a/src/Symfony/Component/Process/PhpProcess.php +++ b/src/Symfony/Component/Process/PhpProcess.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Process; +use Symfony\Component\Process\Exception\RuntimeException; + /** * PhpProcess runs a PHP script in an independent process. * @@ -68,7 +70,7 @@ public function run($callback = null) { if (null === $this->getCommandLine()) { if (false === $php = $this->executableFinder->find()) { - throw new \RuntimeException('Unable to find the PHP executable.'); + throw new RuntimeException('Unable to find the PHP executable.'); } $this->setCommandLine($php); } diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index cd1e8b42155a..14d304708541 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Process; +use Symfony\Component\Process\Exception\InvalidArgumentException; +use Symfony\Component\Process\Exception\RuntimeException; + /** * Process is a thin wrapper around proc_* functions to ease * start independent PHP processes. @@ -111,14 +114,14 @@ class Process * @param integer $timeout The timeout in seconds * @param array $options An array of options for proc_open * - * @throws \RuntimeException When proc_open is not installed + * @throws RuntimeException When proc_open is not installed * * @api */ public function __construct($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array()) { if (!function_exists('proc_open')) { - throw new \RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.'); + throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.'); } $this->commandline = $commandline; @@ -158,7 +161,7 @@ public function __destruct() * * @return integer The exit status code * - * @throws \RuntimeException When process can't be launch or is stopped + * @throws RuntimeException When process can't be launch or is stopped * * @api */ @@ -187,13 +190,13 @@ public function run($callback = null) * @param Closure|string|array $callback A PHP callback to run whenever there is some * output available on STDOUT or STDERR * - * @throws \RuntimeException When process can't be launch or is stopped - * @throws \RuntimeException When process is already running + * @throws RuntimeException When process can't be launch or is stopped + * @throws RuntimeException When process is already running */ public function start($callback = null) { if ($this->isRunning()) { - throw new \RuntimeException('Process is already running'); + throw new RuntimeException('Process is already running'); } $this->stdout = ''; @@ -233,7 +236,7 @@ public function start($callback = null) $this->process = proc_open($commandline, $descriptors, $this->pipes, $this->cwd, $this->env, $this->options); if (!is_resource($this->process)) { - throw new \RuntimeException('Unable to launch a new process.'); + throw new RuntimeException('Unable to launch a new process.'); } $this->status = self::STATUS_STARTED; @@ -270,7 +273,7 @@ public function start($callback = null) if ($n === 0) { proc_terminate($this->process); - throw new \RuntimeException('The process timed out.'); + throw new RuntimeException('The process timed out.'); } if ($w) { @@ -311,7 +314,7 @@ public function start($callback = null) * * @return int The exitcode of the process * - * @throws \RuntimeException + * @throws RuntimeException */ public function wait($callback = null) { @@ -337,7 +340,7 @@ public function wait($callback = null) if (0 === $n) { proc_terminate($this->process); - throw new \RuntimeException('The process timed out.'); + throw new RuntimeException('The process timed out.'); } foreach ($r as $pipe) { @@ -361,7 +364,7 @@ public function wait($callback = null) } $this->updateStatus(); if ($this->processInformation['signaled']) { - throw new \RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig'])); + throw new RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig'])); } $time = 0; @@ -373,7 +376,7 @@ public function wait($callback = null) $exitcode = proc_close($this->process); if ($this->processInformation['signaled']) { - throw new \RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig'])); + throw new RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig'])); } $this->exitcode = $this->processInformation['running'] ? $exitcode : $this->processInformation['exitcode']; @@ -546,7 +549,7 @@ public function isRunning() * * @return integer The exitcode of the process * - * @throws \RuntimeException if the process got signaled + * @throws RuntimeException if the process got signaled */ public function stop($timeout=10) { @@ -622,7 +625,7 @@ public function setTimeout($timeout) $timeout = (integer) $timeout; if ($timeout < 0) { - throw new \InvalidArgumentException('The timeout value must be a valid positive integer.'); + throw new InvalidArgumentException('The timeout value must be a valid positive integer.'); } $this->timeout = $timeout; diff --git a/src/Symfony/Component/Process/ProcessBuilder.php b/src/Symfony/Component/Process/ProcessBuilder.php index 2ffb3af5ffb9..2a88ea00d4ba 100644 --- a/src/Symfony/Component/Process/ProcessBuilder.php +++ b/src/Symfony/Component/Process/ProcessBuilder.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Process; +use Symfony\Component\Process\Exception\InvalidArgumentException; +use Symfony\Component\Process\Exception\LogicException; + /** * Process builder. * @@ -99,7 +102,7 @@ public function setTimeout($timeout) $timeout = (integer) $timeout; if ($timeout < 0) { - throw new \InvalidArgumentException('The timeout value must be a valid positive integer.'); + throw new InvalidArgumentException('The timeout value must be a valid positive integer.'); } $this->timeout = $timeout; @@ -117,7 +120,7 @@ public function setOption($name, $value) public function getProcess() { if (!count($this->arguments)) { - throw new \LogicException('You must add() command arguments before calling getProcess().'); + throw new LogicException('You must add() command arguments before calling getProcess().'); } $options = $this->options; diff --git a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php index 9ca45a80a790..4f6157e46e7f 100644 --- a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php @@ -85,7 +85,7 @@ public function shouldNotReplaceExplicitlySetVars() } /** - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Process\Exception\InvalidArgumentException */ public function testNegativeTimeoutFromSetter() { diff --git a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php index 356c7debaa02..9bc2fdf30fa5 100644 --- a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php @@ -11,8 +11,7 @@ namespace Symfony\Component\Process\Tests; -use Symfony\Component\Process\Process, - Symfony\Component\Process\Exception\ProcessFailedException; +use Symfony\Component\Process\Exception\ProcessFailedException; /** * @author Sebastian Marek diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 64f929cc20d6..da04712f8419 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -19,7 +19,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase { /** - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Process\Exception\InvalidArgumentException */ public function testNegativeTimeoutFromConstructor() { @@ -27,7 +27,7 @@ public function testNegativeTimeoutFromConstructor() } /** - * @expectedException \InvalidArgumentException + * @expectedException Symfony\Component\Process\Exception\InvalidArgumentException */ public function testNegativeTimeoutFromSetter() {