|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the curl-library package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2017 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Library\CURL\Tests\Configuration; |
|
13
|
|
|
|
|
14
|
|
|
use Exception; |
|
15
|
|
|
use PHPUnit_Framework_TestCase; |
|
16
|
|
|
use WBW\Library\Core\Exception\Argument\StringArgumentException; |
|
17
|
|
|
use WBW\Library\CURL\Configuration\CURLConfiguration; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* cURL configuration test. |
|
21
|
|
|
* |
|
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
23
|
|
|
* @package WBW\Library\CURL\Tests\Configuration |
|
24
|
|
|
* @final |
|
25
|
|
|
*/ |
|
26
|
|
|
final class CURLConfigurationTest extends PHPUnit_Framework_TestCase { |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Tests the __constructor() method. |
|
30
|
|
|
* |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testConstruct() { |
|
34
|
|
|
|
|
35
|
|
|
$obj = new CURLConfiguration(); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertFalse($obj->getAllowEncoding()); |
|
38
|
|
|
$this->assertEquals(0, $obj->getConnectTimeout()); |
|
39
|
|
|
$this->assertFalse($obj->getDebug()); |
|
40
|
|
|
$this->assertEquals("php://output", $obj->getDebugFile()); |
|
41
|
|
|
$this->assertEquals([], $obj->getHeaders()); |
|
42
|
|
|
$this->assertNull($obj->getHost()); |
|
43
|
|
|
$this->assertNull($obj->getHttpPassword()); |
|
44
|
|
|
$this->assertNull($obj->getHttpUsername()); |
|
45
|
|
|
$this->assertNull($obj->getProxyHost()); |
|
46
|
|
|
$this->assertNull($obj->getProxyPassword()); |
|
47
|
|
|
$this->assertNull($obj->getProxyPort()); |
|
48
|
|
|
$this->assertNull($obj->getProxyType()); |
|
49
|
|
|
$this->assertNull($obj->getProxyUsername()); |
|
50
|
|
|
$this->assertEquals(0, $obj->getRequestTimeout()); |
|
51
|
|
|
$this->assertTrue($obj->getSslVerification()); |
|
52
|
|
|
$this->assertEquals("webeweb/curl-library", $obj->getUserAgent()); |
|
53
|
|
|
$this->assertFalse($obj->getVerbose()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Tests the addHeader() method. |
|
58
|
|
|
* |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testAddHeader() { |
|
62
|
|
|
|
|
63
|
|
|
$obj = new CURLConfiguration(); |
|
64
|
|
|
|
|
65
|
|
|
// === |
|
66
|
|
|
$obj->addHeader("name", "value"); |
|
67
|
|
|
$res1 = ["name" => "value"]; |
|
68
|
|
|
$this->assertEquals($res1, $obj->getHeaders()); |
|
69
|
|
|
|
|
70
|
|
|
// === |
|
71
|
|
|
try { |
|
72
|
|
|
|
|
73
|
|
|
$obj->addHeader(1, "value"); |
|
74
|
|
|
} catch (Exception $ex) { |
|
75
|
|
|
|
|
76
|
|
|
$this->assertInstanceOf(StringArgumentException::class, $ex); |
|
77
|
|
|
$this->assertEquals("The argument \"1\" is not a string", $ex->getMessage()); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Tests the clearHeader() method. |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
|
|
public function testClearHeaders() { |
|
87
|
|
|
|
|
88
|
|
|
$obj = new CURLConfiguration(); |
|
89
|
|
|
|
|
90
|
|
|
$obj->addHeader("name", "value"); |
|
91
|
|
|
$this->assertCount(1, $obj->getHeaders()); |
|
92
|
|
|
|
|
93
|
|
|
$obj->clearHeaders(); |
|
94
|
|
|
$this->assertCount(0, $obj->getHeaders()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Tests the removeHeader() method. |
|
99
|
|
|
* |
|
100
|
|
|
* @return void |
|
101
|
|
|
*/ |
|
102
|
|
|
public function testRemoveHeader() { |
|
103
|
|
|
|
|
104
|
|
|
$obj = new CURLConfiguration(); |
|
105
|
|
|
$obj->addHeader("name", "value"); |
|
106
|
|
|
|
|
107
|
|
|
// === |
|
108
|
|
|
$obj->removeHeader(""); |
|
109
|
|
|
$res1 = ["name" => "value"]; |
|
110
|
|
|
$this->assertEquals($res1, $obj->getHeaders()); |
|
111
|
|
|
|
|
112
|
|
|
// === |
|
113
|
|
|
$obj->removeHeader("name"); |
|
114
|
|
|
$res2 = []; |
|
115
|
|
|
$this->assertEquals($res2, $obj->getHeaders()); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Tests the setAllowEncoding() method. |
|
120
|
|
|
* |
|
121
|
|
|
* @return void |
|
122
|
|
|
*/ |
|
123
|
|
|
public function testSetAllowEncoding() { |
|
124
|
|
|
|
|
125
|
|
|
$obj = new CURLConfiguration(); |
|
126
|
|
|
|
|
127
|
|
|
$obj->setAllowEncoding(true); |
|
128
|
|
|
$this->assertTrue($obj->getAllowEncoding()); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Tests the setConnectTimeout() method. |
|
133
|
|
|
* |
|
134
|
|
|
* @return void |
|
135
|
|
|
*/ |
|
136
|
|
|
public function testSetConnectTimeout() { |
|
137
|
|
|
|
|
138
|
|
|
$obj = new CURLConfiguration(); |
|
139
|
|
|
|
|
140
|
|
|
$obj->setConnectTimeout(1); |
|
141
|
|
|
$this->assertEquals(1, $obj->getConnectTimeout()); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Tests the setDebug() method. |
|
146
|
|
|
* |
|
147
|
|
|
* @return void |
|
148
|
|
|
*/ |
|
149
|
|
|
public function testSetDebug() { |
|
150
|
|
|
|
|
151
|
|
|
$obj = new CURLConfiguration(); |
|
152
|
|
|
|
|
153
|
|
|
$obj->setDebug(true); |
|
154
|
|
|
$this->assertTrue($obj->getDebug()); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Tests the setDebugFile() method. |
|
159
|
|
|
* |
|
160
|
|
|
* @return void |
|
161
|
|
|
*/ |
|
162
|
|
|
public function testSetDebugFile() { |
|
163
|
|
|
|
|
164
|
|
|
$obj = new CURLConfiguration(); |
|
165
|
|
|
|
|
166
|
|
|
$obj->setDebugFile("./debugfile.log"); |
|
167
|
|
|
$this->assertEquals("./debugfile.log", $obj->getDebugFile()); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Tests the setHost() method. |
|
172
|
|
|
* |
|
173
|
|
|
* @return void |
|
174
|
|
|
*/ |
|
175
|
|
|
public function testSetHost() { |
|
176
|
|
|
|
|
177
|
|
|
$obj = new CURLConfiguration(); |
|
178
|
|
|
|
|
179
|
|
|
$obj->setHost("host"); |
|
180
|
|
|
$this->assertEquals("host", $obj->getHost()); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Tests the setHttpPassword() method. |
|
185
|
|
|
* |
|
186
|
|
|
* @return void |
|
187
|
|
|
*/ |
|
188
|
|
|
public function testSetHttpPassword() { |
|
189
|
|
|
|
|
190
|
|
|
$obj = new CURLConfiguration(); |
|
191
|
|
|
|
|
192
|
|
|
$obj->setHttpPassword("httpPassword"); |
|
193
|
|
|
$this->assertEquals("httpPassword", $obj->getHttpPassword()); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Tests the setHttpUsername() method. |
|
198
|
|
|
* |
|
199
|
|
|
* @return void |
|
200
|
|
|
*/ |
|
201
|
|
|
public function testSetHttpUsername() { |
|
202
|
|
|
|
|
203
|
|
|
$obj = new CURLConfiguration(); |
|
204
|
|
|
|
|
205
|
|
|
$obj->setHttpUsername("httpUsername"); |
|
206
|
|
|
$this->assertEquals("httpUsername", $obj->getHttpUsername()); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Tests the setProxyHost() method. |
|
211
|
|
|
* |
|
212
|
|
|
* @return void |
|
213
|
|
|
*/ |
|
214
|
|
|
public function testSetProxyHost() { |
|
215
|
|
|
|
|
216
|
|
|
$obj = new CURLConfiguration(); |
|
217
|
|
|
|
|
218
|
|
|
$obj->setProxyHost("proxyHost"); |
|
219
|
|
|
$this->assertEquals("proxyHost", $obj->getProxyHost()); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Tests the setProxyPassword() method. |
|
224
|
|
|
* |
|
225
|
|
|
* @return void |
|
226
|
|
|
*/ |
|
227
|
|
|
public function testSetProxyPassword() { |
|
228
|
|
|
|
|
229
|
|
|
$obj = new CURLConfiguration(); |
|
230
|
|
|
|
|
231
|
|
|
$obj->setProxyPassword("proxyPassword"); |
|
232
|
|
|
$this->assertEquals("proxyPassword", $obj->getProxyPassword()); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Tests the setProxyPort() method. |
|
237
|
|
|
* |
|
238
|
|
|
* @return void |
|
239
|
|
|
*/ |
|
240
|
|
|
public function testSetProxyPort() { |
|
241
|
|
|
|
|
242
|
|
|
$obj = new CURLConfiguration(); |
|
243
|
|
|
|
|
244
|
|
|
$obj->setProxyPort("proxyPort"); |
|
245
|
|
|
$this->assertEquals("proxyPort", $obj->getProxyPort()); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Tests the setProxyType() method. |
|
250
|
|
|
* |
|
251
|
|
|
* @return void |
|
252
|
|
|
*/ |
|
253
|
|
|
public function testSetProxyType() { |
|
254
|
|
|
|
|
255
|
|
|
$obj = new CURLConfiguration(); |
|
256
|
|
|
|
|
257
|
|
|
$obj->setProxyType(1); |
|
258
|
|
|
$this->assertEquals(1, $obj->getProxyType()); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Tests the setProxyUsername() method. |
|
263
|
|
|
* |
|
264
|
|
|
* @return void |
|
265
|
|
|
*/ |
|
266
|
|
|
public function testSetProxyUsername() { |
|
267
|
|
|
|
|
268
|
|
|
$obj = new CURLConfiguration(); |
|
269
|
|
|
|
|
270
|
|
|
$obj->setProxyUsername("proxyUsername"); |
|
271
|
|
|
$this->assertEquals("proxyUsername", $obj->getProxyUsername()); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Tests the setRequestTimeout() method. |
|
276
|
|
|
* |
|
277
|
|
|
* @return void |
|
278
|
|
|
*/ |
|
279
|
|
|
public function testSetRequestTimeout() { |
|
280
|
|
|
|
|
281
|
|
|
$obj = new CURLConfiguration(); |
|
282
|
|
|
|
|
283
|
|
|
$obj->setRequestTimeout(1); |
|
284
|
|
|
$this->assertEquals(1, $obj->getRequestTimeout()); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* Tests the setSslVerification() method. |
|
289
|
|
|
* |
|
290
|
|
|
* @return void |
|
291
|
|
|
*/ |
|
292
|
|
|
public function testSetSslVerification() { |
|
293
|
|
|
|
|
294
|
|
|
$obj = new CURLConfiguration(); |
|
295
|
|
|
|
|
296
|
|
|
$obj->setSslVerification(false); |
|
297
|
|
|
$this->assertFalse($obj->getSslVerification()); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* Tests the setUserAgent() method. |
|
302
|
|
|
* |
|
303
|
|
|
* @return void |
|
304
|
|
|
*/ |
|
305
|
|
|
public function testSetUserAgent() { |
|
306
|
|
|
|
|
307
|
|
|
$obj = new CURLConfiguration(); |
|
308
|
|
|
|
|
309
|
|
|
$obj->setUserAgent("userAgent"); |
|
310
|
|
|
$this->assertEquals("userAgent", $obj->getUserAgent()); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* Tests the setVerbose() method. |
|
315
|
|
|
* |
|
316
|
|
|
* @return void |
|
317
|
|
|
*/ |
|
318
|
|
|
public function testSetVerbose() { |
|
319
|
|
|
|
|
320
|
|
|
$obj = new CURLConfiguration(); |
|
321
|
|
|
|
|
322
|
|
|
$obj->setVerbose(true); |
|
323
|
|
|
$this->assertTrue($obj->getVerbose()); |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
} |
|
327
|
|
|
|