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.
16 * @since Class available since Release 3.5.12
18 class PHPUnit_Util_PHP_Windows extends PHPUnit_Util_PHP_Default
28 * Reading from STDOUT or STDERR hangs forever on Windows if the output is
31 * @see https://bugs.php.net/bug.php?id=51800
33 public function runJob($job, array $settings = array())
35 $runtime = new Runtime;
37 if (false === $stdout_handle = tmpfile()) {
38 throw new PHPUnit_Framework_Exception(
39 'A temporary file could not be created; verify that your TEMP environment variable is writable'
44 $runtime->getBinary() . $this->settingsToParameters($settings),
46 0 => array('pipe', 'r'),
48 2 => array('pipe', 'w')
53 if (!is_resource($process)) {
54 throw new PHPUnit_Framework_Exception(
55 'Unable to spawn worker process'
59 $this->process($pipes[0], $job);
62 $stderr = stream_get_contents($pipes[2]);
67 rewind($stdout_handle);
68 $stdout = stream_get_contents($stdout_handle);
69 fclose($stdout_handle);
73 return array('stdout' => $stdout, 'stderr' => $stderr);
77 * @param resource $pipe
80 * @throws PHPUnit_Framework_Exception
82 * @since Method available since Release 3.5.12
84 protected function process($pipe, $job)
86 if (!($this->tempFile = tempnam(sys_get_temp_dir(), 'PHPUnit')) ||
87 file_put_contents($this->tempFile, $job) === false) {
88 throw new PHPUnit_Framework_Exception(
89 'Unable to write temporary file'
95 '<?php require_once ' . var_export($this->tempFile, true) . '; ?>'
100 * @since Method available since Release 3.5.12
102 protected function cleanup()
104 unlink($this->tempFile);