|
2 | 2 |
|
3 | 3 | namespace Github\Tests\HttpClient; |
4 | 4 |
|
| 5 | +use Github\Client; |
5 | 6 | use Github\HttpClient\HttpClient; |
6 | 7 | use Github\HttpClient\Message\Request; |
7 | 8 | use Github\HttpClient\Message\Response; |
@@ -32,6 +33,29 @@ public function shouldBeAbleToSetOption() |
32 | 33 | $this->assertEquals(666, $httpClient->getOption('timeout')); |
33 | 34 | } |
34 | 35 |
|
| 36 | + /** |
| 37 | + * @test |
| 38 | + * @dataProvider getAuthenticationFullData |
| 39 | + */ |
| 40 | + public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) |
| 41 | + { |
| 42 | + $client = new TestHttpClient(); |
| 43 | + $client->authenticate($login, $password, $method); |
| 44 | + |
| 45 | + $this->assertCount(2, $client->listeners); |
| 46 | + $this->assertInstanceOf('Github\HttpClient\Listener\AuthListener', $client->listeners['Github\HttpClient\Listener\AuthListener']); |
| 47 | + } |
| 48 | + |
| 49 | + public function getAuthenticationFullData() |
| 50 | + { |
| 51 | + return array( |
| 52 | + array('login', 'password', Client::AUTH_HTTP_PASSWORD), |
| 53 | + array('token', null, Client::AUTH_HTTP_TOKEN), |
| 54 | + array('token', null, Client::AUTH_URL_TOKEN), |
| 55 | + array('client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID), |
| 56 | + ); |
| 57 | + } |
| 58 | + |
35 | 59 | /** |
36 | 60 | * @test |
37 | 61 | */ |
@@ -186,15 +210,22 @@ public function shouldThrowExceptionWhenApiIsExceeded() |
186 | 210 | $httpClient->get($path, $parameters, $headers); |
187 | 211 | } |
188 | 212 |
|
189 | | - protected function getBrowserMock() |
| 213 | + protected function getBrowserMock(array $methods = array()) |
190 | 214 | { |
191 | | - return $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')); |
| 215 | + return $this->getMock( |
| 216 | + 'Buzz\Client\ClientInterface', |
| 217 | + array_merge( |
| 218 | + array('setTimeout', 'setVerifyPeer', 'send'), |
| 219 | + $methods |
| 220 | + ) |
| 221 | + ); |
192 | 222 | } |
193 | 223 | } |
194 | 224 |
|
195 | 225 | class TestHttpClient extends HttpClient |
196 | 226 | { |
197 | 227 | public $fakeResponse; |
| 228 | + public $listeners; |
198 | 229 |
|
199 | 230 | public function getOption($name, $default = null) |
200 | 231 | { |
|
0 commit comments