1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Component\Process\Tests; 13 14use PHPUnit\Framework\TestCase; 15use Symfony\Component\Process\PhpExecutableFinder; 16 17/** 18 * @author Robert Schönthal <seroscho@googlemail.com> 19 */ 20class PhpExecutableFinderTest extends TestCase 21{ 22 /** 23 * tests find() with the constant PHP_BINARY. 24 */ 25 public function testFind() 26 { 27 if (\defined('HHVM_VERSION')) { 28 $this->markTestSkipped('Should not be executed in HHVM context.'); 29 } 30 31 $f = new PhpExecutableFinder(); 32 33 $current = \PHP_BINARY; 34 $args = 'phpdbg' === \PHP_SAPI ? ' -qrr' : ''; 35 36 $this->assertEquals($current.$args, $f->find(), '::find() returns the executable PHP'); 37 $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP'); 38 } 39 40 /** 41 * tests find() with the env var / constant PHP_BINARY with HHVM. 42 */ 43 public function testFindWithHHVM() 44 { 45 if (!\defined('HHVM_VERSION')) { 46 $this->markTestSkipped('Should be executed in HHVM context.'); 47 } 48 49 $f = new PhpExecutableFinder(); 50 51 $current = getenv('PHP_BINARY') ?: \PHP_BINARY; 52 53 $this->assertEquals($current.' --php', $f->find(), '::find() returns the executable PHP'); 54 $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP'); 55 } 56 57 /** 58 * tests find() with the env var PHP_PATH. 59 */ 60 public function testFindArguments() 61 { 62 $f = new PhpExecutableFinder(); 63 64 if (\defined('HHVM_VERSION')) { 65 $this->assertEquals(['--php'], $f->findArguments(), '::findArguments() returns HHVM arguments'); 66 } elseif ('phpdbg' === \PHP_SAPI) { 67 $this->assertEquals(['-qrr'], $f->findArguments(), '::findArguments() returns phpdbg arguments'); 68 } else { 69 $this->assertEquals([], $f->findArguments(), '::findArguments() returns no arguments'); 70 } 71 } 72} 73