Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'issue_147' of git://github.com/whatthejeff/phpunit into…

… whatthejeff-issue_147
  • Loading branch information...
commit 54093c5f6a37e36c39b4b058dcc901ef8edc84e8 2 parents 3b8ae3e + e23d460
@sebastianbergmann authored
View
31 PHPUnit/Util/PHP.php
@@ -134,40 +134,15 @@ 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)
{
- $process = proc_open(
- self::getPhpBinary(), self::$descriptorSpec, $pipes
- );
-
- // Workaround for http://bugs.php.net/bug.php?id=52911
if (DIRECTORY_SEPARATOR == '\\') {
- sleep(2);
+ return PHPUnit_Util_PHP_Windows::runJob($job, $test, $result);
}
- 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);
- }
- }
+ return PHPUnit_Util_PHP_Default::runJob($job, $test, $result);
}
/**
View
97 PHPUnit/Util/PHP/Default.php
@@ -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);
+ }
+ }
+ }
+}
View
107 PHPUnit/Util/PHP/Windows.php
@@ -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
8 package.xml
@@ -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">
Please sign in to comment.
Something went wrong with that request. Please try again.