diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index f95b34a312673..7042072deb7aa 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -558,6 +558,7 @@ public function getIterator($flags = 0) } $this->readPipesForOutput(__FUNCTION__, $blocking); + $this->checkTimeout(); } } diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index cd57f3a8c32df..f317fc7d72938 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -747,6 +747,27 @@ public function testRunProcessWithTimeout() throw $e; } + /** + * @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException + * @expectedExceptionMessage exceeded the timeout of 0.1 seconds. + */ + public function testIterateOverProcessWithTimeout() + { + $process = $this->getProcess(self::$phpBin.' -r "sleep(30);"'); + $process->setTimeout(0.1); + $start = microtime(true); + try { + $process->start(); + foreach ($process as $buffer); + $this->fail('A RuntimeException should have been raised'); + } catch (RuntimeException $e) { + } + + $this->assertLessThan(15, microtime(true) - $start); + + throw $e; + } + public function testCheckTimeoutOnNonStartedProcess() { $process = $this->getProcess('echo foo');