PhpExecutableFinderTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $this->assertFalse($f->find(false), '::find() returns false for not executable PHP');
  31. //executable PHP_PATH
  32. putenv('PHP_PATH='.$current);
  33. $this->assertEquals($f->find(), $current, '::find() returns the executable PHP');
  34. $this->assertEquals($f->find(false), $current, '::find() returns the executable PHP');
  35. }
  36. /**
  37. * tests find() with the env var PHP_PATH.
  38. */
  39. public function testFindWithHHVM()
  40. {
  41. if (!defined('HHVM_VERSION')) {
  42. $this->markTestSkipped('Should be executed in HHVM context.');
  43. }
  44. $f = new PhpExecutableFinder();
  45. $current = getenv('PHP_BINARY') ?: PHP_BINARY;
  46. $this->assertEquals($current.' --php', $f->find(), '::find() returns the executable PHP');
  47. $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
  48. }
  49. /**
  50. * tests find() with the env var PHP_PATH.
  51. */
  52. public function testFindArguments()
  53. {
  54. $f = new PhpExecutableFinder();
  55. if (defined('HHVM_VERSION')) {
  56. $this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
  57. } elseif ('phpdbg' === PHP_SAPI) {
  58. $this->assertEquals($f->findArguments(), array('-qrr'), '::findArguments() returns phpdbg arguments');
  59. } else {
  60. $this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
  61. }
  62. }
  63. /**
  64. * tests find() with default executable.
  65. */
  66. public function testFindWithSuffix()
  67. {
  68. if (defined('PHP_BINARY')) {
  69. $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
  70. }
  71. putenv('PHP_PATH=');
  72. putenv('PHP_PEAR_PHP_BIN=');
  73. $f = new PhpExecutableFinder();
  74. $current = $f->find();
  75. //TODO maybe php executable is custom or even Windows
  76. if ('\\' === DIRECTORY_SEPARATOR) {
  77. $this->assertTrue(is_executable($current));
  78. $this->assertTrue((bool) preg_match('/'.addslashes(DIRECTORY_SEPARATOR).'php\.(exe|bat|cmd|com)$/i', $current), '::find() returns the executable PHP with suffixes');
  79. }
  80. }
  81. }