From 1de29b9a7b5d087cbc434dccc7dc8e2f82adfcbd Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 23 Apr 2013 22:53:10 +0200 Subject: [PATCH] [Process] Do not throw LogicException in ProcessBuilder::getProcess if no arguments are set but a prefix is --- .../Component/Process/ProcessBuilder.php | 2 +- .../Process/Tests/ProcessBuilderTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Process/ProcessBuilder.php b/src/Symfony/Component/Process/ProcessBuilder.php index 1a7e579e386c..ddd064a2b877 100644 --- a/src/Symfony/Component/Process/ProcessBuilder.php +++ b/src/Symfony/Component/Process/ProcessBuilder.php @@ -154,7 +154,7 @@ public function setOption($name, $value) public function getProcess() { - if (!count($this->arguments)) { + if (!$this->prefix && !count($this->arguments)) { throw new LogicException('You must add() command arguments before calling getProcess().'); } diff --git a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php index 6db0799d385d..eea028a40680 100644 --- a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php @@ -152,4 +152,29 @@ public function testShouldEscapeArgumentsAndPrefix() $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()); + } }