Repository navigation
Expand file tree
/
Copy pathHttpClientTest.php
More file actions
96 lines (81 loc) · 2.8 KB
/
Copy pathHttpClientTest.php
File metadata and controls
96 lines (81 loc) · 2.8 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
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
class Github_Tests_HttpClientTest extends PHPUnit_Framework_TestCase
{
public function testInstanciateWithOptions()
{
$httpClient = new Github_HttpClient_TestDriver(array(
'timeout' => 33
));
$this->assertEquals(33, $httpClient->getOption('timeout'));
$this->assertEquals(80, $httpClient->getOption('http_port'));
}
public function testGet()
{
$path = '/some/path';
$parameters = array('a' => 'b');
$options = array('c' => 'd');
$httpClient = $this->getHttpClientMockBuilder()
->setMethods(array('doRequest', 'request'))
->getMock();
$httpClient->expects($this->once())
->method('request')
->with($path, $parameters, 'GET', $options);
$httpClient->get($path, $parameters, $options);
}
public function testPost()
{
$path = '/some/path';
$parameters = array('a' => 'b');
$options = array('c' => 'd');
$httpClient = $this->getHttpClientMockBuilder()
->setMethods(array('doRequest', 'request'))
->getMock();
$httpClient->expects($this->once())
->method('request')
->with($path, $parameters, 'POST', $options);
$httpClient->post($path, $parameters, $options);
}
public function testRequest()
{
$path = '/some/path';
$parameters = array('a' => 'b');
$method = 'GET';
$options = array('c' => 'd');
$httpClient = $this->getHttpClientMockBuilder()
->setMethods(array('doRequest', 'updateHistory', 'decodeResponse'))
->getMock();
$httpClient->expects($this->once())
->method('updateHistory')
->with();
$httpClient->expects($this->once())
->method('doRequest')
->will($this->returnValue('response'));
$httpClient->expects($this->once())
->method('decodeResponse')
->with('response')
->will($this->returnValue(array('response')));
$response = $httpClient->request($path, $parameters, $method, $options);
$this->assertSame(array('response'), $response);
}
protected function getHttpClientMockBuilder()
{
return $this->getMockBuilder('Github_HttpClient');
}
}
class Github_HttpClient_TestDriver extends Github_HttpClient
{
protected function doRequest($url, array $parameters = array(), $httpMethod = 'GET', array $options = array())
{
}
/**
* Get an option value.
*
* @param string $name The option name
*
* @return mixed The option value
*/
public function getOption($name, $default = null)
{
return isset($this->options[$name]) ? $this->options[$name] : $default;
}
}