diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 66310026b3..5fe56c566f 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -876,9 +876,15 @@ class Process * @param string|null $stdin The new contents * * @return self The current Process instance + * + * @throws LogicException In case the process is running */ public function setStdin($stdin) { + if ($this->isRunning()) { + throw new LogicException('STDIN can not be set while the process is running.'); + } + $this->stdin = $stdin; return $this; diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 738319e24c..3fac141080 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Process\Tests; +use Symfony\Component\Process\Exception\LogicException; use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\RuntimeException; use Symfony\Component\Process\ProcessPipes; @@ -156,6 +157,20 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedLength, strlen($p->getErrorOutput())); } + public function testSetStdinWhileRunningThrowsAnException() + { + $process = $this->getProcess('php -r "usleep(500000);"'); + $process->start(); + try { + $process->setStdin('foobar'); + $process->stop(); + $this->fail('A LogicException should have been raised.'); + } catch (LogicException $e) { + $this->assertEquals('STDIN can not be set while the process is running.', $e->getMessage()); + } + $process->stop(); + } + public function chainedCommandsOutputProvider() { if (defined('PHP_WINDOWS_VERSION_BUILD')) {