diff --git a/src/Config/DefaultDrushConfig.php b/src/Config/DefaultDrushConfig.php index 7b55ddc..343de43 100644 --- a/src/Config/DefaultDrushConfig.php +++ b/src/Config/DefaultDrushConfig.php @@ -26,6 +26,7 @@ public function __construct(?DrushConfig $config = NULL) { } $this->set('drush.bin', $config->get("runtime.drush-script")); $this->setDefault('drush.alias', "self"); + $this->setDefault('drush.uri', $config->get('options.uri')); $this->combine($config->export()); } } diff --git a/src/Drush/Commands/BaseDrushCommands.php b/src/Drush/Commands/BaseDrushCommands.php index fb9afca..34cdf48 100644 --- a/src/Drush/Commands/BaseDrushCommands.php +++ b/src/Drush/Commands/BaseDrushCommands.php @@ -113,7 +113,7 @@ public function switchSiteContext(string $site_name): void { */ protected function initializeConfig(string $site_name = ""): void { $config = new DefaultDrushConfig($this->getConfig()); - $configInitializer = new ConfigInitializer($config, $this->input()); + $configInitializer = new ConfigInitializer($config); if ($site_name) { $configInitializer->setSite($site_name); } diff --git a/src/Robo/Config/ConfigAwareTrait.php b/src/Robo/Config/ConfigAwareTrait.php index db88ac0..33451d8 100644 --- a/src/Robo/Config/ConfigAwareTrait.php +++ b/src/Robo/Config/ConfigAwareTrait.php @@ -2,14 +2,29 @@ namespace Acquia\Drupal\RecommendedSettings\Robo\Config; +use Acquia\Drupal\RecommendedSettings\Config\ConfigInitializer; +use Acquia\Drupal\RecommendedSettings\Config\DefaultDrushConfig; use Drush\Config\ConfigAwareTrait as DrushConfigAwareTrait; +use Drush\Config\DrushConfig; /** * Adds custom methods to DrushConfigAwareTrait. */ trait ConfigAwareTrait { - use DrushConfigAwareTrait; + use DrushConfigAwareTrait { + DrushConfigAwareTrait::getConfig as parentDrushGetConfig; + } + + /** + * {@inheritdoc} + */ + public function getConfig(): DrushConfig { + if (!$this->config instanceof DefaultDrushConfig) { + $this->config = new DefaultDrushConfig($this->parentDrushGetConfig()); + } + return $this->config; + } /** * {@inheritdoc} diff --git a/src/Robo/Tasks/DrushTask.php b/src/Robo/Tasks/DrushTask.php index 8165bc3..7f8c765 100644 --- a/src/Robo/Tasks/DrushTask.php +++ b/src/Robo/Tasks/DrushTask.php @@ -2,6 +2,7 @@ namespace Acquia\Drupal\RecommendedSettings\Robo\Tasks; +use Acquia\Drupal\RecommendedSettings\Robo\Config\ConfigAwareTrait; use Robo\Common\CommandArguments; use Robo\Exception\TaskException; use Robo\Task\CommandStack; @@ -22,6 +23,7 @@ */ class DrushTask extends CommandStack { + use ConfigAwareTrait; use CommandArguments { option as traitOption; } diff --git a/tests/src/Functional/Config/DefaultDrushConfigTest.php b/tests/src/Functional/Config/DefaultDrushConfigTest.php index 7b6bb0b..8dd13a0 100644 --- a/tests/src/Functional/Config/DefaultDrushConfigTest.php +++ b/tests/src/Functional/Config/DefaultDrushConfigTest.php @@ -25,6 +25,7 @@ public function testDefaultDrushConfigData(): void { $drushConfig->set("options.root", $drupal_root); $drushConfig->set("drush.vendor-dir", $project_root . "/vendor"); $drushConfig->set("options.ansi", TRUE); + $drushConfig->set('drush.uri', '/var/www/html/acms.prod/vendor/bin'); $drushConfig->set("runtime.drush-script", $project_root . "/vendor/bin/drush"); $default_drush_config = new DefaultDrushConfig($drushConfig); @@ -32,9 +33,10 @@ public function testDefaultDrushConfigData(): void { $this->assertEquals($actual, [ "drush" => [ "alias" => "self", - "vendor-dir" => $project_root . "/vendor", + "uri" => '/var/www/html/acms.prod/vendor/bin', "ansi" => TRUE, "bin" => $project_root . "/vendor/bin/drush", + "vendor-dir" => $project_root . "/vendor", ], "runtime" => [ "project" => $project_root, diff --git a/tests/src/unit/Robo/Config/ConfigAwareTraitTest.php b/tests/src/unit/Robo/Config/ConfigAwareTraitTest.php index eb17529..19ecfb2 100644 --- a/tests/src/unit/Robo/Config/ConfigAwareTraitTest.php +++ b/tests/src/unit/Robo/Config/ConfigAwareTraitTest.php @@ -21,12 +21,13 @@ class ConfigAwareTraitTest extends TestCase { */ public function testGetConfigValue(): void { $this->config = new DrushConfig(); - // Tests when no value exist for the key, then default value must return. + // Tests that default value for key is always set to /bin. $this->assertEquals( - "/var/www/html/acms.prod/vendor/bin", - $this->getConfigValue("composer.bin", "/var/www/html/acms.prod/vendor/bin"), + "/bin", + $this->getConfigValue("composer.bin"), ); $drush_config = new DrushConfig(); + $drush_config->set('drush.uri', '/var/www/html/acms.prod/vendor/bin'); $drush_config->set("runtime.project", "/var/www/html/acms.prod"); $drush_config->set("options.root", "/var/www/html/acms.prod/docroot"); $drush_config->set("drush.vendor-dir", $drush_config->get("runtime.project") . "/vendor");