4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Process\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Process\PhpExecutableFinder;
18 * @author Robert Schönthal <seroscho@googlemail.com>
20 class PhpExecutableFinderTest extends TestCase
23 * tests find() with the env var PHP_PATH.
25 public function testFindWithPhpPath()
27 if (defined('PHP_BINARY')) {
28 $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
31 $f = new PhpExecutableFinder();
33 $current = $f->find();
35 //not executable PHP_PATH
36 putenv('PHP_PATH=/not/executable/php');
37 $this->assertFalse($f->find(), '::find() returns false for not executable PHP');
38 $this->assertFalse($f->find(false), '::find() returns false for not executable PHP');
41 putenv('PHP_PATH='.$current);
42 $this->assertEquals($f->find(), $current, '::find() returns the executable PHP');
43 $this->assertEquals($f->find(false), $current, '::find() returns the executable PHP');
47 * tests find() with the constant PHP_BINARY.
51 public function testFind()
53 if (defined('HHVM_VERSION')) {
54 $this->markTestSkipped('Should not be executed in HHVM context.');
57 $f = new PhpExecutableFinder();
59 $current = PHP_BINARY;
60 $args = 'phpdbg' === PHP_SAPI ? ' -qrr' : '';
62 $this->assertEquals($current.$args, $f->find(), '::find() returns the executable PHP');
63 $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
67 * tests find() with the env var / constant PHP_BINARY with HHVM.
69 public function testFindWithHHVM()
71 if (!defined('HHVM_VERSION')) {
72 $this->markTestSkipped('Should be executed in HHVM context.');
75 $f = new PhpExecutableFinder();
77 $current = getenv('PHP_BINARY') ?: PHP_BINARY;
79 $this->assertEquals($current.' --php', $f->find(), '::find() returns the executable PHP');
80 $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
84 * tests find() with the env var PHP_PATH.
86 public function testFindArguments()
88 $f = new PhpExecutableFinder();
90 if (defined('HHVM_VERSION')) {
91 $this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
92 } elseif ('phpdbg' === PHP_SAPI) {
93 $this->assertEquals($f->findArguments(), array('-qrr'), '::findArguments() returns phpdbg arguments');
95 $this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
100 * tests find() with default executable.
102 public function testFindWithSuffix()
104 if (defined('PHP_BINARY')) {
105 $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
109 putenv('PHP_PEAR_PHP_BIN=');
110 $f = new PhpExecutableFinder();
112 $current = $f->find();
114 //TODO maybe php executable is custom or even Windows
115 if ('\\' === DIRECTORY_SEPARATOR) {
116 $this->assertTrue(is_executable($current));
117 $this->assertTrue((bool) preg_match('/'.addslashes(DIRECTORY_SEPARATOR).'php\.(exe|bat|cmd|com)$/i', $current), '::find() returns the executable PHP with suffixes');