13
13
use function array_keys ;
14
14
use function array_merge ;
15
15
use function assert ;
16
- use function escapeshellarg ;
16
+ use function explode ;
17
17
use function file_exists ;
18
18
use function file_get_contents ;
19
19
use function ini_get_all ;
@@ -156,12 +156,15 @@ public function runTestJob(string $job, Test $test, string $processResultFile):
156
156
157
157
/**
158
158
* Returns the command based into the configurations.
159
+ *
160
+ * @return string[]
159
161
*/
160
- public function getCommand (array $ settings , ?string $ file = null ): string
162
+ public function getCommand (array $ settings , ?string $ file = null ): array
161
163
{
162
164
$ runtime = new Runtime ;
163
165
164
- $ command = $ runtime ->getBinary ();
166
+ $ command = [];
167
+ $ command [] = $ runtime ->getRawBinary ();
165
168
166
169
if ($ runtime ->hasPCOV ()) {
167
170
$ settings = array_merge (
@@ -179,29 +182,29 @@ public function getCommand(array $settings, ?string $file = null): string
179
182
);
180
183
}
181
184
182
- $ command .= $ this ->settingsToParameters ($ settings );
185
+ $ command = array_merge ( $ command , $ this ->settingsToParameters ($ settings) );
183
186
184
187
if (PHP_SAPI === 'phpdbg ' ) {
185
- $ command . = ' -qrr ' ;
188
+ $ command[] = '-qrr ' ;
186
189
187
190
if (!$ file ) {
188
- $ command . = 's= ' ;
191
+ $ command[] = 's= ' ;
189
192
}
190
193
}
191
194
192
195
if ($ file ) {
193
- $ command .= ' ' . escapeshellarg ($ file );
196
+ $ command [] = '-f ' ;
197
+ $ command [] = $ file ;
194
198
}
195
199
196
200
if ($ this ->arguments ) {
197
201
if (!$ file ) {
198
- $ command . = ' -- ' ;
202
+ $ command[] = '-- ' ;
199
203
}
200
- $ command .= ' ' . $ this ->arguments ;
201
- }
202
204
203
- if ($ this ->stderrRedirection ) {
204
- $ command .= ' 2>&1 ' ;
205
+ foreach (explode (' ' , $ this ->arguments ) as $ arg ) {
206
+ $ command [] = trim ($ arg );
207
+ }
205
208
}
206
209
207
210
return $ command ;
@@ -212,12 +215,16 @@ public function getCommand(array $settings, ?string $file = null): string
212
215
*/
213
216
abstract public function runJob (string $ job , array $ settings = []): array ;
214
217
215
- protected function settingsToParameters (array $ settings ): string
218
+ /**
219
+ * @return list<string>
220
+ */
221
+ protected function settingsToParameters (array $ settings ): array
216
222
{
217
- $ buffer = '' ;
223
+ $ buffer = [] ;
218
224
219
225
foreach ($ settings as $ setting ) {
220
- $ buffer .= ' -d ' . escapeshellarg ($ setting );
226
+ $ buffer [] = '-d ' ;
227
+ $ buffer [] = $ setting ;
221
228
}
222
229
223
230
return $ buffer ;
0 commit comments