merged branch romainneutron/process-builder (PR #7821)
This PR was merged into the master branch. Discussion ---------- [Process] Fix two process-builder minor bugs | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT Everything is in the commit messages : - Use new ProcessUtils::escapeArgument to escape ProcessBuillder prefix - Do not throw LogicException in ProcessBuilder::getProcess if no arguments are set but a prefix is Commits -------1de29b9
[Process] Do not throw LogicException in ProcessBuilder::getProcess if no arguments are set but a prefix is209799b
[Process] Use new ProcessUtils::escapeArgument to escape ProcessBuilder prefix
This commit is contained in:
commit
ae88c02236
|
@ -154,14 +154,14 @@ class ProcessBuilder
|
|||
|
||||
public function getProcess()
|
||||
{
|
||||
if (!count($this->arguments)) {
|
||||
if (!$this->prefix && !count($this->arguments)) {
|
||||
throw new LogicException('You must add() command arguments before calling getProcess().');
|
||||
}
|
||||
|
||||
$options = $this->options;
|
||||
|
||||
$script = ($this->prefix ? escapeshellarg($this->prefix) . ' ' : '')
|
||||
.implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $this->arguments));
|
||||
$arguments = $this->prefix ? array_merge(array($this->prefix), $this->arguments) : $this->arguments;
|
||||
$script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));
|
||||
|
||||
if ($this->inheritEnv) {
|
||||
$env = $this->env ? $this->env + $_ENV : null;
|
||||
|
|
|
@ -139,4 +139,42 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertSame("'%path%' 'foo \" bar'", $proc->getCommandLine());
|
||||
}
|
||||
}
|
||||
|
||||
public function testShouldEscapeArgumentsAndPrefix()
|
||||
{
|
||||
$pb = new ProcessBuilder(array('arg'));
|
||||
$pb->setPrefix('%prefix%');
|
||||
$proc = $pb->getProcess();
|
||||
|
||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||
$this->assertSame('^%"prefix"^% "arg"', $proc->getCommandLine());
|
||||
} else {
|
||||
$this->assertSame("'%prefix%' 'arg'", $proc->getCommandLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Process\Exception\LogicException
|
||||
*/
|
||||
public function testShouldThrowALogicExceptionIfNoPrefixAndNoArgument()
|
||||
{
|
||||
ProcessBuilder::create()->getProcess();
|
||||
}
|
||||
|
||||
public function testShouldNotThrowALogicExceptionIfNoArgument()
|
||||
{
|
||||
$process = ProcessBuilder::create()
|
||||
->setPrefix('/usr/bin/php')
|
||||
->getProcess();
|
||||
|
||||
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
|
||||
}
|
||||
|
||||
public function testShouldNotThrowALogicExceptionIfNoPrefix()
|
||||
{
|
||||
$process = ProcessBuilder::create(array('/usr/bin/php'))
|
||||
->getProcess();
|
||||
|
||||
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue