PhpExecutableFinderTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Process;
  11. use Symfony\Component\Process\PhpExecutableFinder;
  12. /**
  13. * @author Robert Schönthal <seroscho@googlemail.com>
  14. */
  15. class PhpExecutableFinderTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * tests find() with the env var PHP_PATH
  19. */
  20. public function testFindWithPHP_PATH()
  21. {
  22. $f = new PhpExecutableFinder();
  23. $current = $f->find();
  24. //not executable PHP_PATH
  25. putenv('PHP_PATH=/not/executable/php');
  26. $this->assertFalse($f->find(), '::find() returns false for not executable php');
  27. //executable PHP_PATH
  28. putenv('PHP_PATH='.$current);
  29. $this->assertEquals($f->find(), $current, '::find() returns the executable php');
  30. }
  31. /**
  32. * tests find() with default executable
  33. */
  34. public function testFindWithSuffix()
  35. {
  36. putenv('PHP_PATH=');
  37. putenv('PHP_PEAR_PHP_BIN=');
  38. $f = new PhpExecutableFinder();
  39. $current = $f->find();
  40. //TODO maybe php executable is custom or even windows
  41. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  42. $this->assertTrue(is_executable($current));
  43. $this->assertTrue((bool)preg_match('/'.addSlashes(DIRECTORY_SEPARATOR).'php\.(exe|bat|cmd|com)$/i', $current), '::find() returns the executable php with suffixes');
  44. }
  45. }
  46. }