Skip to content

Commit

Permalink
Fixes #3017: Pass 'paths.drush-script' along to backend invoke. (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson authored Oct 7, 2017
1 parent cab3833 commit 7a55e71
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
8 changes: 6 additions & 2 deletions src/Preflight/RedispatchHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
use Symfony\Component\Console\Input\InputInterface;
use Consolidation\AnnotatedCommand\AnnotationData;
use Drush\Log\LogLevel;
use Robo\Contract\ConfigAwareInterface;
use Robo\Common\ConfigAwareTrait;

/**
* The RedispatchHook is installed as an init hook that runs before
* all commands. If the commandline contains an alias or a site specification
* that points at a remote machine, then we will stop execution of the
* current command and instead run the command remotely.
*/
class RedispatchHook implements InitializeHookInterface
class RedispatchHook implements InitializeHookInterface, ConfigAwareInterface
{
use ConfigAwareTrait;

/**
* Check to see if it is necessary to redispatch to a remote site.
* We do not redispatch to local sites here; usually, local sites may
Expand Down Expand Up @@ -84,7 +88,7 @@ public function redispatch(InputInterface $input)
$redispatchOptions = $this->redispatchOptions($input);

$backend_options = [
'drush-script' => null,
'drush-script' => $this->getConfig()->get('paths.drush-script', null),
'remote-host' => $remote_host,
'remote-user' => $remote_user,
'additional-global-options' => [],
Expand Down
8 changes: 6 additions & 2 deletions src/SiteAlias/AliasRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ public function exportConfig()

foreach ($this->remapOptions() as $from => $to) {
if (isset($data[$from])) {
$data['options'][$to] = $data[$from];
unset($data[$from]);
}
$value = $this->get($from, null);
if (isset($value)) {
$data['options'][$to] = $value;
}
}

return new Config($data);
Expand All @@ -251,7 +254,8 @@ public function legacyRecord()
}

/**
* Conversion table from old to new option names.
* Conversion table from old to new option names. These all implicitly
* go in `options`, although they can come from different locations.
*/
protected function remapOptions()
{
Expand Down
7 changes: 6 additions & 1 deletion tests/UnishTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,13 @@ function writeSiteAliases($sites) {
'uri' => $site['uri']
];
}
$this->writeUnishConfig($groups);
}

function writeUnishConfig($unishAliases, $config = [])
{
$etc = self::getSandbox() . '/etc/drush';
file_put_contents(Path::join($etc, 'unish.alias.yml'), Yaml::dump($groups));
file_put_contents(Path::join($etc, 'unish.alias.yml'), Yaml::dump($unishAliases));
$config['drush']['paths']['alias-path'][] = $etc;
file_put_contents(Path::join($etc, 'drush.yml'), Yaml::dump($config, 3));
}
Expand Down
51 changes: 23 additions & 28 deletions tests/backendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,31 @@
* @group base
*/
class backendCase extends CommandUnishTestCase {
// Test to insure that calling drush_invoke_process() with 'dispatch-using-alias'
// will build a command string that uses the alias instead of --root and --uri.
function testDispatchUsingAlias() {
$this->markTestIncomplete('Started failing due to https://github.com/drush-ops/drush/pull/555');
function testDispatchUsingAlias()
{
$unishAliases = [
'remote' => [
'host' => 'server.isp.com',
'user' => 'www-admin',
'root' => '/path/to/drupal',
'uri' => 'http://example.com',
'paths' => [
'drush-script' => '/usr/local/bin/drush',
],
],
];
// n.b. writeUnishConfig will overwrite the alias files create by setupDrupal
$this->writeUnishConfig($unishAliases);
$this->drush('status', [], ['simulate' => NULL], '@unish.remote');
$output = $this->getOutput();

$aliasPath = self::getSandbox() . '/aliases';
mkdir($aliasPath);
$aliasFile = $aliasPath . '/foo.aliases.drushrc.php';
$aliasContents = <<<EOD
<?php
// Written by Unish. This file is safe to delete.
\$aliases['dev'] = array('root' => '/fake/path/to/root', 'uri' => 'default');
EOD;
file_put_contents($aliasFile, $aliasContents);
$options = array(
'alias-path' => $aliasPath,
'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
'script-path' => dirname(__FILE__) . '/resources', // Find unit.drush.inc commandfile.
'backend' => TRUE,
);
$this->drush('php-script', array('testDispatchUsingAlias_script'), $options);
$parsed = $this->parse_backend_output($this->getOutput());
// Clean up -- our other tests do not want extra configuration
unlink(self::getSandbox() . '/etc/drush/drush.yml');

// $parsed['with'] and $parsed['without'] now contain an array
// each with the original arguments passed in with and without
// 'dispatch-using-alias', respectively.
$argDifference = array_diff($parsed['object']['with'], $parsed['object']['without']);
$this->assertEquals(array_diff(array_values($argDifference), array('@foo.dev')), array());
$argDifference = array_diff($parsed['object']['without'], $parsed['object']['with']);
$this->assertEquals(array_diff(array_values($argDifference), array('--root=/fake/path/to/root', '--uri=default')), array());
$output = preg_replace('# *#', ' ', $output);
$output = preg_replace('# -t #', ' ', $output); // volkswagon away the -t, it's not relevant to what we're testing here
$output = preg_replace('#' . self::getSandbox() . '#', '__SANDBOX__', $output);
$this->assertContains("Simulating backend invoke: ssh -o PasswordAuthentication=no [email protected] '/usr/local/bin/drush --alias-path=__SANDBOX__/etc/drush --root=/path/to/drupal --uri=http://example.com --no-ansi status", $output);
}

/**
Expand Down

0 comments on commit 7a55e71

Please sign in to comment.