[Process] fixed setTimeout() to not allow negative timeout values (closes #4647)

This commit is contained in:
Fabien Potencier 2012-07-10 15:21:23 +02:00
parent 80040c6a29
commit 884fffa9c0
4 changed files with 39 additions and 1 deletions

View File

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

View File

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

View File

@ -83,4 +83,13 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
$_ENV = $snapshot;
}
/**
* @expectedException \InvalidArgumentException
*/
public function testNegativeTimeoutFromSetter()
{
$pb = new ProcessBuilder();
$pb->setTimeout(-1);
}
}

View File

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