PhpExecutableFinderTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Component\Process\Tests;
  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 testFindWithPhpPath()
  21. {
  22. if (defined('PHP_BINARY')) {
  23. $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
  24. }
  25. $f = new PhpExecutableFinder();
  26. $current = $f->find();
  27. //not executable PHP_PATH
  28. putenv('PHP_PATH=/not/executable/php');
  29. $this->assertFalse($f->find(), '::find() returns false for not executable php');
  30. //executable PHP_PATH
  31. putenv('PHP_PATH='.$current);
  32. $this->assertEquals($f->find(), $current, '::find() returns the executable php');
  33. }
  34. /**
  35. * tests find() with default executable
  36. */
  37. public function testFindWithSuffix()
  38. {
  39. if (defined('PHP_BINARY')) {
  40. $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
  41. }
  42. putenv('PHP_PATH=');
  43. putenv('PHP_PEAR_PHP_BIN=');
  44. $f = new PhpExecutableFinder();
  45. $current = $f->find();
  46. //TODO maybe php executable is custom or even windows
  47. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  48. $this->assertTrue(is_executable($current));
  49. $this->assertTrue((bool) preg_match('/'.addSlashes(DIRECTORY_SEPARATOR).'php\.(exe|bat|cmd|com)$/i', $current), '::find() returns the executable php with suffixes');
  50. }
  51. }
  52. }