feature#8288 [Process] Added support for stdout and stderr flush (Issue #7884) (imobilis)
This PR was squashed before being merged into the master branch (closes #8288).
Discussion
----------
[Process] Added support for stdout and stderr flush (Issue #7884)
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #7884
| License | MIT
| Doc PR | https://github.com/symfony/symfony-docs/pull/2728
**To-do**
- [x] Submit changes to the documentation.
- [x] Fix a test broken on travis.
- [x] Fix mistakes on the documentation.
- [x] Removed flush + get methods.
- [x] Changed tests assert calls.
This PR introduces flushing methods for both stdout and stderr on Process class. The new methods are:
- flushOutput(): clears the output buffer.
- flushErrorOutput(): clears the error output buffer.
Tests for new methods are included on the PR.
Commits
-------
90daef7
[Process] Added support for stdout and stderr flush (Issue #7884)
This commit is contained in:
commit
eb6da72cf8
@ -396,6 +396,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).
|
||||
*
|
||||
@ -429,6 +442,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.
|
||||
*
|
||||
|
@ -169,6 +169,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++; usleep(500); }')));
|
||||
@ -188,6 +197,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')) {
|
||||
|
Reference in New Issue
Block a user