Skip to content

Commit

Permalink
Add a test for drush-script
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Oct 7, 2017
1 parent a0bc038 commit f077e74
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
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
50 changes: 22 additions & 28 deletions tests/backendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<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('#' . 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);
}

/**
Expand Down

0 comments on commit f077e74

Please sign in to comment.