PhpExecutableFinderTest.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. 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. }