Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Process] Fixes & testNonBlockingNorClearingIteratorOutput #18419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions 13 src/Symfony/Component/Process/Pipes/UnixPipes.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,4 @@ public function areOpen()
{
return (bool) $this->pipes;
}

/**
* Creates a new UnixPipes instance.
*
* @param Process $process
* @param string|resource $input
*
* @return UnixPipes
*/
public static function create(Process $process, $input)
{
return new static($process->isTty(), $process->isPty(), $input, !$process->isOutputDisabled() || $process->hasCallback());
}
}
15 changes: 1 addition & 14 deletions 15 src/Symfony/Component/Process/Pipes/WindowsPipes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class WindowsPipes extends AbstractPipes
/** @var bool */
private $haveReadSupport;

public function __construct($haveReadSupport, $input)
public function __construct($input, $haveReadSupport)
{
$this->haveReadSupport = (bool) $haveReadSupport;

Expand Down Expand Up @@ -160,19 +160,6 @@ public function close()
$this->fileHandles = array();
}

/**
* Creates a new WindowsPipes instance.
*
* @param Process $process The process
* @param $input
*
* @return WindowsPipes
*/
public static function create(Process $process, $input)
{
return new static(!$process->isOutputDisabled() || $process->hasCallback(), $input);
}

/**
* Removes temporary files.
*/
Expand Down
20 changes: 5 additions & 15 deletions 20 src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Process implements \IteratorAggregate
const TIMEOUT_PRECISION = 0.2;

private $callback;
private $hasCallback = false;
private $commandline;
private $cwd;
private $env;
Expand Down Expand Up @@ -257,6 +258,7 @@ public function start(callable $callback = null)
$this->resetProcessData();
$this->starttime = $this->lastOutputTime = microtime(true);
$this->callback = $this->buildCallback($callback);
$this->hasCallback = null !== $callback;
$descriptors = $this->getDescriptors();

$commandline = $this->commandline;
Expand Down Expand Up @@ -513,7 +515,7 @@ public function getIterator($blocking = true, $clearOutput = true)
{
$this->readPipesForOutput(__FUNCTION__, false);

while (null !== $this->callback) {
while (null !== $this->callback || !feof($this->stdout) || !feof($this->stderr)) {
$out = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);

if (isset($out[0])) {
Expand Down Expand Up @@ -1229,18 +1231,6 @@ public static function isPtySupported()
return $result = (bool) @proc_open('echo 1', array(array('pty'), array('pty'), array('pty')), $pipes);
}

/**
* Returns whether a callback is used on underlying process output.
*
* @internal
*
* @return bool
*/
public function hasCallback()
{
return (bool) $this->callback;
}

/**
* Creates the descriptors needed by the proc_open.
*
Expand All @@ -1252,9 +1242,9 @@ private function getDescriptors()
$this->input->rewind();
}
if ('\\' === DIRECTORY_SEPARATOR) {
$this->processPipes = WindowsPipes::create($this, $this->input);
$this->processPipes = new WindowsPipes($this->input, !$this->outputDisabled || $this->hasCallback);
} else {
$this->processPipes = UnixPipes::create($this, $this->input);
$this->processPipes = new UnixPipes($this->isTty(), $this->isPty(), $this->input, !$this->outputDisabled || $this->hasCallback);
}

return $this->processPipes->getDescriptors();
Expand Down
36 changes: 36 additions & 0 deletions 36 src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,42 @@ public function testIteratorOutput()
$this->assertSame($expectedOutput, $output);
}

public function testNonBlockingNorClearingIteratorOutput()
{
$input = new InputStream();

$process = new Process(self::$phpBin.' -r '.escapeshellarg('fwrite(STDOUT, fread(STDIN, 3));'));
$process->setInput($input);
$process->start();
$output = array();

foreach ($process->getIterator(false, false) as $type => $data) {
$output[] = array($type, $data);
break;
}
$expectedOutput = array(
array($process::OUT, ''),
);
$this->assertSame($expectedOutput, $output);

$input->write(123);

foreach ($process->getIterator(false, false) as $type => $data) {
if ('' !== $data) {
$output[] = array($type, $data);
}
}

$this->assertSame('123', $process->getOutput());
$this->assertFalse($process->isRunning());

$expectedOutput = array(
array($process::OUT, ''),
array($process::OUT, '123'),
);
$this->assertSame($expectedOutput, $output);
}

/**
* @param string $commandline
* @param null|string $cwd
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.