Skip to content
Snippets Groups Projects
Commit f56a9625 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3282677 by phenaproxima: In certain situations, Composer may run with a...

Issue #3282677 by phenaproxima: In certain situations, Composer may run with a different PHP interpreter than the one running Drupal
parent d105d726
No related branches found
No related tags found
No related merge requests found
...@@ -74,8 +74,9 @@ final class ProcessFactory implements ProcessFactoryInterface { ...@@ -74,8 +74,9 @@ final class ProcessFactory implements ProcessFactoryInterface {
if ($this->isComposerCommand($command)) { if ($this->isComposerCommand($command)) {
$env['COMPOSER_HOME'] = $this->getComposerHomePath(); $env['COMPOSER_HOME'] = $this->getComposerHomePath();
} }
// Ensure that the PHP interpreter is in the PATH. // Ensure that the current PHP installation is the first place that will be
$env['PATH'] = $this->getEnv('PATH') . ':' . static::getPhpDirectory(); // searched when looking for the PHP interpreter.
$env['PATH'] = static::getPhpDirectory() . ':' . $this->getEnv('PATH');
return $process->setEnv($env); return $process->setEnv($env);
} }
......
<?php
namespace Drupal\Tests\package_manager\Unit;
use Drupal\package_manager\ProcessFactory;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\package_manager\ProcessFactory
*
* @group automatic_updates
*/
class ProcessFactoryTest extends UnitTestCase {
/**
* Tests that the process factory prepends the PHP directory to PATH.
*/
public function testPhpDirectoryPrependedToPath(): void {
$factory = new ProcessFactory(
$this->prophesize('\Drupal\Core\File\FileSystemInterface')->reveal(),
$this->getConfigFactoryStub()
);
// Ensure that the directory of the PHP interpreter can be found.
$reflector = new \ReflectionObject($factory);
$method = $reflector->getMethod('getPhpDirectory');
$method->setAccessible(TRUE);
$php_dir = $method->invoke(NULL);
$this->assertNotEmpty($php_dir);
// The process factory should always put the PHP interpreter's directory
// at the beginning of the PATH environment variable.
$env = $factory->create(['whoami'])->getEnv();
$this->assertStringStartsWith("$php_dir:", $env['PATH']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment