Skip to content

Commit

Permalink
bug #30511 [Process] fix using argument $php of new PhpProcess() (nic…
Browse files Browse the repository at this point in the history
…olas-grekas)

This PR was merged into the 4.2 branch.

Discussion
----------

[Process] fix using argument $php of new PhpProcess()

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

The current logic makes no sense. 3.4 is fine.

Commits
-------

aa6e585 [Process] fix using argument $php of new PhpProcess()
  • Loading branch information
fabpot committed Mar 11, 2019
2 parents 33b881b + aa6e585 commit 00fe6e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Symfony/Component/Process/PhpProcess.php
Expand Up @@ -33,11 +33,10 @@ class PhpProcess extends Process
*/
public function __construct(string $script, string $cwd = null, array $env = null, int $timeout = 60, array $php = null)
{
$executableFinder = new PhpExecutableFinder();
if (false === $php = $php ?? $executableFinder->find(false)) {
$php = null;
} else {
$php = array_merge([$php], $executableFinder->findArguments());
if (null === $php) {
$executableFinder = new PhpExecutableFinder();
$php = $executableFinder->find(false);
$php = false === $php ? null : array_merge([$php], $executableFinder->findArguments());
}
if ('phpdbg' === \PHP_SAPI) {
$file = tempnam(sys_get_temp_dir(), 'dbg');
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Process/Tests/PhpProcessTest.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Process\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\PhpProcess;

class PhpProcessTest extends TestCase
Expand Down Expand Up @@ -45,4 +46,18 @@ public function testCommandLine()

$this->assertSame(PHP_VERSION.\PHP_SAPI, $process->getOutput());
}

public function testPassingPhpExplicitly()
{
$finder = new PhpExecutableFinder();
$php = array_merge([$finder->find(false)], $finder->findArguments());

$expected = 'hello world!';
$script = <<<PHP
<?php echo '$expected';
PHP;
$process = new PhpProcess($script, null, null, 60, $php);
$process->run();
$this->assertEquals($expected, $process->getOutput());
}
}

0 comments on commit 00fe6e6

Please sign in to comment.