Skip to content

Commit

Permalink
[Process] Setting STDIN while running should not be possible
Browse files Browse the repository at this point in the history
  • Loading branch information
romainneutron committed Apr 21, 2014
1 parent ba55b1e commit 3e3517a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -876,9 +876,15 @@ public function getStdin()
* @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;
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Process/Tests/AbstractProcessTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -156,6 +157,20 @@ public function testProcessPipes($code, $size)
$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')) {
Expand Down

0 comments on commit 3e3517a

Please sign in to comment.