Skip to content

Commit

Permalink
Issue #5960: Environment variables ignored if the value provided in t…
Browse files Browse the repository at this point in the history
…he user configuration file. (#5961)

* Issue #5960: Environment variables ignored if the value provided in the user configuration file.

On-behalf-of: @salsadigitalauorg <sonny.kieu@salsa.digital>

* Issue #5960: Updated unit test.

On-behalf-of: @salsadigitalauorg <sonny.kieu@salsa.digital>

---------

Co-authored-by: Moshe Weitzman <weitzman@tejasa.com>
  • Loading branch information
sonnykt and weitzman committed Apr 29, 2024
1 parent 25e00e5 commit d5f5f32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Config/ConfigLocator.php
Expand Up @@ -105,11 +105,11 @@ public function __construct($envPrefix = '', $configFileVariant = '')
// Add placeholders to establish priority. We add
// contexts from lowest to highest priority.
$this->config->addPlaceholder(self::DRUSH_CONTEXT);
$this->config->addPlaceholder(self::USER_CONTEXT);
if (!empty($envPrefix)) {
$envConfig = new EnvConfig($envPrefix);
$this->config->addContext(self::ENV_CONTEXT, $envConfig);
}
$this->config->addPlaceholder(self::USER_CONTEXT);
$this->config->addPlaceholder(self::DRUPAL_CONTEXT);
$this->config->addPlaceholder(self::SITE_CONTEXT);
$this->config->addPlaceholder(self::ALIAS_CONTEXT);
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/ConfigLocatorTest.php
Expand Up @@ -91,6 +91,25 @@ function ($item) {
$this->assertEquals($expected, $aliasPaths);
}

/**
* Test an env var supersedes user's configuration file.
*/
public function testEnvVar()
{
$configLocator = $this->createConfigLocator();

$sources = $configLocator->sources();
$this->assertEquals($this->fixturesDir() . '/home/.drush/drush.yml', Path::canonicalize($sources['test']['home']));

$config = $configLocator->config();
$this->assertEquals('A user-specific setting', $config->get('test.home'));

putenv('TEST_HOME=An env overridden setting');
$this->assertNotEquals('A user-specific setting', $config->get('test.home'));
$this->assertEquals('An env overridden setting', $config->get('test.home'));
putenv('TEST_HOME');
}

/**
* Create a config locator from All The Sources, for use in multiple tests.
*/
Expand Down

0 comments on commit d5f5f32

Please sign in to comment.