diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index c7a1cf2a445b3..9f999c2530b15 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -418,6 +418,9 @@ public function disableOutput() 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 @@ public function setTimeout($timeout) */ 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 75981c97d346f..f15260d729e4a 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -550,7 +550,7 @@ public function testIdleTimeout() { $process = $this->getProcess('sleep 3'); $process->setTimeout(10); - $process->setIdleTimeout(1); + $process->setIdleTimeout(0.5); try { $process->run(); @@ -559,7 +559,7 @@ public function testIdleTimeout() } 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 @@ public function testIdleTimeout() */ 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 @@ public function testIdleTimeoutNotExceededWhenOutputIsSent() } 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 @@ public function testStartAfterATimeout() } $process->start(); - usleep(10000); + usleep(1000); $process->stop(); } @@ -737,6 +737,29 @@ public function testEnableOrDisableOutputAfterRunDoesNotThrowException() $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 */
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: