[Process] Added support for stdout and stderr flush (Issue #7884)

This commit is contained in:
Juan Traverso 2013-06-16 11:12:20 +02:00 committed by Fabien Potencier
parent ded29844cd
commit 90daef75c6
2 changed files with 44 additions and 0 deletions

View File

@ -532,6 +532,19 @@ class Process
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).
*
@ -565,6 +578,19 @@ class Process
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.
*

View File

@ -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()
{
$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()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {