Skip to content

Commit 9372e7a

Browse files
sanmaifabpot
authored andcommitted
[Process] Consider \"executable\" suffixes first on Windows
1 parent 05d69bb commit 9372e7a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Symfony/Component/Process/ExecutableFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function find($name, $default = null, array $extraDirs = array())
7373
$suffixes = array('');
7474
if ('\\' === DIRECTORY_SEPARATOR) {
7575
$pathExt = getenv('PATHEXT');
76-
$suffixes = array_merge($suffixes, $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes);
76+
$suffixes = array_merge($pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes, $suffixes);
7777
}
7878
foreach ($suffixes as $suffix) {
7979
foreach ($dirs as $dir) {

src/Symfony/Component/Process/Tests/ExecutableFinderTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,36 @@ public function testFindProcessInOpenBasedir()
129129
$this->assertSamePath(PHP_BINARY, $result);
130130
}
131131

132+
/**
133+
* @requires PHP 5.4
134+
*/
135+
public function testFindBatchExecutableOnWindows()
136+
{
137+
if (ini_get('open_basedir')) {
138+
$this->markTestSkipped('Cannot test when open_basedir is set');
139+
}
140+
if ('\\' !== DIRECTORY_SEPARATOR) {
141+
$this->markTestSkipped('Can be only tested on windows');
142+
}
143+
144+
$target = tempnam(sys_get_temp_dir(), 'example-windows-executable');
145+
146+
touch($target);
147+
touch($target.'.BAT');
148+
149+
$this->assertFalse(is_executable($target));
150+
151+
$this->setPath(sys_get_temp_dir());
152+
153+
$finder = new ExecutableFinder();
154+
$result = $finder->find(basename($target), false);
155+
156+
unlink($target);
157+
unlink($target.'.BAT');
158+
159+
$this->assertSamePath($target.'.BAT', $result);
160+
}
161+
132162
private function assertSamePath($expected, $tested)
133163
{
134164
if ('\\' === DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)