[2.3][Process] Fixed PhpProcess::getCommandLine() result

This commit is contained in:
Francis Besset 2015-02-18 15:48:31 +01:00 committed by Fabien Potencier
parent e759bc3836
commit d0f1d3236c
2 changed files with 26 additions and 8 deletions

View File

@ -26,8 +26,6 @@ use Symfony\Component\Process\Exception\RuntimeException;
*/
class PhpProcess extends Process
{
private $executableFinder;
/**
* Constructor.
*
@ -41,9 +39,12 @@ class PhpProcess extends Process
*/
public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array())
{
parent::__construct(null, $cwd, $env, $script, $timeout, $options);
$executableFinder = new PhpExecutableFinder();
if (false === $php = $executableFinder->find()) {
$php = null;
}
$this->executableFinder = new PhpExecutableFinder();
parent::__construct($php, $cwd, $env, $script, $timeout, $options);
}
/**
@ -62,10 +63,7 @@ class PhpProcess extends Process
public function start($callback = null)
{
if (null === $this->getCommandLine()) {
if (false === $php = $this->executableFinder->find()) {
throw new RuntimeException('Unable to find the PHP executable.');
}
$this->setCommandLine($php);
throw new RuntimeException('Unable to find the PHP executable.');
}
parent::start($callback);

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Process\Tests;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\PhpProcess;
class PhpProcessTest extends \PHPUnit_Framework_TestCase
@ -26,4 +27,23 @@ PHP
$process->wait();
$this->assertEquals($expected, $process->getOutput());
}
public function testCommandLine()
{
$process = new PhpProcess(<<<PHP
<?php echo 'foobar';
PHP
);
$f = new PhpExecutableFinder();
$commandLine = $f->find();
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP before start');
$process->start();
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
$process->wait();
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
}
}