Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb6da72

Browse files
committed
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 | symfony/symfony-docs#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)
2 parents c5a6578 + 90daef7 commit eb6da72

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,19 @@ public function getIncrementalOutput()
396396
return $latest;
397397
}
398398

399+
/**
400+
* Clears the process output.
401+
*
402+
* @return Process
403+
*/
404+
public function flushOutput()
405+
{
406+
$this->stdout = '';
407+
$this->incrementalOutputOffset = 0;
408+
409+
return $this;
410+
}
411+
399412
/**
400413
* Returns the current error output of the process (STDERR).
401414
*
@@ -429,6 +442,19 @@ public function getIncrementalErrorOutput()
429442
return $latest;
430443
}
431444

445+
/**
446+
* Clears the process output.
447+
*
448+
* @return Process
449+
*/
450+
public function flushErrorOutput()
451+
{
452+
$this->stderr = '';
453+
$this->incrementalErrorOutputOffset = 0;
454+
455+
return $this;
456+
}
457+
432458
/**
433459
* Returns the exit code returned by the process.
434460
*

src/Symfony/Component/Process/Tests/AbstractProcessTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ public function testGetIncrementalErrorOutput()
169169
}
170170
}
171171

172+
public function testFlushErrorOutput()
173+
{
174+
$p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
175+
176+
$p->run();
177+
$p->flushErrorOutput();
178+
$this->assertEmpty($p->getErrorOutput());
179+
}
180+
172181
public function testGetOutput()
173182
{
174183
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++; usleep(500); }')));
@@ -188,6 +197,15 @@ public function testGetIncrementalOutput()
188197
}
189198
}
190199

200+
public function testFlushOutput()
201+
{
202+
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
203+
204+
$p->run();
205+
$p->flushOutput();
206+
$this->assertEmpty($p->getOutput());
207+
}
208+
191209
public function testExitCodeCommandFailed()
192210
{
193211
if (defined('PHP_WINDOWS_VERSION_BUILD')) {

0 commit comments

Comments
 (0)