Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ca598c

Browse files
committed
feature#52679 [Process]ExecutableFinder::addSuffix() has no effect (TravisCarden)
This PR was squashed before being merged into the 7.2 branch.Discussion----------[Process] `ExecutableFinder::addSuffix()` has no effect...except (probably) on Windows.| Q | A| ------------- | ---| Branch? | 6.3| Bug fix? | yes| New feature? | no| Deprecations? | no| License | MIT`ExecutableFinder::addSuffix()` currently has no effect on non-Windows systems because `ExecutableFinder::find()` altogether ignores added suffixes on them. This PR adds tests that prove that it's broken and then fixes it. It clarifies a related docblock along the way.**Note**: I tried to follow the pattern in similar tests of creating fixture files in the temp directory, but `ExecutableFinder::find()` returned a different temp path than `sys_get_temp_dir()`, rendering path comparison impossible. So I added a few fixture files directly to the repo.Commits-------d854b76 [Process] `ExecutableFinder::addSuffix()` has no effect
2 parentsb3508ee +d854b76 commit9ca598c

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

‎src/Symfony/Component/Process/ExecutableFinder.php‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919
*/
2020
class ExecutableFinder
2121
{
22-
privatearray$suffixes = ['.exe','.bat','.cmd','.com'];
22+
privatearray$suffixes = [];
23+
24+
publicfunction__construct()
25+
{
26+
// Set common extensions on Windows.
27+
if ('\\' === \DIRECTORY_SEPARATOR) {
28+
$this->suffixes = ['.exe','.bat','.cmd','.com'];
29+
}
30+
}
2331

2432
/**
2533
* Replaces default suffixes of executable.
@@ -30,7 +38,10 @@ public function setSuffixes(array $suffixes): void
3038
}
3139

3240
/**
33-
* Adds new possible suffix to check for executable.
41+
* Adds new possible suffix to check for executable, including the dot (.).
42+
*
43+
* $finder = new ExecutableFinder();
44+
* $finder->addSuffix('.foo');
3445
*/
3546
publicfunctionaddSuffix(string$suffix):void
3647
{
@@ -52,10 +63,10 @@ public function find(string $name, ?string $default = null, array $extraDirs = [
5263
);
5364

5465
$suffixes = [''];
55-
if ('\\' === \DIRECTORY_SEPARATOR) {
56-
$pathExt =getenv('PATHEXT');
57-
$suffixes =array_merge($pathExt ?explode(\PATH_SEPARATOR,$pathExt) :$this->suffixes,$suffixes);
66+
if ('\\' === \DIRECTORY_SEPARATOR &&$pathExt =getenv('PATHEXT')) {
67+
$suffixes =array_merge(explode(\PATH_SEPARATOR,$pathExt),$suffixes);
5868
}
69+
$suffixes =array_merge($suffixes,$this->suffixes);
5970
foreach ($suffixesas$suffix) {
6071
foreach ($dirsas$dir) {
6172
if (@is_file($file =$dir.\DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,31 @@ public function testFindWithExtraDirs()
8585
$this->assertSamePath(\PHP_BINARY,$result);
8686
}
8787

88+
publicfunctiontestFindWithoutSuffix()
89+
{
90+
$fixturesDir =__DIR__.\DIRECTORY_SEPARATOR.'Fixtures';
91+
$name ='executable_without_suffix';
92+
93+
$finder =newExecutableFinder();
94+
$result =$finder->find($name,null, [$fixturesDir]);
95+
96+
$this->assertSamePath($fixturesDir.\DIRECTORY_SEPARATOR.$name,$result);
97+
}
98+
99+
publicfunctiontestFindWithAddedSuffixes()
100+
{
101+
$fixturesDir =__DIR__.\DIRECTORY_SEPARATOR.'Fixtures';
102+
$name ='executable_with_added_suffix';
103+
$suffix ='.foo';
104+
105+
$finder =newExecutableFinder();
106+
$finder->addSuffix($suffix);
107+
108+
$result =$finder->find($name,null, [$fixturesDir]);
109+
110+
$this->assertSamePath($fixturesDir.\DIRECTORY_SEPARATOR.$name.$suffix,$result);
111+
}
112+
88113
/**
89114
* @runInSeparateProcess
90115
*/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See \Symfony\Component\Process\Tests\ExecutableFinderTest::testFindWithAddedSuffixes()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See \Symfony\Component\Process\Tests\ExecutableFinderTest::testFindWithoutSuffix()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp