Skip to content

Commit 34b954a

Browse files
kabelsebastianbergmann
authored andcommitted
Clean up the php process command builder
* Gets rid of the need for eval-stdin.php in phpdbg with the s option * Only include the args separator when a file is not given
1 parent d4f9ac9 commit 34b954a

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/Util/PHP/AbstractPhpProcess.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,21 @@ public function getCommand(array $settings, string $file = null): string
180180
$command .= $this->settingsToParameters($settings);
181181

182182
if (\PHP_SAPI === 'phpdbg') {
183-
$command .= ' -qrr ';
183+
$command .= ' -qrr';
184184

185-
if ($file) {
186-
$command .= '-e ' . \escapeshellarg($file);
187-
} else {
188-
$command .= \escapeshellarg(__DIR__ . '/eval-stdin.php');
189-
}
190-
} else {
191-
if ($file) {
192-
$command .= ' -f ' . \escapeshellarg($file);
185+
if (!$file) {
186+
$command .= 's=';
193187
}
188+
}
194189

195-
if ($this->args) {
196-
$command .= ' --';
197-
}
190+
if ($file) {
191+
$command .= ' ' . \escapeshellarg($file);
198192
}
199193

200194
if ($this->args) {
195+
if (!$file) {
196+
$command .= ' --';
197+
}
201198
$command .= ' ' . $this->args;
202199
}
203200

tests/Util/PHP/AbstractPhpProcessTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public function testShouldUseArgsToCreateCommand(): void
8383

8484
public function testShouldHaveFileToCreateCommand(): void
8585
{
86-
$argumentEscapingCharacter = \DIRECTORY_SEPARATOR === '\\' ? '"' : '\'';
87-
$expectedCommandFormat = \sprintf('%%s -%%c %1$sfile.php%1$s', $argumentEscapingCharacter);
86+
$expectedCommandFormat = '%s %cfile.php%c';
8887
$actualCommand = $this->phpProcess->getCommand([], 'file.php');
8988

9089
$this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand);

0 commit comments

Comments
 (0)