forked from PCextreme/cloudstack-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientTest.php
More file actions
119 lines (99 loc) · 3.19 KB
/
ClientTest.php
File metadata and controls
119 lines (99 loc) · 3.19 KB
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
112
113
114
115
116
117
118
119
<?php
namespace PCextreme\Cloudstack\Test;
use PCextreme\Cloudstack\Client;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\RequestInterface;
use Mockery as m;
class ClientTest extends \PHPUnit_Framework_TestCase
{
/**
* @var AbstractClient
*/
protected $client;
protected function setUp()
{
$this->client = new Client([
'urlApi' => 'https://example.com/client/api',
'apiKey' => 'mock_api_key',
'secretKey' => 'mock_secret_key',
]);
}
public function testRequiredOptions()
{
$required = [
'urlApi' => 'https://example.com/client/api',
'apiKey' => 'mock_api_key',
'secretKey' => 'mock_secret_key',
];
// Test each of the required options by removing a single value
// and attempting to create a new client.
foreach ($required as $key => $value) {
$options = $required;
unset($options[$key]);
try {
$client = new Client($options);
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e);
}
}
$client = new Client($required + []);
}
public function testConfigurableOptions()
{
$options = [
'apiList' => '/../cache/api_list.php',
'responseError' => 'errortext',
'responseCode' => 'errorcode',
];
$client = new Client($options + [
'urlApi' => 'https://example.com/client/api',
'apiKey' => 'mock_api_key',
'secretKey' => 'mock_secret_key',
]);
foreach ($options as $key => $expected) {
$this->assertAttributeEquals($expected, $key, $client);
}
}
public function commandMethodProvider()
{
return [
['mockCommand', 'GET'],
['deployVirtualMachine', 'POST'],
['login', 'POST'],
];
}
/**
* @dataProvider commandMethodProvider
*/
public function testCommandMethod($command, $expected)
{
$this->assertEquals(
$this->client->getCommandMethod($command),
$expected
);
}
public function testCheckResponse()
{
$response = m::mock(ResponseInterface::class);
$reflection = new \ReflectionClass(get_class($this->client));
$checkResponse = $reflection->getMethod('checkResponse');
$checkResponse->setAccessible(true);
$this->assertNull($checkResponse->invokeArgs($this->client, [$response, []]));
}
/**
* @expectedException PCextreme\Cloudstack\Exception\ClientException
*/
public function testCheckResponseThrowsException()
{
$response = m::mock(ResponseInterface::class);
$reflection = new \ReflectionClass(get_class($this->client));
$checkResponse = $reflection->getMethod('checkResponse');
$checkResponse->setAccessible(true);
$checkResponse->invokeArgs($this->client, [$response, ['clientResponse' => [
'cserrorcode' => 1234,
'errorcode' => 1234,
'errortext' => 'foobar',
'uuidList' => [],
]]]);
}
}