Skip to content

[Process] fix phpdoc and timeout of 0 #9466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -658,7 +658,7 @@ public function setCommandLine($commandline)
/**
* 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()
{
Expand All @@ -670,23 +670,19 @@ public function getTimeout()
*
* 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
*
* @throws InvalidArgumentException if the timeout is negative
*/
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.');
}

Expand All @@ -698,11 +694,10 @@ public function setTimeout($timeout)
/**
* 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
Expand Down Expand Up @@ -765,7 +760,7 @@ public function setEnv(array $env)
/**
* Gets the contents of STDIN.
*
* @return string The current contents
* @return string|null The current contents
*/
public function getStdin()
{
Expand All @@ -775,7 +770,7 @@ public function getStdin()
/**
* Sets the contents of STDIN.
*
* @param string $stdin The new contents
* @param string|null $stdin The new contents
*
* @return self The current Process instance
*/
Expand Down Expand Up @@ -875,7 +870,7 @@ public function setEnhanceSigchildCompatibility($enhance)
*/
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.');
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Process/ProcessPipes.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public function hasOpenHandles()
/**
* 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)
{
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Process/Tests/AbstractProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ public function testNegativeTimeoutFromSetter()
$p->setTimeout(-1);
}

public function testNullTimeout()
public function testFloatAndNullTimeout()
{
$p = $this->getProcess('');

$p->setTimeout(10);
$this->assertSame(10.0, $p->getTimeout());

$p->setTimeout(null);
$this->assertNull($p->getTimeout());

$p->setTimeout(0.0);
$this->assertNull($p->getTimeout());
}

Expand Down