8000 merged branch romainneutron/ProcessExceptions (PR #5398) · romainneutron/symfony@0d181bc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d181bc

Browse files
committed
merged branch romainneutron/ProcessExceptions (PR symfony#5398)
Commits ------- c5e7793 [Process] Normalize exceptions Discussion ---------- [Process] Normalize exceptions Bug fix: no Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes License of the code: MIT There were some exceptions in the Process scope but they were not implemented everywhere in the component. This PR ensure that all exceptions thrown inside Process implements `Process\Exception\ExceptionInterface`. --------------------------------------------------------------------------- by romainneutron at 2012-08-30T20:05:41Z Tests passes, it's a travis issue, see http://travis-ci.org/#!/symfony/symfony/builds/2287439
2 parents bf41d8b + c5e7793 commit 0d181bc

File tree

9 files changed

+72
-23
lines changed

9 files changed

+72
-23
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Process\Exception;
13+
14+
/**
15+
* InvalidArgumentException for the Process Component.
16+
*
17+
* @author Romain Neutron <imprec@gmail.com>
18+
*/
19+
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
20+
{
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Process\Exception;
13+
14+
/**
15+
* LogicException for the Process Component.
16+
*
17+
* @author Romain Neutron <imprec@gmail.com>
18+
*/
19+
class LogicException extends \LogicException implements ExceptionInterface
20+
{
21+
}

src/Symfony/Component/Process/Exception/ProcessFailedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ProcessFailedException extends RuntimeException
2525
public function __construct(Process $process)
2626
{
2727
if ($process->isSuccessful()) {
28-
throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.');
28+
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
2929
}
3030

3131
parent::__construct(

src/Symfony/Component/Process/PhpProcess.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Process;
1313

14+
use Symfony\Component\Process\Exception\RuntimeException;
15+
1416
/**
1517
* PhpProcess runs a PHP script in an independent process.
1618
*
@@ -68,7 +70,7 @@ public function run($callback = null)
6870
{
6971
if (null === $this->getCommandLine()) {
7072
if (false === $php = $this->executableFinder->find()) {
71-
throw new \RuntimeException('Unable to find the PHP executable.');
73+
throw new RuntimeException('Unable to find the PHP executable.');
7274
}
7375
$this->setCommandLine($php);
7476
}

src/Symfony/Component/Process/Process.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Component\Process;
1313

14+
use Symfony\Component\Process\Exception\InvalidArgumentException;
15+
use Symfony\Component\Process\Exception\RuntimeException;
16+
1417
/**
1518
* Process is a thin wrapper around proc_* functions to ease
1619
* start independent PHP processes.
@@ -111,14 +114,14 @@ class Process
111114
* @param integer $timeout The timeout in seconds
112115
* @param array $options An array of options for proc_open
113116
*
114-
* @throws \RuntimeException When proc_open is not installed
117+
* @throws RuntimeException When proc_open is not installed
115118
*
116119
* @api
117120
*/
118121
public function __construct($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
119122
{
120123
if (!function_exists('proc_open')) {
121-
throw new \RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
124+
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
122125
}
123126

124127
$this->commandline = $commandline;
@@ -158,7 +161,7 @@ public function __destruct()
158161
*
159162
* @return integer The exit status code
160163
*
161-
* @throws \RuntimeException When process can't be launch or is stopped
164+
* @throws RuntimeException When process can't be launch or is stopped
162165
*
163166
* @api
164167
*/
@@ -187,13 +190,13 @@ public function run($callback = null)
187190
* @param callable $callback A PHP callback to run whenever there is some
188191
* output available on STDOUT or STDERR
189192
*
190-
* @throws \RuntimeException When process can't be launch or is stopped
191-
* @throws \RuntimeException When process is already running
193+
* @throws RuntimeException When process can't be launch or is stopped
194+
* @throws RuntimeException When process is already running
192195
*/
193196
public function start($callback = null)
194197
{
195198
if ($this->isRunning()) {
196-
throw new \RuntimeException('Process is already running');
199+
throw new RuntimeException('Process is already running');
197200
}
198201

199202
$this->stdout = '';
@@ -233,7 +236,7 @@ public function start($callback = null)
233236
$this->process = proc_open($commandline, $descriptors, $this->pipes, $this->cwd, $this->env, $this->options);
234237

235238
if (!is_resource($this->process)) {
236-
throw new \RuntimeException('Unable to launch a new process.');
239+
throw new RuntimeException('Unable to launch a new process.');
237240
}
238241
$this->status = self::STATUS_STARTED;
239242

@@ -270,7 +273,7 @@ public function start($callback = null)
270273
if ($n === 0) {
271274
proc_terminate($this->process);
272275

273-
throw new \RuntimeException('The process timed out.');
276+
throw new RuntimeException('The process timed out.');
274277
}
275278

276279
if ($w) {
@@ -311,7 +314,7 @@ public function start($callback = null)
311314
*
312315
* @return int The exitcode of the process
313316
*
314-
* @throws \RuntimeException
317+
* @throws RuntimeException
315318
*/
316319
public function wait($callback = null)
317320
{
@@ -337,7 +340,7 @@ public function wait($callback = null)
337340
if (0 === $n) {
338341
proc_terminate($this->process);
339342

340-
throw new \RuntimeException('The process timed out.');
343+
throw new RuntimeException('The process timed out.');
341344
}
342345

343346
foreach ($r as $pipe) {
@@ -361,7 +364,7 @@ public function wait($callback = null)
361364
}
362365
$this->updateStatus();
363366
if ($this->processInformation['signaled']) {
364-
throw new \RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
367+
throw new RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
365368
}
366369

367370
$time = 0;
@@ -373,7 +376,7 @@ public function wait($callback = null)
373376
$exitcode = proc_close($this->process);
374377

375378
if ($this->processInformation['signaled']) {
376-
throw new \RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
379+
throw new RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
377380
}
378381

379382
$this->exitcode = $this->processInformation['running'] ? $exitcode : $this->processInformation['exitcode'];
@@ -546,7 +549,7 @@ public function isRunning()
546549
*
547550
* @return integer The exitcode of the process
548551
*
549-
* @throws \RuntimeException if the process got signaled
552+
* @throws RuntimeException if the process got signaled
550553
*/
551554
public function stop($timeout=10)
552555
{
@@ -622,7 +625,7 @@ public function setTimeout($timeout)
622625
$timeout = (integer) $timeout;
623626

624627
if ($timeout < 0) {
625-
throw new \InvalidArgumentException('The timeout value must be a valid positive integer.');
628+
throw new InvalidArgumentException('The timeout value must be a valid positive integer.');
626629
}
627630

628631
$this->timeout = $timeout;

src/Symfony/Component/Process/ProcessBuilder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Component\Process;
1313

14+
use Symfony\Component\Process\Exception\InvalidArgumentException;
15+
use Symfony\Component\Process\Exception\LogicException;
16+
1417
/**
1518
* Process builder.
1619
*
@@ -99,7 +102,7 @@ public function setTimeout($timeout)
99102
$timeout = (integer) $timeout;
100103

101104
if ($timeout < 0) {
102-
throw new \InvalidArgumentException('The timeout value must be a valid positive integer.');
105+
throw new InvalidArgumentException('The timeout value must be a valid positive integer.');
103106
}
104107

105108
$this->timeout = $timeout;
@@ -117,7 +120,7 @@ public function setOption($name, $value)
117120
public function getProcess()
118121
{
119122
if (!count($this->arguments)) {
120-
throw new \LogicException('You must add() command arguments before calling getProcess().');
123+
throw new LogicException('You must add() command arguments before calling getProcess().');
121124
}
122125

123126
$options = $this->options;

src/Symfony/Component/Process/Tests/ProcessBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function shouldNotReplaceExplicitlySetVars()
8585
}
8686

8787
/**
88-
* @expectedException \InvalidArgumentException
88+
* @expectedException Symfony\Component\Process\Exception\InvalidArgumentException
8989
*/
9090
public function testNegativeTimeoutFromSetter()
9191
{

src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
namespace Symfony\Component\Process\Tests;
1313

14-
use Symfony\Component\Process\Process,
15-
Symfony\Component\Process\Exception\ProcessFailedException;
14+
use Symfony\Component\Process\Exception\ProcessFailedException;
1615

1716
/**
1817
* @author Sebastian Marek <proofek@gmail.com>

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
class ProcessTest extends \PHPUnit_Framework_TestCase
2020
{
2121
/**
22-
* @expectedException \InvalidArgumentException
22+
* @expectedException Symfony\Component\Process\Exception\InvalidArgumentException
2323
*/
2424
public function testNegativeTimeoutFromConstructor()
2525
{
2626
new Process('', null, null, null, -1);
2727
}
2828

2929
/**
30-
* @expectedException \InvalidArgumentException
30+
* @expectedException Symfony\Component\Process\Exception\InvalidArgumentException
3131
*/
3232
public function testNegativeTimeoutFromSetter()
3333
{

0 commit comments

Comments
 (0)
0