Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Config/ConfigLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ConfigLocator

protected $configFilePaths = [];

protected $processedConfigPaths = [];

/*
* From context.inc:
*
Expand Down Expand Up @@ -308,6 +310,15 @@ public function addConfigPaths($contextName, $paths)
$this->addToSources($processor->sources());
$context->import($processor->export($reference));
$this->config->addContext($contextName, $context);
$this->processedConfigPaths = array_merge($this->processedConfigPaths, $paths);

// Recursive case.
if ($context->has('drush.paths.config')) {
$new_config_paths = array_diff((array) $context->get('drush.paths.config'), $this->processedConfigPaths);
if ($new_config_paths) {
$this->addConfigPaths($contextName, $new_config_paths);
}
}

return $this;
}
Expand Down
57 changes: 57 additions & 0 deletions tests/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,61 @@ public function testOptionsUri()
$output = $this->getOutputFromJSON();
$this->assertEquals($test_uri, $output->uri);
}

public function testRecursiveConfigLoading()
{
// Put a yml file in the drush folder.
$drush_config_file = Path::join($this->getSut(), 'drush', 'drush.yml');
$a_drush_config_file = Path::join($this->getSut(), 'drush', 'a.drush.yml');
$b_drush_config_file = Path::join($this->getSut(), 'drush', 'b.drush.yml');
$test_uri = 'http://test.uri';
// Set up multiple drush.yml files that include one another to test
// potential infinite loop.
$drush_yml_options = [
'drush' => [
'paths' => [
'config' => [
$a_drush_config_file,
],
],
],
];
$a_drush_yml_options = [
'drush' => [
'paths' => [
'config' => [
$b_drush_config_file,
],
],
],
];
$b_drush_yml_options = [
'drush' => [
'paths' => [
'config' => [
$a_drush_config_file,
],
],
],
'options' => [
'uri' => $test_uri,
],
];
$command_options = [
'format' => 'json',
'uri' => 'OMIT', // A special value which causes --uri to not be specified.
];
file_put_contents($drush_config_file, Yaml::dump($drush_yml_options, PHP_INT_MAX, 2));
file_put_contents($a_drush_config_file, Yaml::dump($a_drush_yml_options, PHP_INT_MAX, 2));
file_put_contents($b_drush_config_file, Yaml::dump($b_drush_yml_options, PHP_INT_MAX, 2));
$this->drush('core-status', [], $command_options, null, $this->getSut());
unlink($drush_config_file);
unlink($a_drush_config_file);
unlink($b_drush_config_file);
$output = $this->getOutputFromJSON();
$drush_conf_as_string = print_r($output->{'drush-conf'}, true);
$this->assertContains($a_drush_config_file, $output->{'drush-conf'}, "Loaded drush config files are: " . $drush_conf_as_string);
$this->assertContains($b_drush_config_file, $output->{'drush-conf'}, "Loaded drush config files are: " . $drush_conf_as_string);
$this->assertEquals($test_uri, $output->uri);
}
}