1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AcquiaCloudApi\Tests\Endpoints; |
4
|
|
|
|
5
|
|
|
use AcquiaCloudApi\Tests\CloudApiTestCase; |
6
|
|
|
use AcquiaCloudApi\Connector\Client; |
7
|
|
|
use AcquiaCloudApi\Connector\Connector; |
8
|
|
|
use AcquiaCloudApi\Endpoints\Code; |
9
|
|
|
|
10
|
|
|
class ClientTest extends CloudApiTestCase |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
public function testAddQuery() |
14
|
|
|
{ |
15
|
|
|
$client = $this->getMockClient(); |
16
|
|
|
|
17
|
|
|
$client->addQuery('filter', 'name=dev'); |
18
|
|
|
$client->addQuery('filter', 'type=file'); |
19
|
|
|
|
20
|
|
|
$expectedQuery = [ |
21
|
|
|
'filter' => [ |
22
|
|
|
'name=dev', |
23
|
|
|
'type=file', |
24
|
|
|
], |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
$this->assertEquals($expectedQuery, $client->getQuery()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testFilteredQuery() |
31
|
|
|
{ |
32
|
|
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/Client/getFilteredCode.json'); |
33
|
|
|
$client = $this->getMockClient($response); |
34
|
|
|
|
35
|
|
|
/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */ |
36
|
|
|
$client->addQuery('filter', 'name=@*2014*'); |
37
|
|
|
$client->addQuery('filter', 'type=@*true*'); |
38
|
|
|
$code = new Code($client); |
39
|
|
|
$result = $code->getAll('8ff6c046-ec64-4ce4-bea6-27845ec18600'); |
40
|
|
|
|
41
|
|
|
foreach ($result as $record) { |
42
|
|
|
$this->assertContains('2014', $record->name); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testClearQuery() |
47
|
|
|
{ |
48
|
|
|
$client = $this->getMockClient(); |
49
|
|
|
|
50
|
|
|
$client->addQuery('filter', 'name=dev'); |
51
|
|
|
$this->assertEquals(['filter' => 'name=dev'], $client->getQuery()); |
52
|
|
|
|
53
|
|
|
$client->clearQuery(); |
54
|
|
|
$this->assertTrue(empty($client->getQuery())); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testOptions() |
58
|
|
|
{ |
59
|
|
|
$client = $this->getMockClient(); |
60
|
|
|
|
61
|
|
|
$client->addOption('verify', 'false'); |
62
|
|
|
$client->addOption('curl.options', ['CURLOPT_RETURNTRANSFER' => true]); |
63
|
|
|
$client->addOption('curl.options', ['CURLOPT_FILE' => '/tmp/foo']); |
64
|
|
|
|
65
|
|
|
$expectedOptions = [ |
66
|
|
|
'verify' => 'false', |
67
|
|
|
'curl.options' => [ |
68
|
|
|
'CURLOPT_RETURNTRANSFER' => true, |
69
|
|
|
'CURLOPT_FILE' => '/tmp/foo', |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
$this->assertEquals($expectedOptions, $client->getOptions()); |
74
|
|
|
|
75
|
|
|
$client->clearOptions(); |
76
|
|
|
$this->assertTrue(empty($client->getOptions())); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testModifyOptions() |
80
|
|
|
{ |
81
|
|
|
$client = $this->getMockClient(); |
82
|
|
|
|
83
|
|
|
// Set a number of options and queries as a dependent library would. |
84
|
|
|
$client->addOption('headers', ['User-Agent' => 'AcquiaCli/4.20']); |
85
|
|
|
// Add a user agent twice to ensure that we only see it once in the request. |
86
|
|
|
$client->addOption('headers', ['User-Agent' => 'AcquiaCli/4.20']); |
87
|
|
|
$client->addOption('headers', ['User-Agent' => 'ZCli/1.1.1']); |
88
|
|
|
$client->addOption('headers', ['User-Agent' => 'AaahCli/0.1']); |
89
|
|
|
$client->addQuery('filter', 'name=@*2014*'); |
90
|
|
|
$client->addQuery('filter', 'type=@*true*'); |
91
|
|
|
$client->addQuery('limit', '1'); |
92
|
|
|
|
93
|
|
|
// Set options as an endpoint call would. |
94
|
|
|
$options = [ |
95
|
|
|
'json' => [ |
96
|
|
|
'source' => 'source', |
97
|
|
|
'message' => 'message', |
98
|
|
|
], |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
// Modify the request to ensure that all of the above get merged correctly. |
102
|
|
|
// Run modifyOptions twice to ensure that multiple uses of it do not change |
103
|
|
|
// the end result. |
104
|
|
|
// @see https://github.com/typhonius/acquia-php-sdk-v2/issues/87 |
105
|
|
|
$client->modifyOptions($options); |
106
|
|
|
$actualOptions = $client->modifyOptions($options); |
107
|
|
|
|
108
|
|
|
$version = $client->getVersion(); |
109
|
|
|
$expectedOptions = [ |
110
|
|
|
'headers' => [ |
111
|
|
|
'User-Agent' => sprintf('acquia-php-sdk-v2/%s (https://github.com/typhonius/acquia-php-sdk-v2) AcquiaCli/4.20 ZCli/1.1.1 AaahCli/0.1', $version) |
112
|
|
|
], |
113
|
|
|
'json' => [ |
114
|
|
|
'source' => 'source', |
115
|
|
|
'message' => 'message' |
116
|
|
|
], |
117
|
|
|
'query' => [ |
118
|
|
|
'filter' => 'name=@*2014*,type=@*true*', |
119
|
|
|
'limit' => '1' |
120
|
|
|
] |
121
|
|
|
]; |
122
|
|
|
|
123
|
|
|
$this->assertEquals($expectedOptions, $actualOptions); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testVersion() |
127
|
|
|
{ |
128
|
|
|
$versionFile = sprintf('%s/VERSION', dirname(dirname(__DIR__))); |
129
|
|
|
$version = trim(file_get_contents($versionFile)); |
130
|
|
|
|
131
|
|
|
$client = $this->getMockClient(); |
132
|
|
|
$actualValue = $client->getVersion(); |
133
|
|
|
|
134
|
|
|
$this->assertEquals($version, $actualValue); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function testMissingVersion() |
138
|
|
|
{ |
139
|
|
|
$versionFile = sprintf('%s/VERSION', dirname(dirname(__DIR__))); |
140
|
|
|
$versionFileBak = sprintf('%s.bak', $versionFile); |
141
|
|
|
rename($versionFile, $versionFileBak); |
142
|
|
|
|
143
|
|
|
try { |
144
|
|
|
$client = $this->getMockClient(); |
145
|
|
|
$version = $client->getVersion(); |
|
|
|
|
146
|
|
|
} catch (\Exception $e) { |
147
|
|
|
$this->assertEquals('Exception', get_class($e)); |
148
|
|
|
$this->assertEquals('No VERSION file', $e->getMessage()); |
149
|
|
|
} |
150
|
|
|
rename($versionFileBak, $versionFile); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|