Skip to content

Commit

Permalink
Fixes GH-147
Browse files Browse the repository at this point in the history
 * Refactored `PHPUnit_Util_PHP::runJob()` to use a file-based solution.
  • Loading branch information
whatthejeff committed Feb 11, 2011
1 parent 20bfe2a commit 7ab7ee8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions PHPUnit/Util/PHP.php
Expand Up @@ -134,24 +134,26 @@ public static function getPhpBinary()
* @param PHPUnit_Framework_TestCase $test * @param PHPUnit_Framework_TestCase $test
* @param PHPUnit_Framework_TestResult $result * @param PHPUnit_Framework_TestResult $result
* @return array|null * @return array|null
* @throws PHPUnit_Framework_Exception
*/ */
public static function runJob($job, PHPUnit_Framework_Test $test = NULL, PHPUnit_Framework_TestResult $result = NULL) public static function runJob($job, PHPUnit_Framework_Test $test = NULL, PHPUnit_Framework_TestResult $result = NULL)
{ {
if(!($file = tempnam(sys_get_temp_dir(), 'PHPUnit')) || file_put_contents($file, $job) === false) {
throw new PHPUnit_Framework_Exception(
'Unable to write temporary files for process isolation.'
);
}

$process = proc_open( $process = proc_open(
self::getPhpBinary(), self::$descriptorSpec, $pipes self::getPhpBinary(), self::$descriptorSpec, $pipes
); );


// Workaround for http://bugs.php.net/bug.php?id=52911
if (DIRECTORY_SEPARATOR == '\\') {
sleep(2);
}

if (is_resource($process)) { if (is_resource($process)) {
if ($result !== NULL) { if ($result !== NULL) {
$result->startTest($test); $result->startTest($test);
} }


fwrite($pipes[0], $job); fwrite($pipes[0], "<?php require_once '" . addcslashes($file, "'") . "'; ?>");
fclose($pipes[0]); fclose($pipes[0]);


$stdout = stream_get_contents($pipes[1]); $stdout = stream_get_contents($pipes[1]);
Expand All @@ -161,12 +163,15 @@ public static function runJob($job, PHPUnit_Framework_Test $test = NULL, PHPUnit
fclose($pipes[2]); fclose($pipes[2]);


proc_close($process); proc_close($process);
unlink($file);


if ($result !== NULL) { if ($result !== NULL) {
self::processChildResult($test, $result, $stdout, $stderr); self::processChildResult($test, $result, $stdout, $stderr);
} else { } else {
return array('stdout' => $stdout, 'stderr' => $stderr); return array('stdout' => $stdout, 'stderr' => $stderr);
} }
} else {
unlink($file);
} }
} }


Expand Down

0 comments on commit 7ab7ee8

Please sign in to comment.