[Process] fixed setTimeout() to not allow negative timeout values (closes #4647)
This commit is contained in:
parent
80040c6a29
commit
884fffa9c0
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -83,4 +83,13 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$_ENV = $snapshot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testNegativeTimeoutFromSetter()
|
||||
{
|
||||
$pb = new ProcessBuilder();
|
||||
$pb->setTimeout(-1);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user