10000 bug #11497 Use separated function to resolve command and related argu… · symfony/symfony@b33d637 · GitHub
[go: up one dir, main page]

Skip to content

Commit b33d637

Browse files
committed
bug #11497 Use separated function to resolve command and related arguments (JJK801)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11497). Discussion ---------- Use separated function to resolve command and related arguments Hi, This PR split command and related arguments resolution into two distinct functions. It will help to solve the HHVM issue sensiolabs/SensioDistributionBundle#150 . Thanks, Jérémy | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ Commits ------- ee75af0 Use separated function to resolve command and related arguments
2 parents a45e3da + ee75af0 commit b33d637

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/Symfony/Component/Process/PhpExecutableFinder.php

Lines changed: 21 additions & 2 deletions
71
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ public function __construct()
2929
/**
3030
* Finds The PHP executable.
3131
*
32+
* @param bool $includeArgs Whether or not include command arguments
33+
*
3234
* @return string|false The PHP executable path or false if it cannot be found
3335
*/
34-
public function find()
36+
public function find($includeArgs = true)
3537
{
3638
// HHVM support
3739
if (defined('HHVM_VERSION')) {
38-
return (false !== ($hhvm = getenv('PHP_BINARY')) ? $hhvm : PHP_BINARY).' --php';
40+
return (false !== ($hhvm = getenv('PHP_BINARY')) ? $hhvm : PHP_BINARY).($includeArgs ? ' '.implode(' ', $this->findArguments()) : '');
3941
}
4042

4143
// PHP_BINARY return the current sapi executable
@@ -64,4 +66,21 @@ public function find()
6466

6567
return $this->executableFinder->find('php', false, $dirs);
6668
}
69+
70+
/**
+
* Finds the PHP executable arguments.
72+
*
73+
* @return array The PHP executable arguments
74+
*/
75+
public function findArguments()
76+
{
77+
$arguments = array();
78+
79+
// HHVM support
80+
if (defined('HHVM_VERSION')) {
81+
$arguments[] = '--php';
82+
}
83+
84+
return $arguments;
85+
}
6786
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,43 @@ public function testFindWithPhpPath()
3434
//not executable PHP_PATH
3535
putenv('PHP_PATH=/not/executable/php');
3636
$this->assertFalse($f->find(), '::find() returns false for not executable PHP');
37+
$this->assertFalse($f->find(false), '::find() returns false for not executable PHP');
3738

3839
//executable PHP_PATH
3940
putenv('PHP_PATH='.$current);
4041
$this->assertEquals($f->find(), $current, '::find() returns the executable PHP');
42+
$this->assertEquals($f->find(false), $current, '::find() returns the executable PHP');
43+
}
44+
45+
/**
46+
* tests find() with the env var PHP_PATH
47+
*/
48+
public function testFindWithHHVM()
49+
{
50+
if (!defined('HHVM_VERSION')) {
51+
$this->markTestSkipped('Should be executed in HHVM context.');
52+
}
53+
54+
$f = new PhpExecutableFinder();
55+
56+
$current = $f->find();
57+
58+
$this->assertEquals($f->find(), $current.' --php', '::find() returns the executable PHP');
59+
$this->assertEquals($f->find(false), $current, '::find() returns the executable PHP');
60+
}
61+
62+
/**
63+
* tests find() with the env var PHP_PATH
64+
*/
65+
public function testFindArguments()
66+
{
67+
$f = new PhpExecutableFinder();
68+
69+
if (defined('HHVM_VERSION')) {
70+
$this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
71+
} else {
72+
$this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
73+
}
4174
}
4275

4376
/**

0 commit comments

Comments
 (0)
0