10000 [Process] Added support for stdout and stderr flush (Issue #7884) by imobilis · Pull Request #8288 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

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

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[Process] New tests for flush methods
  • Loading branch information
Juan Traverso committed Jun 16, 2013
commit 9f5aef941c347aeac9f32ee567b428863a340d2d
60 changes: 60 additions & 0 deletions src/Symfony/Component/Process/Tests/AbstractProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,36 @@ public function testGetIncrementalErrorOutput()
}
}

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->assertEquals('', $p->getErrorOutput());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEmpty() ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right @stloyd assertEmpty is more accurate. I'll change that.

}

public function testGetAndFlushErrorOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));

$p->run();
$this->assertEquals(3, preg_match_all('/ERROR/', $p->getAndFlushErrorOutput(), $matches));
$this->assertEquals('', $p->getErrorOutput());
}

public function testGetAndFlushIncrementalErrorOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { usleep(50000); file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));

$p->start();
while ($p->isRunning()) {
$this->assertLessThanOrEqual(1, preg_match_all('/ERROR/', $p->getandFlushIncrementalErrorOutput(), $matches));
$this->assertEquals('', $p->getErrorOutput());
usleep(20000);
}
}

public function testGetOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
Expand All @@ -175,6 +205,36 @@ public function testGetIncrementalOutput()
}
}

public function testFlushOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));

$p->run();
$p->flushOutput();
$this->assertEquals('', $p->getOutput());
}

public function testGetAndFlushOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));

$p->run();
$this->assertEquals(3, preg_match_all('/foo/', $p->getAndFlushOutput(), $matches));
$this->assertEquals('', $p->getOutput());
}

public function testGetAndFlushIncrementalOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) { echo \' foo \'; usleep(50000); $n++; }')));

$p->start();
while ($p->isRunning()) {
$this->assertLessThanOrEqual(1, preg_match_all('/foo/', $p->getAndFlushIncrementalOutput(), $matches));
$this->assertEquals('', $p->getOutput());
usleep(20000);
}
}

public function testExitCodeCommandFailed()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
Expand Down
0