Skip to content

Commit

Permalink
Merge branch '4.4' into 5.4
Browse files Browse the repository at this point in the history
* 4.4:
  Remove extra space in NotificationEmail
  Fix the usage of the Valid constraints in array-based forms
  [DI] fix `ServiceSubscriberTrait` bug where parent has `__call()`
  [HttpClient] Fix reading proxy settings from dotenv when curl is used
  [Process] Don't return executable directories in PhpExecutableFinder
  Center icons vertically in trace list
  • Loading branch information
derrabus committed Mar 13, 2022
2 parents 9544040 + 7489e29 commit ca5bdf2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
10 changes: 7 additions & 3 deletions PhpExecutableFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function find(bool $includeArgs = true)
}
}

if (@is_dir($php)) {
return false;
}

return $php;
}

Expand All @@ -57,20 +61,20 @@ public function find(bool $includeArgs = true)
}

if ($php = getenv('PHP_PATH')) {
if (!@is_executable($php)) {
if (!@is_executable($php) || @is_dir($php)) {
return false;
}

return $php;
}

if ($php = getenv('PHP_PEAR_PHP_BIN')) {
if (@is_executable($php)) {
if (@is_executable($php) && !@is_dir($php)) {
return $php;
}
}

if (@is_executable($php = \PHP_BINDIR.('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php'))) {
if (@is_executable($php = \PHP_BINDIR.('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php')) && !@is_dir($php)) {
return $php;
}

Expand Down
30 changes: 25 additions & 5 deletions Tests/PhpExecutableFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,32 @@ public function testFindArguments()
public function testNotExitsBinaryFile()
{
$f = new PhpExecutableFinder();
$phpBinaryEnv = \PHP_BINARY;
putenv('PHP_BINARY=/usr/local/php/bin/php-invalid');

$this->assertFalse($f->find(), '::find() returns false because of not exist file');
$this->assertFalse($f->find(false), '::find(false) returns false because of not exist file');
$originalPhpBinary = getenv('PHP_BINARY');

putenv('PHP_BINARY='.$phpBinaryEnv);
try {
putenv('PHP_BINARY=/usr/local/php/bin/php-invalid');

$this->assertFalse($f->find(), '::find() returns false because of not exist file');
$this->assertFalse($f->find(false), '::find(false) returns false because of not exist file');
} finally {
putenv('PHP_BINARY='.$originalPhpBinary);
}
}

public function testFindWithExecutableDirectory()
{
$originalPhpBinary = getenv('PHP_BINARY');

try {
$executableDirectoryPath = sys_get_temp_dir().'/PhpExecutableFinderTest_testFindWithExecutableDirectory';
@mkdir($executableDirectoryPath);
$this->assertTrue(is_executable($executableDirectoryPath));
putenv('PHP_BINARY='.$executableDirectoryPath);

$this->assertFalse((new PhpExecutableFinder())->find());
} finally {
putenv('PHP_BINARY='.$originalPhpBinary);
}
}
}

0 comments on commit ca5bdf2

Please sign in to comment.