Skip to content

Commit

Permalink
Merge pull request #1366 from sun/cli-io-streams
Browse files Browse the repository at this point in the history
STDOUT/STDERR IO streams do not exist in process isolation
  • Loading branch information
whatthejeff committed Jul 30, 2014
2 parents 89c425e + 1dc6673 commit 30a6b8e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Util/PHP/Template/TestCaseMethod.tpl.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
if (!defined('STDOUT')) {
// php://stdout does not obey output buffering. Any output would break
// unserialization of child process results in the parent process.
define('STDOUT', fopen('php://temp', 'w+b'));
define('STDERR', fopen('php://stderr', 'wb'));
}

{iniSettings}
ini_set('display_errors', 'stderr');
set_include_path('{include_path}');
Expand Down Expand Up @@ -40,6 +47,11 @@ function __phpunit_run_isolated_test()
$test->run($result);
$output = $test->getActualOutput();

rewind(STDOUT);
if ($stdout = stream_get_contents(STDOUT)) {
$output = $stdout . $output;
}

print serialize(
array(
'testResult' => $test->getResult(),
Expand Down
35 changes: 35 additions & 0 deletions tests/Regression/GitHub/1348.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
GH-1348: STDOUT/STDERR IO streams should exist in process isolation
--SKIPIF--
<?php
if (defined('HHVM_VERSION'))
print "skip: PHP runtime required";
?>
--FILE--
<?php

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][] = '--strict';
$_SERVER['argv'][] = '--process-isolation';
$_SERVER['argv'][] = 'Issue1348Test';
$_SERVER['argv'][] = __DIR__ . '/1348/Issue1348Test.php';

require __DIR__ . '/../../bootstrap.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

.
STDOUT does not break test result
E

Time: %s, Memory: %sMb

There was 1 error:

1) Issue1348Test::testSTDERR
PHPUnit_Framework_Exception: STDERR works as usual.

FAILURES!
Tests: 2, Assertions: 1, Errors: 1.
14 changes: 14 additions & 0 deletions tests/Regression/GitHub/1348/Issue1348Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
class Issue1348Test extends PHPUnit_Framework_TestCase
{
public function testSTDOUT()
{
fwrite(STDOUT, "\nSTDOUT does not break test result\n");
$this->assertTrue(true);
}

public function testSTDERR()
{
fwrite(STDERR, 'STDERR works as usual.');
}
}

0 comments on commit 30a6b8e

Please sign in to comment.