Use separated function to resolve command and related arguments

This commit is contained in:
Jérémy JOURDIN 2014-07-28 15:26:43 +02:00 committed by Fabien Potencier
parent a45e3da3e4
commit ee75af0c89
2 changed files with 54 additions and 2 deletions

View File

@ -29,13 +29,15 @@ class PhpExecutableFinder
/**
* 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
@ -64,4 +66,21 @@ class PhpExecutableFinder
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;
}
}

View File

@ -34,10 +34,43 @@ class PhpExecutableFinderTest extends \PHPUnit_Framework_TestCase
//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');
}
}
/**