scratch – Blame information for rev 126
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
126 | office | 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\ExecutableFinder; |
||
16 | |||
17 | /** |
||
18 | * @author Chris Smith <chris@cs278.org> |
||
19 | */ |
||
20 | class ExecutableFinderTest extends TestCase |
||
21 | { |
||
22 | private $path; |
||
23 | |||
24 | protected function tearDown() |
||
25 | { |
||
26 | if ($this->path) { |
||
27 | // Restore path if it was changed. |
||
28 | putenv('PATH='.$this->path); |
||
29 | } |
||
30 | } |
||
31 | |||
32 | private function setPath($path) |
||
33 | { |
||
34 | $this->path = getenv('PATH'); |
||
35 | putenv('PATH='.$path); |
||
36 | } |
||
37 | |||
38 | public function testFind() |
||
39 | { |
||
40 | if (ini_get('open_basedir')) { |
||
41 | $this->markTestSkipped('Cannot test when open_basedir is set'); |
||
42 | } |
||
43 | |||
44 | $this->setPath(dirname(PHP_BINARY)); |
||
45 | |||
46 | $finder = new ExecutableFinder(); |
||
47 | $result = $finder->find($this->getPhpBinaryName()); |
||
48 | |||
49 | $this->assertSamePath(PHP_BINARY, $result); |
||
50 | } |
||
51 | |||
52 | public function testFindWithDefault() |
||
53 | { |
||
54 | if (ini_get('open_basedir')) { |
||
55 | $this->markTestSkipped('Cannot test when open_basedir is set'); |
||
56 | } |
||
57 | |||
58 | $expected = 'defaultValue'; |
||
59 | |||
60 | $this->setPath(''); |
||
61 | |||
62 | $finder = new ExecutableFinder(); |
||
63 | $result = $finder->find('foo', $expected); |
||
64 | |||
65 | $this->assertEquals($expected, $result); |
||
66 | } |
||
67 | |||
68 | public function testFindWithExtraDirs() |
||
69 | { |
||
70 | if (ini_get('open_basedir')) { |
||
71 | $this->markTestSkipped('Cannot test when open_basedir is set'); |
||
72 | } |
||
73 | |||
74 | $this->setPath(''); |
||
75 | |||
76 | $extraDirs = array(dirname(PHP_BINARY)); |
||
77 | |||
78 | $finder = new ExecutableFinder(); |
||
79 | $result = $finder->find($this->getPhpBinaryName(), null, $extraDirs); |
||
80 | |||
81 | $this->assertSamePath(PHP_BINARY, $result); |
||
82 | } |
||
83 | |||
84 | public function testFindWithOpenBaseDir() |
||
85 | { |
||
86 | if ('\\' === DIRECTORY_SEPARATOR) { |
||
87 | $this->markTestSkipped('Cannot run test on windows'); |
||
88 | } |
||
89 | |||
90 | if (ini_get('open_basedir')) { |
||
91 | $this->markTestSkipped('Cannot test when open_basedir is set'); |
||
92 | } |
||
93 | |||
94 | $this->iniSet('open_basedir', dirname(PHP_BINARY).(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : '')); |
||
95 | |||
96 | $finder = new ExecutableFinder(); |
||
97 | $result = $finder->find($this->getPhpBinaryName()); |
||
98 | |||
99 | $this->assertSamePath(PHP_BINARY, $result); |
||
100 | } |
||
101 | |||
102 | public function testFindProcessInOpenBasedir() |
||
103 | { |
||
104 | if (ini_get('open_basedir')) { |
||
105 | $this->markTestSkipped('Cannot test when open_basedir is set'); |
||
106 | } |
||
107 | if ('\\' === DIRECTORY_SEPARATOR) { |
||
108 | $this->markTestSkipped('Cannot run test on windows'); |
||
109 | } |
||
110 | |||
111 | $this->setPath(''); |
||
112 | $this->iniSet('open_basedir', PHP_BINARY.(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : '')); |
||
113 | |||
114 | $finder = new ExecutableFinder(); |
||
115 | $result = $finder->find($this->getPhpBinaryName(), false); |
||
116 | |||
117 | $this->assertSamePath(PHP_BINARY, $result); |
||
118 | } |
||
119 | |||
120 | private function assertSamePath($expected, $tested) |
||
121 | { |
||
122 | if ('\\' === DIRECTORY_SEPARATOR) { |
||
123 | $this->assertEquals(strtolower($expected), strtolower($tested)); |
||
124 | } else { |
||
125 | $this->assertEquals($expected, $tested); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | private function getPhpBinaryName() |
||
130 | { |
||
131 | return basename(PHP_BINARY, '\\' === DIRECTORY_SEPARATOR ? '.exe' : ''); |
||
132 | } |
||
133 | } |