Skip to content
Browse files

Fixes GH-147

 * Refactored `PHPUnit_Util_PHP::runJob()` to use a file-based solution.
  • Loading branch information...
1 parent 20bfe2a commit 7ab7ee8d838c48e56b90a5541448d8dfa1422aee @whatthejeff whatthejeff committed Feb 11, 2011
Showing with 11 additions and 6 deletions.
  1. +11 −6 PHPUnit/Util/PHP.php
View
17 PHPUnit/Util/PHP.php
@@ -134,24 +134,26 @@ public static function getPhpBinary()
* @param PHPUnit_Framework_TestCase $test
* @param PHPUnit_Framework_TestResult $result
* @return array|null
+ * @throws PHPUnit_Framework_Exception
*/
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(
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 ($result !== NULL) {
$result->startTest($test);
}
- fwrite($pipes[0], $job);
+ fwrite($pipes[0], "<?php require_once '" . addcslashes($file, "'") . "'; ?>");
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
@@ -161,12 +163,15 @@ public static function runJob($job, PHPUnit_Framework_Test $test = NULL, PHPUnit
fclose($pipes[2]);
proc_close($process);
+ unlink($file);
if ($result !== NULL) {
self::processChildResult($test, $result, $stdout, $stderr);
} else {
return array('stdout' => $stdout, 'stderr' => $stderr);
}
+ } else {
+ unlink($file);
}
}

0 comments on commit 7ab7ee8

Please sign in to comment.
Something went wrong with that request. Please try again.