From ee75af0c8993a3c28c653c036ac55ae5d6ab8c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20JOURDIN?= Date: Mon, 28 Jul 2014 15:26:43 +0200 Subject: [PATCH] Use separated function to resolve command and related arguments --- .../Component/Process/PhpExecutableFinder.php | 23 +++++++++++-- .../Process/Tests/PhpExecutableFinderTest.php | 33 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Process/PhpExecutableFinder.php b/src/Symfony/Component/Process/PhpExecutableFinder.php index cda86995a481..7854487a26b2 100644 --- a/src/Symfony/Component/Process/PhpExecutableFinder.php +++ b/src/Symfony/Component/Process/PhpExecutableFinder.php @@ -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 @@ -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; + } } diff --git a/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php b/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php index df48c4f556c2..e16f3f8bed14 100644 --- a/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php +++ b/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php @@ -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'); + } } /**