PhpExecutableFinderTest.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 (false === strstr(PHP_OS, 'WIN')) {
  42. $this->assertEquals($current, PHP_BINDIR.DIRECTORY_SEPARATOR.'php', '::find() returns the executable php with suffixes');
  43. }
  44. }
  45. /**
  46. * tests find() with env var PHP_BINDIR
  47. */
  48. public function testFindWithPHP_PEAR_PHP_BIN()
  49. {
  50. //TODO the code for suffixes in PHP_BINDIR always catches, so the rest cant be tested
  51. //maybe remove the code or move the PHP_PEAR_PHP_BIN code above
  52. $this->markTestIncomplete();
  53. $f = new PhpExecutableFinder();
  54. $current = $f->find();
  55. //not executable PHP_PEAR_PHP_BIN
  56. putenv('PHP_PEAR_PHP_BIN=/not/executable/php');
  57. $this->assertFalse($f->find(), '::find() returns false for not executable php');
  58. //executable PHP_PEAR_PHP_BIN
  59. putenv('PHP_PEAR_PHP_BIN='.$current);
  60. $this->assertEquals($f->find(), $current, '::find() returns the executable php');
  61. }
  62. }