5
* Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* * Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* * Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in
17
* the documentation and/or other materials provided with the
20
* * Neither the name of Sebastian Bergmann nor the names of his
21
* contributors may be used to endorse or promote products derived
22
* from this software without specific prior written permission.
24
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
* POSSIBILITY OF SUCH DAMAGE.
39
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
40
* @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
41
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
42
* @link http://www.phpunit.de/
43
* @since File available since Release 3.4.0
46
require_once 'PHPUnit/Util/Filter.php';
48
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
51
* Utility methods for PHP sub-processes.
55
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
56
* @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
57
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
58
* @version Release: @package_version@
59
* @link http://www.phpunit.de/
60
* @since Class available since Release 3.4.0
62
class PHPUnit_Util_PHP
65
* Path to the PHP interpreter that is to be used.
67
* @var string $phpBinary
69
protected static $phpBinary = NULL;
72
* Descriptor specification for proc_open().
76
protected static $descriptorSpec = array(
77
0 => array('pipe', 'r'),
78
1 => array('pipe', 'w'),
79
2 => array('pipe', 'w')
83
* Returns the path to a PHP interpreter.
85
* PHPUnit_Util_PHP::$phpBinary contains the path to the PHP
88
* When not set, the following assumptions will be made:
90
* 1. When the PHP CLI/CGI binary configured with the PEAR Installer
91
* (php_bin configuration value) is readable, it will be used.
93
* 2. When PHPUnit is run using the CLI SAPI and the $_SERVER['_']
94
* variable does not contain the string "PHPUnit", $_SERVER['_']
95
* is assumed to contain the path to the current PHP interpreter
96
* and that will be used.
98
* 3. When PHPUnit is run using the CLI SAPI and the $_SERVER['_']
99
* variable contains the string "PHPUnit", the file that $_SERVER['_']
100
* points to is assumed to be the PHPUnit TextUI CLI wrapper script
101
* "phpunit" and the binary set up using #! on that file's first
102
* line of code is assumed to contain the path to the current PHP
103
* interpreter and that will be used.
105
* 4. The current PHP interpreter is assumed to be in the $PATH and
106
* to be invokable through "php".
110
public static function getPhpBinary()
112
if (self::$phpBinary === NULL) {
113
if (is_readable('@php_bin@')) {
114
self::$phpBinary = '@php_bin@';
117
else if (PHP_SAPI == 'cli' && isset($_SERVER['_']) &&
118
strpos($_SERVER['_'], 'phpunit') !== FALSE) {
119
$file = file($_SERVER['_']);
120
$tmp = explode(' ', $file[0]);
121
self::$phpBinary = trim($tmp[1]);
124
if (!is_readable(self::$phpBinary)) {
125
self::$phpBinary = 'php';
127
self::$phpBinary = escapeshellarg(self::$phpBinary);
131
return self::$phpBinary;
135
* Runs a single job (PHP code) using a separate PHP process.
140
public static function runJob($job)
142
$process = proc_open(
143
self::getPhpBinary(), self::$descriptorSpec, $pipes
146
if (is_resource($process)) {
147
fwrite($pipes[0], $job);
150
$stdout = stream_get_contents($pipes[1]);
153
$stderr = stream_get_contents($pipes[2]);
156
proc_close($process);
158
return array('stdout' => $stdout, 'stderr' => $stderr);
b'\\ No newline at end of file'