PhpExecutableFinderTest.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. } else {
  58. $this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
  59. }
  60. }
  61. /**
  62. * tests find() with default executable.
  63. */
  64. public function testFindWithSuffix()
  65. {
  66. if (defined('PHP_BINARY')) {
  67. $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
  68. }
  69. putenv('PHP_PATH=');
  70. putenv('PHP_PEAR_PHP_BIN=');
  71. $f = new PhpExecutableFinder();
  72. $current = $f->find();
  73. //TODO maybe php executable is custom or even Windows
  74. if ('\\' === DIRECTORY_SEPARATOR) {
  75. $this->assertTrue(is_executable($current));
  76. $this->assertTrue((bool) preg_match('/'.addslashes(DIRECTORY_SEPARATOR).'php\.(exe|bat|cmd|com)$/i', $current), '::find() returns the executable PHP with suffixes');
  77. }
  78. }
  79. }