Permalink
Browse files

Refs GH-147

 * Only use the file-based solution for Windows.
  • Loading branch information...
1 parent 7ab7ee8 commit f4cc7224047fc331c6fb324156875eb132b0ab45 @whatthejeff whatthejeff committed Feb 13, 2011
Showing with 215 additions and 33 deletions.
  1. +3 −33 PHPUnit/Util/PHP.php
  2. +97 −0 PHPUnit/Util/PHP/Default.php
  3. +107 −0 PHPUnit/Util/PHP/Windows.php
  4. +8 −0 package.xml
View
@@ -138,41 +138,11 @@ public static function getPhpBinary()
*/
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.'
- );
+ if (DIRECTORY_SEPARATOR == '\\') {
+ return PHPUnit_Util_PHP_Windows::runJob($job, $test, $result);
}
- $process = proc_open(
- self::getPhpBinary(), self::$descriptorSpec, $pipes
- );
-
- if (is_resource($process)) {
- if ($result !== NULL) {
- $result->startTest($test);
- }
-
- fwrite($pipes[0], "<?php require_once '" . addcslashes($file, "'") . "'; ?>");
- fclose($pipes[0]);
-
- $stdout = stream_get_contents($pipes[1]);
- fclose($pipes[1]);
-
- $stderr = stream_get_contents($pipes[2]);
- 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);
- }
+ return PHPUnit_Util_PHP_Default::runJob($job, $test, $result);
}
/**
@@ -0,0 +1,97 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2011, Sebastian Bergmann <sebastian@phpunit.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Sebastian Bergmann nor the names of his
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @package PHPUnit
+ * @subpackage Util
+ * @author Sebastian Bergmann <sebastian@phpunit.de>
+ * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @link http://www.phpunit.de/
+ * @since File available since Release 3.5.11
+ */
+
+/**
+ * Default utility for PHP sub-processes.
+ *
+ * @package PHPUnit
+ * @subpackage Util
+ * @author Sebastian Bergmann <sebastian@phpunit.de>
+ * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: @package_version@
+ * @link http://www.phpunit.de/
+ * @since Class available since Release 3.5.11
+ */
+class PHPUnit_Util_PHP_Default extends PHPUnit_Util_PHP
+{
+ /**
+ * Runs a single job (PHP code) using a separate PHP process.
+ *
+ * @param string $job
+ * @param PHPUnit_Framework_TestCase $test
+ * @param PHPUnit_Framework_TestResult $result
+ * @return array|null
+ */
+ public static function runJob($job, PHPUnit_Framework_Test $test = NULL, PHPUnit_Framework_TestResult $result = NULL)
+ {
+ $process = proc_open(
+ self::getPhpBinary(), self::$descriptorSpec, $pipes
+ );
+
+ if (is_resource($process)) {
+ if ($result !== NULL) {
+ $result->startTest($test);
+ }
+
+ fwrite($pipes[0], $job);
+ fclose($pipes[0]);
+
+ $stdout = stream_get_contents($pipes[1]);
+ fclose($pipes[1]);
+
+ $stderr = stream_get_contents($pipes[2]);
+ fclose($pipes[2]);
+
+ proc_close($process);
+
+ if ($result !== NULL) {
+ self::processChildResult($test, $result, $stdout, $stderr);
+ } else {
+ return array('stdout' => $stdout, 'stderr' => $stderr);
+ }
+ }
+ }
+}
@@ -0,0 +1,107 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2011, Sebastian Bergmann <sebastian@phpunit.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Sebastian Bergmann nor the names of his
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @package PHPUnit
+ * @subpackage Util
+ * @author Sebastian Bergmann <sebastian@phpunit.de>
+ * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @link http://www.phpunit.de/
+ * @since File available since Release 3.5.11
+ */
+
+/**
+ * Windows utility for PHP sub-processes.
+ *
+ * @package PHPUnit
+ * @subpackage Util
+ * @author Sebastian Bergmann <sebastian@phpunit.de>
+ * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: @package_version@
+ * @link http://www.phpunit.de/
+ * @since Class available since Release 3.5.11
+ */
+class PHPUnit_Util_PHP_Windows extends PHPUnit_Util_PHP
+{
+ /**
+ * Runs a single job (PHP code) using a separate PHP process.
+ *
+ * @param string $job
+ * @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
+ );
+
+ if (is_resource($process)) {
+ if ($result !== NULL) {
+ $result->startTest($test);
+ }
+
+ fwrite($pipes[0], "<?php require_once '" . addcslashes($file, "'") . "'; ?>");
+ fclose($pipes[0]);
+
+ $stdout = stream_get_contents($pipes[1]);
+ fclose($pipes[1]);
+
+ $stderr = stream_get_contents($pipes[2]);
+ 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);
+ }
+ }
+}
View
@@ -352,6 +352,14 @@
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
</dir>
+ <dir name="PHP">
+ <file baseinstalldir="/" name="Default.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
+ <file baseinstalldir="/" name="Windows.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
+ </dir>
<dir name="Skeleton">
<dir name="Template">
<file baseinstalldir="/" name="Class.tpl.dist" role="php">

0 comments on commit f4cc722

Please sign in to comment.