Skip to content

Commit

Permalink
Merge pull request #74 from acquia/ACMS-4333
Browse files Browse the repository at this point in the history
ACMS-4333: Fixed the bug reported in D11.
  • Loading branch information
vishalkhode1 authored Nov 26, 2024
2 parents 691c63f + ba0c74b commit 2c62bb0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Config/DefaultDrushConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Drush/Commands/BaseDrushCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 16 additions & 1 deletion src/Robo/Config/ConfigAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions src/Robo/Tasks/DrushTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@
*/
class DrushTask extends CommandStack {

use ConfigAwareTrait;
use CommandArguments {
option as traitOption;
}
Expand Down
4 changes: 3 additions & 1 deletion tests/src/Functional/Config/DefaultDrushConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ 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);
$actual = $default_drush_config->export();
$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,
Expand Down
7 changes: 4 additions & 3 deletions tests/src/unit/Robo/Config/ConfigAwareTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 2c62bb0

Please sign in to comment.