[Process] Setting STDIN while running should not be possible
This commit is contained in:
parent
ba55b1ed18
commit
3e3517abfd
@ -876,9 +876,15 @@ class Process
|
|||||||
* @param string|null $stdin The new contents
|
* @param string|null $stdin The new contents
|
||||||
*
|
*
|
||||||
* @return self The current Process instance
|
* @return self The current Process instance
|
||||||
|
*
|
||||||
|
* @throws LogicException In case the process is running
|
||||||
*/
|
*/
|
||||||
public function setStdin($stdin)
|
public function setStdin($stdin)
|
||||||
{
|
{
|
||||||
|
if ($this->isRunning()) {
|
||||||
|
throw new LogicException('STDIN can not be set while the process is running.');
|
||||||
|
}
|
||||||
|
|
||||||
$this->stdin = $stdin;
|
$this->stdin = $stdin;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Process\Tests;
|
namespace Symfony\Component\Process\Tests;
|
||||||
|
|
||||||
|
use Symfony\Component\Process\Exception\LogicException;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Symfony\Component\Process\Exception\RuntimeException;
|
use Symfony\Component\Process\Exception\RuntimeException;
|
||||||
use Symfony\Component\Process\ProcessPipes;
|
use Symfony\Component\Process\ProcessPipes;
|
||||||
@ -156,6 +157,20 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedLength, strlen($p->getErrorOutput()));
|
$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()
|
public function chainedCommandsOutputProvider()
|
||||||
{
|
{
|
||||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||||
|
Reference in New Issue
Block a user