Repository navigation
Expand file tree
/
Copy pathCurlTest.php
More file actions
83 lines (66 loc) · 3.12 KB
/
Copy pathCurlTest.php
File metadata and controls
83 lines (66 loc) · 3.12 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
<?php
class Github_Tests_HttpClient_CurlTest extends PHPUnit_Framework_TestCase
{
public function testDoRequest()
{
$url = 'http://site.com/some/path';
$curlResponse = array('headers' => array('http_code' => 200), 'response' => 'hi there', 'errorNumber' => '', 'errorMessage' => '');
$options = array('format' => 'text');
$httpClient = $this->getHttpClientCurlMockBuilder()
->setMethods(array('doCurlCall'))
->getMock();
$httpClient->expects($this->once())
->method('doCurlCall')
->will($this->returnValue($curlResponse));
$responseText = $httpClient->get($url, array(), $options);
$this->assertEquals($curlResponse['response'], $responseText);
}
public function testDoAuthenticatedRequest()
{
$url = 'http://site.com/some/path';
$curlResponse = array('headers' => array('http_code' => 200), 'response' => 'hi there', 'errorNumber' => '', 'errorMessage' => '');
$options = array('format' => 'text', 'login' => 'mylogin', 'secret' => 'mysecret', 'auth_method' => Github_Client::AUTH_URL_TOKEN);
$httpClient = $this->getHttpClientCurlMockBuilder()
->setMethods(array('doCurlCall'))
->getMock();
$httpClient->expects($this->once())
->method('doCurlCall')
->will($this->returnValue($curlResponse));
$responseText = $httpClient->get($url, array(), $options);
$this->assertEquals($curlResponse['response'], $responseText);
}
public function testDoGetRequestWithParameters()
{
$url = 'http://site.com/some/path';
$curlResponse = array('headers' => array('http_code' => 200), 'response' => 'hi there', 'errorNumber' => '', 'errorMessage' => '');
$params = array('a' => 'b');
$options = array('format' => 'text');
$httpClient = $this->getHttpClientCurlMockBuilder()
->setMethods(array('doCurlCall'))
->getMock();
$httpClient->expects($this->once())
->method('doCurlCall')
->will($this->returnValue($curlResponse));
$responseText = $httpClient->get($url, $params, $options);
$this->assertEquals($curlResponse['response'], $responseText);
}
public function testDoPostRequestWithParameters()
{
$url = 'http://site.com/some/path';
$curlResponse = array('headers' => array('http_code' => 200), 'response' => 'hi there', 'errorNumber' => '', 'errorMessage' => '');
$params = array('a' => 'b');
$options = array('format' => 'text');
$httpClient = $this->getHttpClientCurlMockBuilder()
->setMethods(array('doCurlCall'))
->getMock();
$httpClient->expects($this->once())
->method('doCurlCall')
->will($this->returnValue($curlResponse));
$responseText = $httpClient->post($url, $params, $options);
$this->assertEquals($curlResponse['response'], $responseText);
}
protected function getHttpClientCurlMockBuilder()
{
return $this->getMockBuilder('Github_HttpClient_Curl');
}
}