Skip to content

Commit

Permalink
Clean up the php process command builder
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kabel authored and sebastianbergmann committed Jul 9, 2018
1 parent d4f9ac9 commit 34b954a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
21 changes: 9 additions & 12 deletions src/Util/PHP/AbstractPhpProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,21 @@ public function getCommand(array $settings, string $file = null): string
$command .= $this->settingsToParameters($settings);

if (\PHP_SAPI === 'phpdbg') {
$command .= ' -qrr ';
$command .= ' -qrr';

if ($file) {
$command .= '-e ' . \escapeshellarg($file);
} else {
$command .= \escapeshellarg(__DIR__ . '/eval-stdin.php');
}
} else {
if ($file) {
$command .= ' -f ' . \escapeshellarg($file);
if (!$file) {
$command .= 's=';
}
}

if ($this->args) {
$command .= ' --';
}
if ($file) {
$command .= ' ' . \escapeshellarg($file);
}

if ($this->args) {
if (!$file) {
$command .= ' --';
}
$command .= ' ' . $this->args;
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Util/PHP/AbstractPhpProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public function testShouldUseArgsToCreateCommand(): void

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

$this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand);
Expand Down

0 comments on commit 34b954a

Please sign in to comment.