19
19
*/
20
20
class ExecutableFinderTest extends TestCase
21
21
{
22
- private $ path ;
23
-
24
22
protected function tearDown (): void
25
23
{
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 );
24
+ putenv ('PATH= ' .($ _SERVER ['PATH ' ] ?? $ _SERVER ['Path ' ]));
36
25
}
37
26
38
27
public function testFind ()
@@ -41,7 +30,7 @@ public function testFind()
41
30
$ this ->markTestSkipped ('Cannot test when open_basedir is set ' );
42
31
}
43
32
44
- $ this -> setPath ( \dirname (\PHP_BINARY ));
33
+ putenv ( ' PATH= ' . \dirname (\PHP_BINARY ));
45
34
46
35
$ finder = new ExecutableFinder ();
47
36
$ result = $ finder ->find ($ this ->getPhpBinaryName ());
@@ -57,7 +46,7 @@ public function testFindWithDefault()
57
46
58
47
$ expected = 'defaultValue ' ;
59
48
60
- $ this -> setPath ( ' ' );
49
+ putenv ( ' PATH= ' );
61
50
62
51
$ finder = new ExecutableFinder ();
63
52
$ result = $ finder ->find ('foo ' , $ expected );
@@ -71,7 +60,7 @@ public function testFindWithNullAsDefault()
71
60
$ this ->markTestSkipped ('Cannot test when open_basedir is set ' );
72
61
}
73
62
74
- $ this -> setPath ( ' ' );
63
+ putenv ( ' PATH= ' );
75
64
76
65
$ finder = new ExecutableFinder ();
77
66
@@ -86,7 +75,7 @@ public function testFindWithExtraDirs()
86
75
$ this ->markTestSkipped ('Cannot test when open_basedir is set ' );
87
76
}
88
77
89
- $ this -> setPath ( ' ' );
78
+ putenv ( ' PATH= ' );
90
79
91
80
$ extraDirs = [\dirname (\PHP_BINARY )];
92
81
@@ -109,6 +98,7 @@ public function testFindWithOpenBaseDir()
109
98
$ this ->markTestSkipped ('Cannot test when open_basedir is set ' );
110
99
}
111
100
101
+ putenv ('PATH= ' .\dirname (\PHP_BINARY ));
112
102
$ initialOpenBaseDir = ini_set ('open_basedir ' , \dirname (\PHP_BINARY ).\PATH_SEPARATOR .'/ ' );
113
103
114
104
try {
@@ -121,32 +111,6 @@ public function testFindWithOpenBaseDir()
121
111
}
122
112
}
123
113
124
- /**
125
- * @runInSeparateProcess
126
- */
127
- public function testFindProcessInOpenBasedir ()
128
- {
129
- if (\ini_get ('open_basedir ' )) {
130
- $ this ->markTestSkipped ('Cannot test when open_basedir is set ' );
131
- }
132
- if ('\\' === \DIRECTORY_SEPARATOR ) {
133
- $ this ->markTestSkipped ('Cannot run test on windows ' );
134
- }
135
-
136
- $ this ->setPath ('' );
137
-
138
- $ initialOpenBaseDir = ini_set ('open_basedir ' , \PHP_BINARY .\PATH_SEPARATOR .'/ ' );
139
-
140
- try {
141
- $ finder = new ExecutableFinder ();
142
- $ result = $ finder ->find ($ this ->getPhpBinaryName (), false );
143
-
144
- $ this ->assertSamePath (\PHP_BINARY , $ result );
145
- } finally {
146
- ini_set ('open_basedir ' , $ initialOpenBaseDir );
147
- }
148
- }
149
-
150
114
public function testFindBatchExecutableOnWindows ()
151
115
{
152
116
if (\ini_get ('open_basedir ' )) {
@@ -163,7 +127,7 @@ public function testFindBatchExecutableOnWindows()
163
127
164
128
$ this ->assertFalse (is_executable ($ target ));
165
129
166
- $ this -> setPath ( sys_get_temp_dir ());
130
+ putenv ( ' PATH= ' . sys_get_temp_dir ());
167
131
168
132
$ finder = new ExecutableFinder ();
169
133
$ result = $ finder ->find (basename ($ target ), false );
0 commit comments