Skip to content

Commit 0f6a62b

Browse files
Merge branch '11.0'
2 parents b4a4693 + b7fda56 commit 0f6a62b

File tree

3 files changed

+31
-66
lines changed

3 files changed

+31
-66
lines changed

src/Util/PHP/AbstractPhpProcess.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
*/
1010
namespace PHPUnit\Util\PHP;
1111

12+
use const PHP_BINARY;
1213
use const PHP_SAPI;
1314
use function array_keys;
1415
use function array_merge;
1516
use function assert;
16-
use function escapeshellarg;
17+
use function explode;
1718
use function file_exists;
1819
use function file_get_contents;
1920
use function ini_get_all;
@@ -154,12 +155,15 @@ public function runTestJob(string $job, Test $test, string $processResultFile):
154155

155156
/**
156157
* Returns the command based into the configurations.
158+
*
159+
* @return string[]
157160
*/
158-
public function getCommand(array $settings, ?string $file = null): string
161+
public function getCommand(array $settings, ?string $file = null): array
159162
{
160163
$runtime = new Runtime;
161164

162-
$command = $runtime->getBinary();
165+
$command = [];
166+
$command[] = PHP_BINARY;
163167

164168
if ($runtime->hasPCOV()) {
165169
$settings = array_merge(
@@ -177,29 +181,29 @@ public function getCommand(array $settings, ?string $file = null): string
177181
);
178182
}
179183

180-
$command .= $this->settingsToParameters($settings);
184+
$command = array_merge($command, $this->settingsToParameters($settings));
181185

182186
if (PHP_SAPI === 'phpdbg') {
183-
$command .= ' -qrr';
187+
$command[] = '-qrr';
184188

185189
if (!$file) {
186-
$command .= 's=';
190+
$command[] = 's=';
187191
}
188192
}
189193

190194
if ($file) {
191-
$command .= ' ' . escapeshellarg($file);
195+
$command[] = '-f';
196+
$command[] = $file;
192197
}
193198

194199
if ($this->arguments) {
195200
if (!$file) {
196-
$command .= ' --';
201+
$command[] = '--';
197202
}
198-
$command .= ' ' . $this->arguments;
199-
}
200203

201-
if ($this->stderrRedirection) {
202-
$command .= ' 2>&1';
204+
foreach (explode(' ', $this->arguments) as $arg) {
205+
$command[] = trim($arg);
206+
}
203207
}
204208

205209
return $command;
@@ -210,12 +214,16 @@ public function getCommand(array $settings, ?string $file = null): string
210214
*/
211215
abstract public function runJob(string $job, array $settings = []): array;
212216

213-
protected function settingsToParameters(array $settings): string
217+
/**
218+
* @return list<string>
219+
*/
220+
protected function settingsToParameters(array $settings): array
214221
{
215-
$buffer = '';
222+
$buffer = [];
216223

217224
foreach ($settings as $setting) {
218-
$buffer .= ' -d ' . escapeshellarg($setting);
225+
$buffer[] = '-d';
226+
$buffer[] = $setting;
219227
}
220228

221229
return $buffer;

src/Util/PHP/DefaultPhpProcess.php

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use function is_resource;
1818
use function proc_close;
1919
use function proc_open;
20-
use function rewind;
2120
use function stream_get_contents;
2221
use function sys_get_temp_dir;
2322
use function tempnam;
@@ -55,14 +54,6 @@ public function runJob(string $job, array $settings = []): array
5554
return $this->runProcess($job, $settings);
5655
}
5756

58-
/**
59-
* Returns an array of file handles to be used in place of pipes.
60-
*/
61-
protected function getHandles(): array
62-
{
63-
return [];
64-
}
65-
6657
/**
6758
* Handles creating the child process and returning the STDOUT and STDERR.
6859
*
@@ -73,8 +64,6 @@ protected function getHandles(): array
7364
*/
7465
protected function runProcess(string $job, array $settings): array
7566
{
76-
$handles = $this->getHandles();
77-
7867
$env = null;
7968

8069
if ($this->env) {
@@ -90,11 +79,15 @@ protected function runProcess(string $job, array $settings): array
9079
}
9180

9281
$pipeSpec = [
93-
0 => $handles[0] ?? ['pipe', 'r'],
94-
1 => $handles[1] ?? ['pipe', 'w'],
95-
2 => $handles[2] ?? ['pipe', 'w'],
82+
0 => ['pipe', 'r'],
83+
1 => ['pipe', 'w'],
84+
2 => ['pipe', 'w'],
9685
];
9786

87+
if ($this->stderrRedirection) {
88+
$pipeSpec[2] = ['redirect', 1];
89+
}
90+
9891
$process = proc_open(
9992
$this->getCommand($settings, $this->tempFile),
10093
$pipeSpec,
@@ -129,22 +122,6 @@ protected function runProcess(string $job, array $settings): array
129122
fclose($pipes[2]);
130123
}
131124

132-
if (isset($handles[1])) {
133-
rewind($handles[1]);
134-
135-
$stdout = stream_get_contents($handles[1]);
136-
137-
fclose($handles[1]);
138-
}
139-
140-
if (isset($handles[2])) {
141-
rewind($handles[2]);
142-
143-
$stderr = stream_get_contents($handles[2]);
144-
145-
fclose($handles[2]);
146-
}
147-
148125
proc_close($process);
149126

150127
$this->cleanup();

src/Util/PHP/WindowsPhpProcess.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,15 @@
99
*/
1010
namespace PHPUnit\Util\PHP;
1111

12-
use function tmpfile;
13-
use PHPUnit\Framework\Exception;
14-
1512
/**
1613
* @internal This class is not covered by the backward compatibility promise for PHPUnit
1714
*
1815
* @see https://bugs.php.net/bug.php?id=51800
1916
*/
2017
final class WindowsPhpProcess extends DefaultPhpProcess
2118
{
22-
/**
23-
* @throws Exception
24-
* @throws PhpProcessException
25-
*/
26-
protected function getHandles(): array
27-
{
28-
if (false === $stdout_handle = tmpfile()) {
29-
throw new PhpProcessException(
30-
'A temporary file could not be created; verify that your TEMP environment variable is writable',
31-
);
32-
}
33-
34-
return [
35-
1 => $stdout_handle,
36-
];
37-
}
38-
3919
protected function useTemporaryFile(): bool
4020
{
41-
return true;
21+
return false;
4222
}
4323
}

0 commit comments

Comments
 (0)