From 18f73ebc959846ece935dea7354b6f4091db1c02 Mon Sep 17 00:00:00 2001 From: Ronan Dowling Date: Fri, 16 Sep 2016 13:21:27 -0500 Subject: [PATCH] Remove confirmation dialog from mt:delete --- php/Terminus/Exceptions/TerminusException.php | 1 + src/Commands/MachineToken/DeleteCommand.php | 20 ++++++------------- tests/active_features/machine-token.feature | 2 +- .../MachineTokensDeleteCommandTest.php | 18 ++++------------- 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/php/Terminus/Exceptions/TerminusException.php b/php/Terminus/Exceptions/TerminusException.php index f01fd3f84..9871ea569 100644 --- a/php/Terminus/Exceptions/TerminusException.php +++ b/php/Terminus/Exceptions/TerminusException.php @@ -30,6 +30,7 @@ public function __construct( $code = 0 ) { $this->replacements = $replacements; + parent::__construct($message, $code); } diff --git a/src/Commands/MachineToken/DeleteCommand.php b/src/Commands/MachineToken/DeleteCommand.php index 5faa168f9..25341d30e 100644 --- a/src/Commands/MachineToken/DeleteCommand.php +++ b/src/Commands/MachineToken/DeleteCommand.php @@ -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.'); } } diff --git a/tests/active_features/machine-token.feature b/tests/active_features/machine-token.feature index f2bc5e352..7ac4717ed 100644 --- a/tests/active_features/machine-token.feature +++ b/tests/active_features/machine-token.feature @@ -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]]! diff --git a/tests/new_unit_tests/Commands/MachineToken/MachineTokensDeleteCommandTest.php b/tests/new_unit_tests/Commands/MachineToken/MachineTokensDeleteCommandTest.php index c0af0f13c..79123c9f3 100644 --- a/tests/new_unit_tests/Commands/MachineToken/MachineTokensDeleteCommandTest.php +++ b/tests/new_unit_tests/Commands/MachineToken/MachineTokensDeleteCommandTest.php @@ -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; /** @@ -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); } @@ -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'); }