1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Onoi\HttpRequest\Tests; |
4
|
|
|
|
5
|
|
|
use Onoi\HttpRequest\CurlRequest; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \Onoi\HttpRequest\CurlRequest |
9
|
|
|
* @group onoi-http-request |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 1.0 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class CurlRequestTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
public function testCanConstruct() { |
19
|
|
|
|
20
|
|
|
$instance = new CurlRequest( curl_init() ); |
21
|
|
|
|
22
|
|
|
$this->assertInstanceOf( |
23
|
|
|
'\Onoi\HttpRequest\CurlRequest', |
24
|
|
|
$instance |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
$this->assertInstanceOf( |
28
|
|
|
'\Onoi\HttpRequest\HttpRequest', |
29
|
|
|
$instance |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testWrongResourceTypeThrowsException() { |
34
|
|
|
$this->setExpectedException( 'InvalidArgumentException' ); |
35
|
|
|
new CurlRequest( curl_multi_init() ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testPing() { |
39
|
|
|
|
40
|
|
|
$instance = new CurlRequest( curl_init() ); |
41
|
|
|
|
42
|
|
|
$this->assertFalse( |
43
|
|
|
$instance->ping() |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$instance->setOption( CURLOPT_URL, 'http://example.org' ); |
47
|
|
|
|
48
|
|
|
$this->assertInternalType( |
49
|
|
|
'boolean', |
50
|
|
|
$instance->ping() |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetLastError() { |
55
|
|
|
|
56
|
|
|
$instance = new CurlRequest( curl_init() ); |
57
|
|
|
|
58
|
|
|
$this->assertInternalType( |
59
|
|
|
'string', |
60
|
|
|
$instance->getLastError() |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testGetLastErrorCode() { |
65
|
|
|
|
66
|
|
|
$instance = new CurlRequest( curl_init() ); |
67
|
|
|
|
68
|
|
|
$this->assertInternalType( |
69
|
|
|
'integer', |
70
|
|
|
$instance->getLastErrorCode() |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testExecuteForNullUrl() { |
75
|
|
|
|
76
|
|
|
$instance = new CurlRequest( curl_init( null ) ); |
77
|
|
|
$instance->setOption( CURLOPT_RETURNTRANSFER, true ); |
78
|
|
|
|
79
|
|
|
$this->assertTrue( |
80
|
|
|
$instance->getOption( CURLOPT_RETURNTRANSFER ) |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$this->assertFalse( |
84
|
|
|
$instance->execute() |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
$this->assertNull( |
88
|
|
|
$instance->getOption( CURLOPT_RETURNTRANSFER ) |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$this->assertEmpty( |
92
|
|
|
$instance->getLastTransferInfo( CURLINFO_HTTP_CODE ) |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testSetOptionUsingOnoiSpecificConstantDoesNotCauseAnyFailureWithCurl_Setopt() { |
97
|
|
|
|
98
|
|
|
$instance = new CurlRequest( curl_init( null ) ); |
99
|
|
|
$instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, 42 ); |
100
|
|
|
|
101
|
|
|
$this->assertEquals( |
102
|
|
|
42, |
103
|
|
|
$instance->getOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL ) |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|