minor #9466 [Process] fix phpdoc and timeout of 0 (Tobion)

This PR was merged into the 2.2 branch.

Discussion
----------

[Process] fix phpdoc and timeout of 0

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | n/a

getTimeout says it returns null when it's disabled. But passing 0 or 0.0 also disabled timeouts. So it should be treated as null as well. also it says it returns integer whereas it returns float.

Commits
-------

1758010 [Process] fix phpdoc and timeout of 0
This commit is contained in:
Fabien Potencier 2013-11-22 18:11:04 +01:00
commit 0434c7435d
3 changed files with 25 additions and 25 deletions

View File

@ -117,12 +117,12 @@ class Process
/**
* Constructor.
*
* @param string $commandline The command line to run
* @param string $cwd The working directory
* @param array $env The environment variables or null to inherit
* @param string $stdin The STDIN content
* @param integer $timeout The timeout in seconds
* @param array $options An array of options for proc_open
* @param string $commandline The command line to run
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
* @param array|null $env The environment variables or null to inherit
* @param string|null $stdin The STDIN content
* @param integer|float|null $timeout The timeout in seconds or null to disable
* @param array $options An array of options for proc_open
*
* @throws RuntimeException When proc_open is not installed
*
@ -658,7 +658,7 @@ class Process
/**
* Gets the process timeout.
*
* @return integer|null The timeout in seconds or null if it's disabled
* @return float|null The timeout in seconds or null if it's disabled
*/
public function getTimeout()
{
@ -670,7 +670,7 @@ class Process
*
* To disable the timeout, set this value to null.
*
* @param float|null $timeout The timeout in seconds
* @param integer|float|null $timeout The timeout in seconds
*
* @return self The current Process instance
*
@ -678,15 +678,11 @@ class Process
*/
public function setTimeout($timeout)
{
if (null === $timeout) {
$this->timeout = null;
return $this;
}
$timeout = (float) $timeout;
if ($timeout < 0) {
if (0.0 === $timeout) {
$timeout = null;
} elseif ($timeout < 0) {
throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
}
@ -698,11 +694,10 @@ class Process
/**
* Gets the working directory.
*
* @return string The current working directory
* @return string|null The current working directory or null on failure
*/
public function getWorkingDirectory()
{
// This is for BC only
if (null === $this->cwd) {
// getcwd() will return false if any one of the parent directories does not have
// the readable or search mode set, even if the current directory does
@ -765,7 +760,7 @@ class Process
/**
* Gets the contents of STDIN.
*
* @return string The current contents
* @return string|null The current contents
*/
public function getStdin()
{
@ -775,7 +770,7 @@ class Process
/**
* Sets the contents of STDIN.
*
* @param string $stdin The new contents
* @param string|null $stdin The new contents
*
* @return self The current Process instance
*/
@ -875,7 +870,7 @@ class Process
*/
public function checkTimeout()
{
if (0 < $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
$this->stop(0);
throw new RuntimeException('The process timed-out.');

View File

@ -156,8 +156,8 @@ class ProcessPipes
/**
* Writes stdin data.
*
* @param Boolean $blocking Whether to use blocking calls or not.
* @param string $stdin The data to write.
* @param Boolean $blocking Whether to use blocking calls or not.
* @param string|null $stdin The data to write.
*/
public function write($blocking, $stdin)
{

View File

@ -46,12 +46,17 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$p->setTimeout(-1);
}
public function testNullTimeout()
public function testFloatAndNullTimeout()
{
$p = $this->getProcess('');
$p->setTimeout(10);
$p->setTimeout(null);
$p->setTimeout(10);
$this->assertSame(10.0, $p->getTimeout());
$p->setTimeout(null);
$this->assertNull($p->getTimeout());
$p->setTimeout(0.0);
$this->assertNull($p->getTimeout());
}