Version 1
[yaffs-website] / vendor / symfony / process / Tests / PhpExecutableFinderTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Process\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Process\PhpExecutableFinder;
16
17 /**
18  * @author Robert Schönthal <seroscho@googlemail.com>
19  */
20 class PhpExecutableFinderTest extends TestCase
21 {
22     /**
23      * tests find() with the env var PHP_PATH.
24      */
25     public function testFindWithPhpPath()
26     {
27         if (defined('PHP_BINARY')) {
28             $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
29         }
30
31         $f = new PhpExecutableFinder();
32
33         $current = $f->find();
34
35         //not executable PHP_PATH
36         putenv('PHP_PATH=/not/executable/php');
37         $this->assertFalse($f->find(), '::find() returns false for not executable PHP');
38         $this->assertFalse($f->find(false), '::find() returns false for not executable PHP');
39
40         //executable PHP_PATH
41         putenv('PHP_PATH='.$current);
42         $this->assertEquals($f->find(), $current, '::find() returns the executable PHP');
43         $this->assertEquals($f->find(false), $current, '::find() returns the executable PHP');
44     }
45
46     /**
47      * tests find() with the constant PHP_BINARY.
48      *
49      * @requires PHP 5.4
50      */
51     public function testFind()
52     {
53         if (defined('HHVM_VERSION')) {
54             $this->markTestSkipped('Should not be executed in HHVM context.');
55         }
56
57         $f = new PhpExecutableFinder();
58
59         $current = PHP_BINARY;
60         $args = 'phpdbg' === PHP_SAPI ? ' -qrr' : '';
61
62         $this->assertEquals($current.$args, $f->find(), '::find() returns the executable PHP');
63         $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
64     }
65
66     /**
67      * tests find() with the env var / constant PHP_BINARY with HHVM.
68      */
69     public function testFindWithHHVM()
70     {
71         if (!defined('HHVM_VERSION')) {
72             $this->markTestSkipped('Should be executed in HHVM context.');
73         }
74
75         $f = new PhpExecutableFinder();
76
77         $current = getenv('PHP_BINARY') ?: PHP_BINARY;
78
79         $this->assertEquals($current.' --php', $f->find(), '::find() returns the executable PHP');
80         $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
81     }
82
83     /**
84      * tests find() with the env var PHP_PATH.
85      */
86     public function testFindArguments()
87     {
88         $f = new PhpExecutableFinder();
89
90         if (defined('HHVM_VERSION')) {
91             $this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
92         } elseif ('phpdbg' === PHP_SAPI) {
93             $this->assertEquals($f->findArguments(), array('-qrr'), '::findArguments() returns phpdbg arguments');
94         } else {
95             $this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
96         }
97     }
98
99     /**
100      * tests find() with default executable.
101      */
102     public function testFindWithSuffix()
103     {
104         if (defined('PHP_BINARY')) {
105             $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
106         }
107
108         putenv('PHP_PATH=');
109         putenv('PHP_PEAR_PHP_BIN=');
110         $f = new PhpExecutableFinder();
111
112         $current = $f->find();
113
114         //TODO maybe php executable is custom or even Windows
115         if ('\\' === DIRECTORY_SEPARATOR) {
116             $this->assertTrue(is_executable($current));
117             $this->assertTrue((bool) preg_match('/'.addslashes(DIRECTORY_SEPARATOR).'php\.(exe|bat|cmd|com)$/i', $current), '::find() returns the executable PHP with suffixes');
118         }
119     }
120 }