Skip to content

Commit

Permalink
Merge pull request #1521 from pantheon-systems/remove/ssh_framework_c…
Browse files Browse the repository at this point in the history
…heck

BUGS-976- Removed framework check from remote type commands
  • Loading branch information
TeslaDethray authored Jan 11, 2017
2 parents 44f2b73 + 68ebba6 commit 6ffba3d
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 105 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. This projec
## MASTER
### Added
- Added `--to=` option to `backup:get` to allow specifying of a local download location. (#1520)
- Removed framework type check from `drush` and `wp` commands. (#1521)

## 1.0.0-beta.2 - 2017-01-10
### Fixed
Expand Down
8 changes: 0 additions & 8 deletions src/Commands/Remote/DrushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ class DrushCommand extends SSHBaseCommand
*/
protected $command = 'drush';

/**
* @inheritdoc
*/
protected $valid_frameworks = [
'drupal',
'drupal8',
];

/**
* Runs a Drush command remotely on a site's environment.
*
Expand Down
25 changes: 0 additions & 25 deletions src/Commands/Remote/SSHBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ abstract class SSHBaseCommand extends TerminusCommand implements SiteAwareInterf
* @var string Name of the command to be run as it will be used on server
*/
protected $command = '';
/**
* @var array
*/
protected $valid_frameworks = [];
/**
* @var Site
*/
Expand Down Expand Up @@ -91,7 +87,6 @@ function ($buffer) use ($output) {
protected function validateEnvironment($site, $environment)
{
$this->validateConnectionMode($environment->get('connection_mode'));
$this->validateFramework($site->get('framework'));
}

/**
Expand All @@ -109,26 +104,6 @@ protected function validateConnectionMode($mode)
}
}

/**
* Validates the framework being used
*
* @param string $framework
* @throws TerminusException
*/
protected function validateFramework($framework)
{
if (!in_array($framework, $this->valid_frameworks)) {
throw new TerminusException(
'The {command} command is only available on sites running {frameworks}. The framework for this site is {framework}.',
[
'command' => $this->command,
'frameworks' => implode(', ', $this->valid_frameworks),
'framework' => $framework,
]
);
}
}

/**
* Gets the command-line args
*
Expand Down
8 changes: 0 additions & 8 deletions src/Commands/Remote/WPCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ class WPCommand extends SSHBaseCommand
*/
protected $command = 'wp';

/**
* @inheritdoc
*/
protected $valid_frameworks = [
'wordpress',
'wordpress_network',
];

/**
* Runs a WP-CLI command remotely on a site's environment.
*
Expand Down
5 changes: 0 additions & 5 deletions tests/features/drush.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@ Feature: Running Drush Commands on a Drupal Site
When I run: terminus drush [[test_site_name]].dev -- version
Then I should get: "Terminus is in test mode"
And I should get: "drush version"

@vcr wp.yml
Scenario: Running a drush command on a Wordpress site is not possible
When I run: terminus drush [[test_site_name]].dev -- status
Then I should see an error message: The drush command is only available on sites running drupal, drupal8. The framework for this site is wordpress.
5 changes: 0 additions & 5 deletions tests/features/wp-cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@ Feature: Running WP-CLI Commands on a Drupal Site
When I run: terminus wp [[test_site_name]].dev -- cli version
Then I should get: "Terminus is in test mode"
And I should get: "wp cli version"

@vcr drush.yml
Scenario: Running a WP-CLI command on a Drupal site is not possible
When I run: terminus wp [[test_site_name]].dev -- cli version
Then I should see an error message: The wp command is only available on sites running wordpress, wordpress_network. The framework for this site is drupal8.
14 changes: 3 additions & 11 deletions tests/unit_tests/Commands/Remote/DummyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,14 @@
*/
class DummyCommand extends SSHBaseCommand
{
/**
* @var string
*/
protected $command = 'dummy';

protected $unavailable_commands = [
'avoided' => 'alternative',
'no-alternative' => '',
];

protected $valid_frameworks = [
'framework-a',
'framework-b',
];

public function dummyCommand($site_env_id, array $dummy_args)
{
$this->prepareEnvironment($site_env_id);

return $this->executeCommand($dummy_args);
}
}
46 changes: 3 additions & 43 deletions tests/unit_tests/Commands/Remote/SSHBaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function testExecuteCommand()
{
$dummy_output = 'dummy output';
$options = ['arg1', 'arg2',];
$framework_name = 'framework-a';
$site_name = 'site name';
$mode = 'sftp';
$command = 'dummy ' . implode(' ', $options);
Expand All @@ -44,11 +43,10 @@ public function testExecuteCommand()
->willReturn($mode);
$this->site->expects($this->any())->method('get')
->withConsecutive(
[$this->equalTo('framework'),],
[$this->equalTo('name'),],
[$this->equalTo('name'),]
)
->willReturnOnConsecutiveCalls($framework_name, $site_name, $site_name);
->willReturnOnConsecutiveCalls($site_name, $site_name);
$this->logger->expects($this->once())
->method('log')
->with(
Expand Down Expand Up @@ -77,7 +75,6 @@ public function testExecuteCommandNonzeroStatus()
{
$dummy_output = 'dummy output';
$options = ['arg1', 'arg2',];
$framework_name = 'framework-a';
$site_name = 'site name';
$mode = 'sftp';
$status_code = 1;
Expand All @@ -90,11 +87,10 @@ public function testExecuteCommandNonzeroStatus()
->willReturn($mode);
$this->site->expects($this->any())->method('get')
->withConsecutive(
[$this->equalTo('framework'),],
[$this->equalTo('name'),],
[$this->equalTo('name'),]
)
->willReturnOnConsecutiveCalls($framework_name, $site_name, $site_name);
->willReturnOnConsecutiveCalls($site_name, $site_name);
$this->environment->expects($this->once())
->method('sendCommandViaSsh')
->with($this->equalTo($command))
Expand All @@ -118,48 +114,13 @@ public function testExecuteCommandNonzeroStatus()
$this->assertNull($out);
}

/**
* Tests command execution when attempting to execute with an invalid framework
*/
public function testExecuteCommandInvalidFramework()
{
$options = ['arg1', 'arg2',];
$framework_name = 'framework';
$site_name = 'site name';
$mode = 'sftp';

$this->environment->expects($this->once())
->method('get')
->with($this->equalTo('connection_mode'))
->willReturn($mode);
$this->site->expects($this->any())->method('get')
->withConsecutive(
[$this->equalTo('framework'),],
[$this->equalTo('name'),]
)
->willReturnOnConsecutiveCalls($framework_name, $site_name);
$this->logger->expects($this->never())
->method('log');
$this->environment->expects($this->never())
->method('sendCommandViaSsh');

$this->setExpectedException(
TerminusException::class,
"The dummy command is only available on sites running framework-a, framework-b. The framework for this site is $framework_name."
);

$out = $this->command->dummyCommand("$site_name.env", $options);
$this->assertNull($out);
}

/**
* Tests command execution when in git mode
*/
public function testExecuteCommandInGitMode()
{
$dummy_output = 'dummy output';
$options = ['arg1', 'arg2',];
$framework_name = 'framework-a';
$site_name = 'site name';
$mode = 'git';
$status_code = 0;
Expand All @@ -180,11 +141,10 @@ public function testExecuteCommandInGitMode()
);
$this->site->expects($this->any())->method('get')
->withConsecutive(
[$this->equalTo('framework'),],
[$this->equalTo('name'),],
[$this->equalTo('name'),]
)
->willReturnOnConsecutiveCalls($framework_name, $site_name, $site_name);
->willReturnOnConsecutiveCalls($site_name, $site_name);
$this->logger->expects($this->at(1))
->method('log')
->with(
Expand Down

0 comments on commit 6ffba3d

Please sign in to comment.