8000 [Process] fix using argument $php of new PhpProcess() · symfony/symfony@aa6e585 · GitHub
[go: up one dir, main page]

Skip to content

Commit aa6e585

Browse files
[Process] fix using argument $php of new PhpProcess()
1 parent 33b881b commit aa6e585

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Symfony/Component/Process/PhpProcess.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ class PhpProcess extends Process
3333
*/
3434
public function __construct(string $script, string $cwd = null, array $env = null, int $timeout = 60, array $php = null)
3535
{
36-
$executableFinder = new PhpExecutableFinder();
37-
if (false === $php = $php ?? $executableFinder->find(false)) {
38-
$php = null;
39-
} else {
40-
$php = array_merge([$php], $executableFinder->findArguments());
36+
if (null === $php) {
37+
$executableFinder = new PhpExecutableFinder();
38+
$php = $executableFinder->find(false);
39+
$php = false === $php ? null : array_merge([$php], $executableFinder->findArguments());
4140
}
4241
if ('phpdbg' === \PHP_SAPI) {
4342
$file = tempnam(sys_get_temp_dir(), 'dbg');

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Process\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Process\PhpExecutableFinder;
1516
use Symfony\Component\Process\PhpProcess;
1617

1718
class PhpProcessTest extends TestCase
@@ -45,4 +46,18 @@ public function testCommandLine()
4546

4647
$this->assertSame(PHP_VERSION.\PHP_SAPI, $process->getOutput());
4748
}
49+
50+
public function testPassingPhpExplicitly()
51+
{
52+
$finder = new PhpExecutableFinder();
53+
$php = array_merge([$finder->find(false)], $finder->findArguments());
54+
55+
$expected = 'hello world!';
56+
$script = <<<PHP
57+
<?php echo '$expected';
58+
PHP;
59+
$process = new PhpProcess($script, null, null, 60, $php);
60+
$process->run();
61+
$this->assertEquals($expected, $process->getOutput());
62+
}
4863
}

0 commit comments

Comments
 (0)
0