diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 1c11505f07..5b6773540a 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -131,7 +131,7 @@ class Process $this->env = null; } $this->stdin = $stdin; - $this->timeout = $timeout; + $this->setTimeout($timeout); $this->enhanceWindowsCompatibility = true; $this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options); } @@ -587,6 +587,12 @@ class Process public function setTimeout($timeout) { + $timeout = (integer) $timeout; + + if ($timeout < 0) { + 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 a1008e2b71..f9d2333d64 100644 --- a/src/Symfony/Component/Process/ProcessBuilder.php +++ b/src/Symfony/Component/Process/ProcessBuilder.php @@ -83,6 +83,12 @@ class ProcessBuilder public function setTimeout($timeout) { + $timeout = (integer) $timeout; + + if ($timeout < 0) { + throw new \InvalidArgumentException('The timeout value must be a valid positive integer.'); + } + $this->timeout = $timeout; return $this; diff --git a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php index 4e9c2e885e..fd9d620730 100644 --- a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php @@ -83,4 +83,13 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase $_ENV = $snapshot; } + + /** + * @expectedException \InvalidArgumentException + */ + public function testNegativeTimeoutFromSetter() + { + $pb = new ProcessBuilder(); + $pb->setTimeout(-1); + } } diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index dcaa3f4b59..354b3aea8a 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -18,6 +18,23 @@ use Symfony\Component\Process\Process; */ class ProcessTest extends \PHPUnit_Framework_TestCase { + /** + * @expectedException \InvalidArgumentException + */ + public function testNegativeTimeoutFromConstructor() + { + new Process('', null, null, null, -1); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testNegativeTimeoutFromSetter() + { + $p = new Process(''); + $p->setTimeout(-1); + } + /** * tests results from sub processes *