[Process] Added support for stdout and stderr flush (Issue #7884)
This commit is contained in:
parent
ded29844cd
commit
90daef75c6
@ -532,6 +532,19 @@ class Process
|
|||||||
return $latest;
|
return $latest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the process output.
|
||||||
|
*
|
||||||
|
* @return Process
|
||||||
|
*/
|
||||||
|
public function flushOutput()
|
||||||
|
{
|
||||||
|
$this->stdout = '';
|
||||||
|
$this->incrementalOutputOffset = 0;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current error output of the process (STDERR).
|
* Returns the current error output of the process (STDERR).
|
||||||
*
|
*
|
||||||
@ -565,6 +578,19 @@ class Process
|
|||||||
return $latest;
|
return $latest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the process output.
|
||||||
|
*
|
||||||
|
* @return Process
|
||||||
|
*/
|
||||||
|
public function flushErrorOutput()
|
||||||
|
{
|
||||||
|
$this->stderr = '';
|
||||||
|
$this->incrementalErrorOutputOffset = 0;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the exit code returned by the process.
|
* Returns the exit code returned by the process.
|
||||||
*
|
*
|
||||||
|
@ -156,6 +156,15 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFlushErrorOutput()
|
||||||
|
{
|
||||||
|
$p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
|
||||||
|
|
||||||
|
$p->run();
|
||||||
|
$p->flushErrorOutput();
|
||||||
|
$this->assertEmpty($p->getErrorOutput());
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetOutput()
|
public function testGetOutput()
|
||||||
{
|
{
|
||||||
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
|
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
|
||||||
@ -175,6 +184,15 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFlushOutput()
|
||||||
|
{
|
||||||
|
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
|
||||||
|
|
||||||
|
$p->run();
|
||||||
|
$p->flushOutput();
|
||||||
|
$this->assertEmpty($p->getOutput());
|
||||||
|
}
|
||||||
|
|
||||||
public function testExitCodeCommandFailed()
|
public function testExitCodeCommandFailed()
|
||||||
{
|
{
|
||||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||||
|
Reference in New Issue
Block a user