diff --git a/src/SiteAlias/AliasRecord.php b/src/SiteAlias/AliasRecord.php index 19c637a3ca..5340fb74b5 100644 --- a/src/SiteAlias/AliasRecord.php +++ b/src/SiteAlias/AliasRecord.php @@ -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); @@ -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() { diff --git a/tests/UnishTestCase.php b/tests/UnishTestCase.php index 379ce81a1c..23db050463 100644 --- a/tests/UnishTestCase.php +++ b/tests/UnishTestCase.php @@ -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)); } diff --git a/tests/backendTest.php b/tests/backendTest.php index a3eed468d4..0f0a0e3cdf 100644 --- a/tests/backendTest.php +++ b/tests/backendTest.php @@ -16,36 +16,30 @@ * @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 = << '/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('#' . self::getSandbox() . '#', '__SANDBOX__', $output); + $this->assertContains("Simulating backend invoke: ssh -o PasswordAuthentication=no www-admin@server.isp.com '/usr/local/bin/drush --alias-path=__SANDBOX__/etc/drush --root=/path/to/drupal --uri=http://example.com --no-ansi status", $output); } /**