Skip to content

Commit

Permalink
Remove confirmation dialog from mt:delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan Dowling committed Sep 16, 2016
1 parent dcd8f6b commit 18f73eb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
1 change: 1 addition & 0 deletions php/Terminus/Exceptions/TerminusException.php
Expand Up @@ -30,6 +30,7 @@ public function __construct(
$code = 0
) {
$this->replacements = $replacements;

parent::__construct($message, $code);
}

Expand Down
20 changes: 6 additions & 14 deletions src/Commands/MachineToken/DeleteCommand.php
Expand Up @@ -28,22 +28,14 @@ public function delete($machine_token_id) {

// Find the token. Will throw an exception if it doesn't exist.
$machine_token = $user->machine_tokens->get($machine_token_id);
if (empty($machine_token)) {
throw new TerminusException('There are no machine tokens with the id {id}.', compact($machine_token_id));
}
$name = $machine_token->get('device_name');

// Confirm the delete.
if ($this->confirm(sprintf('Are you sure you want to delete "%s"?', $name))) {
$this->log()->notice('Deleting {token} ...', ['token' => $name]);

$response = $machine_token->delete();
if ($response['status_code'] == 200) {
$this->log()->notice('Deleted {token}!', ['token' => $name]);
} else {
throw new TerminusException('There was an problem deleting the machine token.');
}

$this->log()->notice('Deleting {token} ...', ['token' => $name]);
$response = $machine_token->delete();
if ($response['status_code'] == 200) {
$this->log()->notice('Deleted {token}!', ['token' => $name]);
} else {
throw new TerminusException('There was an problem deleting the machine token.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/active_features/machine-token.feature
Expand Up @@ -16,7 +16,7 @@ Feature: Machine tokens command

@vcr machine-tokens_delete
Scenario: Delete machine token
When I run "terminus machine-token:delete [[machine_token_id]] --yes"
When I run "terminus machine-token:delete [[machine_token_id]]"
Then I should get:
"""
Deleted [[machine_token_device]]!
Expand Down
Expand Up @@ -2,7 +2,7 @@
namespace Pantheon\Terminus\UnitTests\Commands\Auth;
use Pantheon\Terminus\Commands\MachineToken\DeleteCommand;
use Pantheon\Terminus\Config;
use Symfony\Component\Console\Input\ArrayInput;
use Terminus\Exceptions\TerminusException;
use Terminus\Models\MachineToken;

/**
Expand All @@ -22,17 +22,6 @@ protected function setUp()
$this->command = new DeleteCommand(new Config());
$this->command->setSession($this->session);
$this->command->setLogger($this->logger);

// Ignore user input.
$input = $this->getMockBuilder(ArrayInput::class)
->disableOriginalConstructor()
->getMock();
$input->expects($this->any())
->method('hasParameterOption')
->with(['--yes', '-y'])
->willReturn(true);

$this->command->setInput($input);
}


Expand Down Expand Up @@ -82,9 +71,10 @@ public function testMachineTokenDeleteNonExistant()
$this->machine_tokens->expects($this->once())
->method('get')
->with($this->equalTo('123'))
->willReturn(null);
->will($this->throwException(new TerminusException));


$this->setExpectedException(\Exception::class, 'There are no machine tokens with the id {id}.');
$this->setExpectedException(TerminusException::class);

$this->command->delete('123');
}
Expand Down

0 comments on commit 18f73eb

Please sign in to comment.