Skip to content

Commit

Permalink
Added regression test.
Browse files Browse the repository at this point in the history
  • Loading branch information
sun committed Jul 23, 2014

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e243de0 commit ab8345f
Showing 3 changed files with 136 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Util/PHP.php
Original file line number Diff line number Diff line change
@@ -128,6 +128,8 @@ private function processChildResult(PHPUnit_Framework_Test $test, PHPUnit_Framew
$time = 0;

if (!empty($stderr)) {
// @todo Not catch-able by @expectedException.
// @todo STDERR == PHPUnit_Framework_Error?
$result->addError(
$test,
new PHPUnit_Framework_Exception(trim($stderr)), $time
27 changes: 27 additions & 0 deletions tests/Regression/GitHub/1340.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
GH-1340: Process isolation blocks infinitely upon fatal error
--FILE--
<?php

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][3] = 'Issue1340Test';
$_SERVER['argv'][4] = dirname(__FILE__).'/1340/Issue1340Test.php';

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

.
parent
.
child
php://stdout
.
STDOUT
.......

Time: %s, Memory: %sMb

OK (10 tests, 10 assertions)
107 changes: 107 additions & 0 deletions tests/Regression/GitHub/1340/Issue1340Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
class Issue1340Test extends PHPUnit_Framework_TestCase
{
protected function prepareTemplate(\Text_Template $template) {
$property = new \ReflectionProperty($template, 'values');
$property->setAccessible(true);
$value = $property->getValue($template);

$template->setVar(array(
'included_files' => $value['included_files'] . '$excessive_stdin = ' . var_export(str_repeat('1234567890', 30000), TRUE) . ";\n",
));
}

public function testSameProcess()
{
echo "\nparent\n";
$this->assertTrue(TRUE);
}

/**
* @runInSeparateProcess
*/
public function testIsolatedDebugOutput() {
echo "\nchild\n";
file_put_contents('php://stdout', "\nphp://stdout\n");
$this->assertTrue(TRUE);
}

/**
* @runInSeparateProcess
*/
public function testIsolatedDebugSTDOUT() {
fwrite(STDOUT, "\nSTDOUT\n");
$this->assertTrue(TRUE);
}

/**
* @runInSeparateProcess
* @expectedOutput expected
* @see https://bugs.php.net/bug.php?id=43283
* @see https://gist.github.com/sun/d02c242514c8f34bccdb
*/
public function testIsolatedExpectedOutput() {
echo "\nexpected\n";
}

/**
* @runInSeparateProcess
* @expectedOutput expected
* @see https://bugs.php.net/bug.php?id=43283
* @see https://gist.github.com/sun/d02c242514c8f34bccdb
*/
public function testIsolatedExpectedPhpSTDOUT() {
file_put_contents('php://stdout', "\nexpected\n");
}

/**
* @runInSeparateProcess
* @expectedOutput STDOUT is a stream
* @see https://bugs.php.net/bug.php?id=43283
* @see https://gist.github.com/sun/d02c242514c8f34bccdb
*/
public function testIsolatedExpectedSTDOUT() {
fwrite(STDOUT, "\nSTDOUT is a stream\n");
}

/**
* @runInSeparateProcess
* @expectedException \PHPUnit_Framework_Error
* @expectedExceptionMessage php://stderr
* @see https://bugs.php.net/bug.php?id=43283
* @see https://gist.github.com/sun/d02c242514c8f34bccdb
*/
public function testIsolatedExpectedPhpSTDERR() {
file_put_contents('php://stderr', "\nphp://stderr\n");
}

/**
* @runInSeparateProcess
* @expectedException \PHPUnit_Framework_Error
* @expectedExceptionMessage STDERR
* @see https://bugs.php.net/bug.php?id=43283
* @see https://gist.github.com/sun/d02c242514c8f34bccdb
*/
public function testIsolatedExpectedSTDERR() {
fwrite(STDERR, "\nSTDERR\n");
}

/**
* @runInSeparateProcess
* @expectedException \PHPUnit_Framework_Error_Notice
* @expectedExceptionMessage Undefined variable: foo
*/
public function testIsolatedNotice() {
$bar = $foo['foo'];
}

/**
* @runInSeparateProcess
* @expectedException \PHPUnit_Framework_Error
* @expectedExceptionMessage Fatal error: Call to undefined function undefined_function()
*/
public function testIsolatedFatalError() {
$undefined = 'undefined_function';
$undefined();
}
}

0 comments on commit ab8345f

Please sign in to comment.