1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @SuppressWarnings("StaticAccess") |
4
|
|
|
*/ |
5
|
|
|
class CurlTest extends \PHPUnit\Framework\TestCase |
6
|
|
|
{ |
7
|
|
|
public function testConstruct() |
8
|
|
|
{ |
9
|
|
|
$handler = \Suricate\Suricate::Curl(); |
|
|
|
|
10
|
|
|
$reflection = new \ReflectionClass(get_class($handler)); |
11
|
|
|
$property = $reflection->getProperty('response'); |
12
|
|
|
$property->setAccessible(true); |
13
|
|
|
$this->assertInstanceOf(\Suricate\Request::class, $property->getValue($handler)); |
14
|
|
|
|
15
|
|
|
$property = $reflection->getProperty('request'); |
16
|
|
|
$property->setAccessible(true); |
17
|
|
|
$this->assertInstanceOf(\Suricate\Request::class, $property->getValue($handler)); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testGetSetUrl() |
21
|
|
|
{ |
22
|
|
|
$handler = \Suricate\Suricate::Curl(); |
23
|
|
|
$this->assertSame(null, $handler->getUrl()); |
24
|
|
|
$handler->setUrl('https://www.google.com'); |
25
|
|
|
$this->assertSame('https://www.google.com', $handler->getUrl()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testMethod() |
29
|
|
|
{ |
30
|
|
|
$handler = \Suricate\Suricate::Curl(); |
31
|
|
|
$handler->setMethod('DELETE'); |
32
|
|
|
$reflection = new \ReflectionClass(get_class($handler)); |
33
|
|
|
$property = $reflection->getProperty('request'); |
34
|
|
|
$property->setAccessible(true); |
35
|
|
|
$request = $property->getValue($handler); |
36
|
|
|
$this->assertSame('DELETE', $request->getMethod()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSetUA() |
40
|
|
|
{ |
41
|
|
|
$handler = \Suricate\Suricate::Curl(); |
42
|
|
|
$handler->setUserAgent('GoogleBot'); |
43
|
|
|
|
44
|
|
|
$this->assertSame('GoogleBot', $handler->userAgent); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testAddHeader() |
48
|
|
|
{ |
49
|
|
|
$handler = \Suricate\Suricate::Curl(); |
50
|
|
|
|
51
|
|
|
$this->assertSame([], $handler->headers); |
52
|
|
|
$handler->addHeader('Content-type: application/json'); |
53
|
|
|
$this->assertSame(['Content-type: application/json'], $handler->headers); |
54
|
|
|
$handler->addHeader('Content-length: 42'); |
55
|
|
|
$this->assertSame(['Content-type: application/json', 'Content-length: 42'], $handler->headers); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|