Repository navigation
Expand file tree
/
Copy pathClientTest.php
More file actions
147 lines (119 loc) · 4.1 KB
/
Copy pathClientTest.php
File metadata and controls
147 lines (119 loc) · 4.1 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace Github\Tests;
use Github\Client;
use Github\HttpClient\Listener\AuthListener;
use Github\Exception\InvalidArgumentException;
class ClientTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function shouldNotHaveToPassHttpClientToConstructor()
{
$client = new Client();
$this->assertInstanceOf('Github\HttpClient\HttpClient', $client->getHttpClient());
}
/**
* @test
*/
public function shouldPassHttpClientInterfaceToConstructor()
{
$client = new Client($this->getHttpClientMock());
$this->assertInstanceOf('Github\HttpClient\HttpClientInterface', $client->getHttpClient());
}
/**
* @test
* @dataProvider getAuthenticationData
*/
public function shouldAuthenticateUsingGivenParameters($login, $password, $method)
{
$httpClient = $this->getHttpClientMock(array('addListener'));
$httpClient->expects($this->once())
->method('addListener')
->with(new AuthListener($method, array('tokenOrLogin' => $login, 'password' => $password)));
$client = new Client($httpClient);
$client->authenticate($login, $password, $method);
}
public function getAuthenticationData()
{
return array(
array('login', null, null),
array('login', 'password', Client::AUTH_HTTP_PASSWORD),
array('token', null, Client::AUTH_HTTP_TOKEN),
array('token', null, Client::AUTH_URL_TOKEN),
array('client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID),
);
}
/**
* @test
*/
public function shouldClearHeadersLazy()
{
$httpClient = $this->getHttpClientMock(array('clearHeaders'));
$httpClient->expects($this->once())->method('clearHeaders');
$client = new Client($httpClient);
$client->clearHeaders();
}
/**
* @test
*/
public function shouldSetHeadersLaizly()
{
$headers = array('header1', 'header2');
$httpClient = $this->getHttpClientMock();
$httpClient->expects($this->once())->method('setHeaders')->with($headers);
$client = new Client($httpClient);
$client->setHeaders($headers);
}
/**
* @test
* @dataProvider getApiClassesProvider
*/
public function shouldGetApiInstance($apiName, $class)
{
$client = new Client();
$this->assertInstanceOf($class, $client->api($apiName));
}
/**
* @test
* @expectedException InvalidArgumentException
*/
public function shouldNotGetApiInstance()
{
$client = new Client();
$client->api('do_not_exist');
}
public function getApiClassesProvider()
{
return array(
array('user', 'Github\Api\User'),
array('users', 'Github\Api\User'),
array('me', 'Github\Api\CurrentUser'),
array('current_user', 'Github\Api\CurrentUser'),
array('git', 'Github\Api\GitData'),
array('git_data', 'Github\Api\GitData'),
array('gist', 'Github\Api\Gists'),
array('gists', 'Github\Api\Gists'),
array('issue', 'Github\Api\Issue'),
array('issues', 'Github\Api\Issue'),
array('markdown', 'Github\Api\Markdown'),
array('organization', 'Github\Api\Organization'),
array('organizations', 'Github\Api\Organization'),
array('repo', 'Github\Api\Repo'),
array('repos', 'Github\Api\Repo'),
array('repository', 'Github\Api\Repo'),
array('repositories', 'Github\Api\Repo'),
array('pr', 'Github\Api\PullRequest'),
array('pull_request', 'Github\Api\PullRequest'),
array('pull_requests', 'Github\Api\PullRequest'),
);
}
public function getHttpClientMock(array $methods = array())
{
$methods = array_merge(
array('get', 'post', 'patch', 'put', 'delete', 'request', 'setOption', 'setHeaders'),
$methods
);
return $this->getMock('Github\HttpClient\HttpClientInterface', $methods);
}
}