Skip to content

Commit

Permalink
Use separated function to resolve command and related arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérémy JOURDIN authored and fabpot committed Sep 11, 2014
1 parent a45e3da commit ee75af0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Symfony/Component/Process/PhpExecutableFinder.php
Expand Up @@ -29,13 +29,15 @@ public function __construct()
/**
* Finds The PHP executable.
*
* @param bool $includeArgs Whether or not include command arguments
*
* @return string|false The PHP executable path or false if it cannot be found
*/
public function find()
public function find($includeArgs = true)
{
// HHVM support
if (defined('HHVM_VERSION')) {
return (false !== ($hhvm = getenv('PHP_BINARY')) ? $hhvm : PHP_BINARY).' --php';
return (false !== ($hhvm = getenv('PHP_BINARY')) ? $hhvm : PHP_BINARY).($includeArgs ? ' '.implode(' ', $this->findArguments()) : '');
}

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

return $this->executableFinder->find('php', false, $dirs);
}

/**
* Finds the PHP executable arguments.
*
* @return array The PHP executable arguments
*/
public function findArguments()
{
$arguments = array();

// HHVM support
if (defined('HHVM_VERSION')) {
$arguments[] = '--php';
}

return $arguments;
}
}
33 changes: 33 additions & 0 deletions src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php
Expand Up @@ -34,10 +34,43 @@ public function testFindWithPhpPath()
//not executable PHP_PATH
putenv('PHP_PATH=/not/executable/php');
$this->assertFalse($f->find(), '::find() returns false for not executable PHP');
$this->assertFalse($f->find(false), '::find() returns false for not executable PHP');

//executable PHP_PATH
putenv('PHP_PATH='.$current);
$this->assertEquals($f->find(), $current, '::find() returns the executable PHP');
$this->assertEquals($f->find(false), $current, '::find() returns the executable PHP');
}

/**
* tests find() with the env var PHP_PATH
*/
public function testFindWithHHVM()
{
if (!defined('HHVM_VERSION')) {
$this->markTestSkipped('Should be executed in HHVM context.');
}

$f = new PhpExecutableFinder();

$current = $f->find();

$this->assertEquals($f->find(), $current.' --php', '::find() returns the executable PHP');
$this->assertEquals($f->find(false), $current, '::find() returns the executable PHP');
}

/**
* tests find() with the env var PHP_PATH
*/
public function testFindArguments()
{
$f = new PhpExecutableFinder();

if (defined('HHVM_VERSION')) {
$this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
} else {
$this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
}
}

/**
Expand Down

0 comments on commit ee75af0

Please sign in to comment.