PhpExecutableFinderTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Process\PhpExecutableFinder;
  13. /**
  14. * @author Robert Schönthal <seroscho@googlemail.com>
  15. */
  16. class PhpExecutableFinderTest extends TestCase
  17. {
  18. /**
  19. * tests find() with the env var PHP_PATH.
  20. */
  21. public function testFindWithPhpPath()
  22. {
  23. if (defined('PHP_BINARY')) {
  24. $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
  25. }
  26. $f = new PhpExecutableFinder();
  27. $current = $f->find();
  28. //not executable PHP_PATH
  29. putenv('PHP_PATH=/not/executable/php');
  30. $this->assertFalse($f->find(), '::find() returns false for not executable PHP');
  31. $this->assertFalse($f->find(false), '::find() returns false for not executable PHP');
  32. //executable PHP_PATH
  33. putenv('PHP_PATH='.$current);
  34. $this->assertEquals($f->find(), $current, '::find() returns the executable PHP');
  35. $this->assertEquals($f->find(false), $current, '::find() returns the executable PHP');
  36. }
  37. /**
  38. * tests find() with the env var PHP_PATH.
  39. */
  40. public function testFindWithHHVM()
  41. {
  42. if (!defined('HHVM_VERSION')) {
  43. $this->markTestSkipped('Should be executed in HHVM context.');
  44. }
  45. $f = new PhpExecutableFinder();
  46. $current = getenv('PHP_BINARY') ?: PHP_BINARY;
  47. $this->assertEquals($current.' --php', $f->find(), '::find() returns the executable PHP');
  48. $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
  49. }
  50. /**
  51. * tests find() with the env var PHP_PATH.
  52. */
  53. public function testFindArguments()
  54. {
  55. $f = new PhpExecutableFinder();
  56. if (defined('HHVM_VERSION')) {
  57. $this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
  58. } elseif ('phpdbg' === PHP_SAPI) {
  59. $this->assertEquals($f->findArguments(), array('-qrr'), '::findArguments() returns phpdbg arguments');
  60. } else {
  61. $this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
  62. }
  63. }
  64. /**
  65. * tests find() with default executable.
  66. */
  67. public function testFindWithSuffix()
  68. {
  69. if (defined('PHP_BINARY')) {
  70. $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
  71. }
  72. putenv('PHP_PATH=');
  73. putenv('PHP_PEAR_PHP_BIN=');
  74. $f = new PhpExecutableFinder();
  75. $current = $f->find();
  76. //TODO maybe php executable is custom or even Windows
  77. if ('\\' === DIRECTORY_SEPARATOR) {
  78. $this->assertTrue(is_executable($current));
  79. $this->assertRegExp('/\\\\php\.(exe|bat|cmd|com)$/i', $current, '::find() returns the executable PHP with suffixes');
  80. }
  81. }
  82. }