diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index c7a1cf2a44..9f999c2530 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -418,6 +418,9 @@ class Process if ($this->isRunning()) { throw new RuntimeException('Disabling output while the process is running is not possible.'); } + if (null !== $this->idleTimeout) { + throw new LogicException('Output can not be disabled while an idle timeout is set.'); + } $this->outputDisabled = true; @@ -870,6 +873,10 @@ class Process */ public function setIdleTimeout($timeout) { + if (null !== $timeout && $this->outputDisabled) { + throw new LogicException('Idle timeout can not be set while the output is disabled.'); + } + $this->idleTimeout = $this->validateTimeout($timeout); return $this; diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 75981c97d3..f15260d729 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -550,7 +550,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase { $process = $this->getProcess('sleep 3'); $process->setTimeout(10); - $process->setIdleTimeout(1); + $process->setIdleTimeout(0.5); try { $process->run(); @@ -559,7 +559,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase } catch (ProcessTimedOutException $ex) { $this->assertTrue($ex->isIdleTimeout()); $this->assertFalse($ex->isGeneralTimeout()); - $this->assertEquals(1.0, $ex->getExceededTimeout()); + $this->assertEquals(0.5, $ex->getExceededTimeout()); } } @@ -568,9 +568,9 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase */ public function testIdleTimeoutNotExceededWhenOutputIsSent() { - $process = $this->getProcess('echo "foo" && sleep 1 && echo "foo" && sleep 1 && echo "foo" && sleep 1 && echo "foo" && sleep 5'); - $process->setTimeout(5); - $process->setIdleTimeout(3); + $process = $this->getProcess('echo "foo" && sleep 1 && echo "foo" && sleep 1 && echo "foo" && sleep 1'); + $process->setTimeout(2); + $process->setIdleTimeout(1.5); try { $process->run(); @@ -578,14 +578,14 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase } catch (ProcessTimedOutException $ex) { $this->assertTrue($ex->isGeneralTimeout()); $this->assertFalse($ex->isIdleTimeout()); - $this->assertEquals(5.0, $ex->getExceededTimeout()); + $this->assertEquals(2, $ex->getExceededTimeout()); } } public function testStartAfterATimeout() { $process = $this->getProcess('php -r "while (true) {echo \'\'; usleep(1000); }"'); - $process->setTimeout(0.1); + $process->setTimeout(0.2); try { $process->run(); $this->fail('An exception should have been raised.'); @@ -593,7 +593,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase } $process->start(); - usleep(10000); + usleep(1000); $process->stop(); } @@ -737,6 +737,29 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $p->disableOutput(); } + public function testDisableOutputWhileIdleTimeoutIsSet() + { + $process = $this->getProcess('sleep 3'); + $process->setIdleTimeout(1); + $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Output can not be disabled while an idle timeout is set.'); + $process->disableOutput(); + } + + public function testSetIdleTimeoutWhileOutputIsDisabled() + { + $process = $this->getProcess('sleep 3'); + $process->disableOutput(); + $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Idle timeout can not be set while the output is disabled.'); + $process->setIdleTimeout(1); + } + + public function testSetNullIdleTimeoutWhileOutputIsDisabled() + { + $process = $this->getProcess('sleep 3'); + $process->disableOutput(); + $process->setIdleTimeout(null); + } + /** * @dataProvider provideStartMethods */