3
* This file is part of PHPUnit.
5
* (c) Sebastian Bergmann <sebastian@phpunit.de>
7
* For the full copyright and license information, please view the LICENSE
8
* file that was distributed with this source code.
11
use SebastianBergmann\Environment\Runtime;
14
* Windows utility for PHP sub-processes.
18
* @author Sebastian Bergmann <sebastian@phpunit.de>
19
* @copyright Sebastian Bergmann <sebastian@phpunit.de>
20
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
21
* @link http://www.phpunit.de/
22
* @since Class available since Release 3.5.12
24
class PHPUnit_Util_PHP_Windows extends PHPUnit_Util_PHP_Default
34
* Reading from STDOUT or STDERR hangs forever on Windows if the output is
37
* @see https://bugs.php.net/bug.php?id=51800
39
public function runJob($job, array $settings = array())
41
$runtime = new Runtime;
43
if (false === $stdout_handle = tmpfile()) {
44
throw new PHPUnit_Framework_Exception(
45
'A temporary file could not be created; verify that your TEMP environment variable is writable'
50
$runtime->getBinary() . $this->settingsToParameters($settings),
52
0 => array('pipe', 'r'),
54
2 => array('pipe', 'w')
59
if (!is_resource($process)) {
60
throw new PHPUnit_Framework_Exception(
61
'Unable to spawn worker process'
65
$this->process($pipes[0], $job);
68
$stderr = stream_get_contents($pipes[2]);
73
rewind($stdout_handle);
74
$stdout = stream_get_contents($stdout_handle);
75
fclose($stdout_handle);
79
return array('stdout' => $stdout, 'stderr' => $stderr);
83
* @param resource $pipe
85
* @throws PHPUnit_Framework_Exception
86
* @since Method available since Release 3.5.12
88
protected function process($pipe, $job)
90
if (!($this->tempFile = tempnam(sys_get_temp_dir(), 'PHPUnit')) ||
91
file_put_contents($this->tempFile, $job) === false) {
92
throw new PHPUnit_Framework_Exception(
93
'Unable to write temporary file'
99
"<?php require_once " . var_export($this->tempFile, true) . "; ?>"
104
* @since Method available since Release 3.5.12
106
protected function cleanup()
108
unlink($this->tempFile);