-
Notifications
You must be signed in to change notification settings - Fork 190
/
MachineTokensDeleteCommandTest.php
111 lines (89 loc) · 2.51 KB
/
MachineTokensDeleteCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace Pantheon\Terminus\UnitTests\Commands\Auth;
use Pantheon\Terminus\Commands\MachineToken\DeleteCommand;
use Pantheon\Terminus\Config;
use Terminus\Exceptions\TerminusException;
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);
}
/**
* 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'))
->will($this->throwException(new TerminusException));
$this->setExpectedException(TerminusException::class);
$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');
}
}