Skip to content

Commit d0f1d32

Browse files
francisbessetfabpot
authored andcommitted
[2.3][Process] Fixed PhpProcess::getCommandLine() result
1 parent e759bc3 commit d0f1d32

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/Symfony/Component/Process/PhpProcess.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
*/
2727
class PhpProcess extends Process
2828
{
29-
private $executableFinder;
30-
3129
/**
3230
* Constructor.
3331
*
@@ -41,9 +39,12 @@ class PhpProcess extends Process
4139
*/
4240
public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array())
4341
{
44-
parent::__construct(null, $cwd, $env, $script, $timeout, $options);
42+
$executableFinder = new PhpExecutableFinder();
43+
if (false === $php = $executableFinder->find()) {
44+
$php = null;
45+
}
4546

46-
$this->executableFinder = new PhpExecutableFinder();
47+
parent::__construct($php, $cwd, $env, $script, $timeout, $options);
4748
}
4849

4950
/**
@@ -62,10 +63,7 @@ public function setPhpBinary($php)
6263
public function start($callback = null)
6364
{
6465
if (null === $this->getCommandLine()) {
65-
if (false === $php = $this->executableFinder->find()) {
66-
throw new RuntimeException('Unable to find the PHP executable.');
67-
}
68-
$this->setCommandLine($php);
66+
throw new RuntimeException('Unable to find the PHP executable.');
6967
}
7068

7169
parent::start($callback);

src/Symfony/Component/Process/Tests/PhpProcessTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Process\Tests;
1313

14+
use Symfony\Component\Process\PhpExecutableFinder;
1415
use Symfony\Component\Process\PhpProcess;
1516

1617
class PhpProcessTest extends \PHPUnit_Framework_TestCase
@@ -26,4 +27,23 @@ public function testNonBlockingWorks()
2627
$process->wait();
2728
$this->assertEquals($expected, $process->getOutput());
2829
}
30+
31+
public function testCommandLine()
32+
{
33+
$process = new PhpProcess(<<<PHP
34+
<?php echo 'foobar';
35+
PHP
36+
);
37+
38+
$f = new PhpExecutableFinder();
39+
$commandLine = $f->find();
40+
41+
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP before start');
42+
43+
$process->start();
44+
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
45+
46+
$process->wait();
47+
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
48+
}
2949
}

0 commit comments

Comments
 (0)