Skip to content

Commit

Permalink
Add associative list tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Sep 23, 2016
1 parent 76a15b0 commit 221d211
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
54 changes: 54 additions & 0 deletions tests/src/alpha/AlphaCommandFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Consolidation\AnnotatedCommand\CommandError;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Consolidation\OutputFormatters\StructuredData\AssociativeList;

/**
* Test file used in the testCommandDiscovery() test.
Expand Down Expand Up @@ -89,6 +90,59 @@ public function exampleTable($options = ['format' => 'table', 'fields' => ''])
return new RowsOfFields($outputData);
}

/**
* Test command with formatters using an associative list
*
* @command example:list
* @field-labels
* sftp_command: SFTP Command
* sftp_username: SFTP Username
* sftp_host: SFTP Host
* sftp_password: SFTP Password
* sftp_url: SFTP URL
* git_command: Git Command
* git_username: Git Username
* git_host: Git Host
* git_port: Git Port
* git_url: Git URL
* mysql_command: MySQL Command
* mysql_username: MySQL Username
* mysql_host: MySQL Host
* mysql_password: MySQL Password
* mysql_url: MySQL URL
* mysql_port: MySQL Port
* mysql_database: MySQL Database
* redis_command: Redis Command
* redis_port: Redis Port
* redis_url: Redis URL
* redis_password: Redis Password
* @default-fields *_command
* @return \Consolidation\OutputFormatters\StructuredData\AssociativeList
*/
public function exampleAssociativeList()
{
$outputData = [
'sftp_command' => 'sftp -o Port=2222 dev@appserver.dev.drush.in',
'sftp_username' => 'dev',
'sftp_host' => 'appserver.dev.drush.in',
'sftp_password' => 'Use your account password',
'sftp_url' => 'sftp://dev@appserver.dev.drush.in:2222',
'git_command' => 'git clone ssh://codeserver.dev@codeserver.dev.drush.in:2222/~/repository.git wp-update',
'git_username' => 'codeserver.dev',
'git_host' => 'codeserver.dev.drush.in',
'git_port' => 2222,
'git_url' => 'ssh://codeserver.dev@codeserver.dev.drush.in:2222/~/repository.git',
'mysql_command' => 'mysql -u pantheon -p4b33cb -h dbserver.dev.drush.in -P 16191 pantheon',
'mysql_username' => 'pantheon',
'mysql_host' => 'dbserver.dev.drush.in',
'mysql_password' => '4b33cb',
'mysql_url' => 'mysql://pantheon:4b33cb@dbserver.dev.drush.in:16191/pantheon',
'mysql_port' => 16191,
'mysql_database' => 'pantheon',
];
return new AssociativeList($outputData);
}

/**
* This command has no annotations; this means that it will not be
* found when createCommandsFromClass() is called with
Expand Down
23 changes: 17 additions & 6 deletions tests/testFullStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ function testCommandsAndHooks()
EOT;
$this->assertRunCommandViaApplicationEquals('example:table --fields=III,II', $expected);

// Now we will once again add all commands, this time including all
// public methods. The command 'withoutAnnotations' should now be found.
$factory->setIncludeAllPublicMethods(true);
$this->addDiscoveredCommands($factory, $commandFiles);
$this->assertTrue($this->application->has('without:annotations'));

$expectedSingleField = <<<EOT
Two
Zwei
Expand All @@ -164,6 +158,23 @@ function testCommandsAndHooks()
// When --field is specified (instead of --fields), then the format
// is forced to 'string'.
$this->assertRunCommandViaApplicationEquals('example:table --field=II', $expectedSingleField);

$expectedAssociativeListTable = <<<EOT
--------------- ----------------------------------------------------------------------------------------
SFTP Command sftp -o Port=2222 dev@appserver.dev.drush.in
Git Command git clone ssh://codeserver.dev@codeserver.dev.drush.in:2222/~/repository.git wp-update
MySQL Command mysql -u pantheon -p4b33cb -h dbserver.dev.drush.in -P 16191 pantheon
--------------- ----------------------------------------------------------------------------------------
EOT;
$this->assertRunCommandViaApplicationEquals('example:list', $expectedAssociativeListTable);
$this->assertRunCommandViaApplicationEquals('example:list --field=sftp_command', 'sftp -o Port=2222 dev@appserver.dev.drush.in');

// Now we will once again add all commands, this time including all
// public methods. The command 'withoutAnnotations' should now be found.
$factory->setIncludeAllPublicMethods(true);
$this->addDiscoveredCommands($factory, $commandFiles);
$this->assertTrue($this->application->has('without:annotations'));

}

public function addDiscoveredCommands($factory, $commandFiles) {
Expand Down

0 comments on commit 221d211

Please sign in to comment.