Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ronan Dowling
committed
Sep 15, 2016
1 parent
8dde1f0
commit a264d57
Showing
6 changed files
with
310 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Feature: Machine tokens command | ||
In order to manage my devices | ||
As a user | ||
I need to be able to view and delete my machine tokens. | ||
|
||
Background: I am logged in | ||
Given I am authenticated | ||
|
||
@vcr machine-tokens_list | ||
Scenario: List the machine tokens | ||
When I run "terminus machine-token:list" | ||
Then I should get: | ||
""" | ||
[[machine_token_id]] | ||
""" | ||
|
||
@vcr machine-tokens_delete | ||
Scenario: Delete machine token | ||
When I run "terminus machine-token:delete [[machine_token_id]] --yes" | ||
Then I should get: | ||
""" | ||
Deleted [[machine_token_device]]! | ||
""" |
51 changes: 51 additions & 0 deletions
51
tests/new_unit_tests/Commands/MachineToken/MachineTokenCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* @file | ||
* Contains Pantheon\Terminus\UnitTests\Commands\Auth\MachineTokenCommandTest | ||
*/ | ||
|
||
|
||
namespace Pantheon\Terminus\UnitTests\Commands\Auth; | ||
|
||
|
||
use Pantheon\Terminus\Session\Session; | ||
use Psr\Log\NullLogger; | ||
use Terminus\Collections\MachineTokens; | ||
use Terminus\Models\User; | ||
|
||
abstract class MachineTokenCommandTest extends \PHPUnit_Framework_TestCase { | ||
protected $session; | ||
protected $machine_tokens; | ||
protected $user; | ||
protected $logger; | ||
protected $command; | ||
|
||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->machine_tokens = $this->getMockBuilder(MachineTokens::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->user = $this->getMockBuilder(User::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->user->machine_tokens = $this->machine_tokens; | ||
|
||
$this->session = $this->getMockBuilder(Session::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->session->method('getUser') | ||
->willReturn($this->user); | ||
|
||
$this->logger = $this->getMockBuilder(NullLogger::class) | ||
->setMethods(array('log')) | ||
->getMock(); | ||
|
||
|
||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
tests/new_unit_tests/Commands/MachineToken/MachineTokensDeleteCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
namespace Pantheon\Terminus\UnitTests\Commands\Auth; | ||
use Pantheon\Terminus\Commands\MachineToken\DeleteCommand; | ||
use Pantheon\Terminus\Config; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Terminus\Models\MachineToken; | ||
|
||
/** | ||
* Testing class for Pantheon\Terminus\Commands\Auth\LoginCommand | ||
*/ | ||
class MachineTokenDeleteCommandTest extends MachineTokenCommandTest | ||
{ | ||
|
||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::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); | ||
} | ||
|
||
|
||
/** | ||
* Tests the machine-token:delete command. | ||
* | ||
* @return void | ||
*/ | ||
public function testMachineTokenDelete() | ||
{ | ||
$token = $this->getMockBuilder(MachineToken::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$token->expects($this->once()) | ||
->method('delete') | ||
->willReturn( | ||
['status_code' => 200] | ||
); | ||
|
||
|
||
$this->machine_tokens->expects($this->once()) | ||
->method('get') | ||
->with($this->equalTo('123')) | ||
->willReturn( | ||
$token | ||
); | ||
|
||
|
||
$this->command->delete('123'); | ||
} | ||
|
||
/** | ||
* Tests the machine-token:delete command when there are no tokens. | ||
* | ||
* @return void | ||
*/ | ||
public function testMachineTokenDeleteNonExistant() | ||
{ | ||
$token = $this->getMockBuilder(MachineToken::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$token->expects($this->never()) | ||
->method('delete'); | ||
|
||
$this->machine_tokens->expects($this->once()) | ||
->method('get') | ||
->with($this->equalTo('123')) | ||
->willReturn(null); | ||
|
||
$this->setExpectedException(\Exception::class, 'There are no machine tokens with the id {id}.'); | ||
|
||
$this->command->delete('123'); | ||
} | ||
|
||
/** | ||
* Tests the machine-token:delete command when the API fails. | ||
* | ||
* @return void | ||
*/ | ||
public function testMachineTokenDeleteAPIFailure() | ||
{ | ||
$token = $this->getMockBuilder(MachineToken::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$token->expects($this->once()) | ||
->method('delete') | ||
->willReturn( | ||
['status_code' => 500] | ||
); | ||
|
||
$this->machine_tokens->expects($this->once()) | ||
->method('get') | ||
->with($this->equalTo('123')) | ||
->willReturn( | ||
$token | ||
); | ||
|
||
|
||
$this->setExpectedException(\Exception::class, 'There was an problem deleting the machine token.'); | ||
|
||
$this->command->delete('123'); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
tests/new_unit_tests/Commands/MachineToken/MachineTokensListCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
namespace Pantheon\Terminus\UnitTests\Commands\Auth; | ||
use Pantheon\Terminus\Commands\MachineToken\ListCommand; | ||
use Pantheon\Terminus\Config; | ||
use Terminus\Collections\MachineTokens; | ||
use Terminus\Models\MachineToken; | ||
|
||
/** | ||
* Testing class for Pantheon\Terminus\Commands\Auth\LoginCommand | ||
*/ | ||
class MachineTokensListCommandTest extends MachineTokenCommandTest | ||
{ | ||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->command = new ListCommand(new Config()); | ||
$this->command->setSession($this->session); | ||
$this->command->setLogger($this->logger); | ||
} | ||
|
||
/** | ||
* Tests the machine-token:list command when there are no tokens. | ||
* | ||
* @return void | ||
*/ | ||
public function testMachineTokenListEmpty() | ||
{ | ||
$this->machine_tokens->method('all') | ||
->willReturn([]); | ||
|
||
$this->logger->expects($this->once()) | ||
->method('log') | ||
->with($this->equalTo('warning'), $this->equalTo('You have no machine tokens.')); | ||
|
||
$out = $this->command->listTokens(); | ||
$this->assertInstanceOf('Consolidation\OutputFormatters\StructuredData\RowsOfFields', $out); | ||
$this->assertEquals([], $out->getArrayCopy()); | ||
} | ||
|
||
/** | ||
* Tests the machine-token:list command when there are tokens. | ||
* | ||
* @return void | ||
*/ | ||
public function testMachineTokenListNotEmpty() | ||
{ | ||
$tokens = [ | ||
['id' => '1', 'device_name' => 'Foo'], | ||
['id' => '2', 'device_name' => 'Bar'] | ||
]; | ||
$collection = new MachineTokens(['user' => $this->user]); | ||
$this->machine_tokens->method('all') | ||
->willReturn([ | ||
new MachineToken((object)$tokens[0], ['collection' => $collection]), | ||
new MachineToken((object)$tokens[1], ['collection' => $collection]) | ||
]); | ||
|
||
$this->logger->expects($this->never()) | ||
->method($this->anything()); | ||
|
||
$out = $this->command->listTokens(); | ||
$this->assertInstanceOf('Consolidation\OutputFormatters\StructuredData\RowsOfFields', $out); | ||
$this->assertEquals($tokens, $out->getArrayCopy()); | ||
} | ||
|
||
} |