Skip to content

Commit 838493d

Browse files
committed
Merge pull request #9 from l3l0/add-tests
Added unit tests
2 parents 15a9418 + 8ef3980 commit 838493d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+5464
-311
lines changed

lib/Github/Api/CurrentUser/Emails.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Emails extends AbstractApi
1313
{
1414
/**
1515
* List emails for the authenticated user
16-
* @link http://developer.github.com/v3/repos/emails/
16+
* @link http://developer.github.com/v3/users/emails/
1717
*
1818
* @return array
1919
*/
@@ -24,7 +24,7 @@ public function all()
2424

2525
/**
2626
* Adds one or more email for the authenticated user
27-
* @link http://developer.github.com/v3/repos/emails/
27+
* @link http://developer.github.com/v3/users/emails/
2828
*
2929
* @param string|array $emails
3030
* @return array
@@ -44,7 +44,7 @@ public function add($emails)
4444

4545
/**
4646
* Removes one or more email for the authenticated user
47-
* @link http://developer.github.com/v3/repos/emails/
47+
* @link http://developer.github.com/v3/users/emails/
4848
*
4949
* @param string|array $emails
5050
* @return array
@@ -59,6 +59,6 @@ public function remove($emails)
5959
throw new InvalidArgumentException();
6060
}
6161

62-
return $this->delete('user/emails/', $emails);
62+
return $this->delete('user/emails', $emails);
6363
}
6464
}

lib/Github/Api/Issue/Events.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Events extends AbstractApi
1212
{
1313
public function all($username, $repository, $issue = null, $page = 1)
1414
{
15-
if (null === $issue) {
15+
if (null !== $issue) {
1616
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/events', array(
1717
'page' => $page
1818
));

lib/Github/Api/Issue/Milestones.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class Milestones extends AbstractApi
1313
{
1414
public function all($username, $repository, array $params = array())
1515
{
16-
if (!in_array($params['state'], array('open', 'closed'))) {
16+
if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) {
1717
$params['state'] = 'open';
1818
}
19-
if (!in_array($params['sort'], array('due_date', 'completeness'))) {
19+
if (isset($params['sort']) && !in_array($params['sort'], array('due_date', 'completeness'))) {
2020
$params['sort'] = 'due_date';
2121
}
22-
if (!in_array($params['direction'], array('asc', 'desc'))) {
22+
if (isset($params['direction']) && !in_array($params['direction'], array('asc', 'desc'))) {
2323
$params['direction'] = 'desc';
2424
}
2525

lib/Github/Api/Repository/Contents.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class Contents extends AbstractApi
1313
{
1414
public function readme($username, $repository, $reference = null)
1515
{
16-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/contents/readme', array(
17-
'ref' => $reference
18-
));
16+
return $this->show($username, $repository, 'readme', $reference);
1917
}
2018

2119
public function show($username, $repository, $path, $reference = null)

lib/Github/HttpClient/HttpClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function authenticate()
8585
$this->browser->addListener(
8686
new AuthListener(
8787
$this->options['auth_method'],
88-
array($this->options['login'], $this->options['password'], $this->options['token'])
88+
array('login' => $this->options['login'], 'password' => $this->options['password'], 'token' => $this->options['token'])
8989
)
9090
);
9191
}
@@ -96,6 +96,8 @@ public function authenticate()
9696
public function setHeaders(array $headers)
9797
{
9898
$this->headers = $headers;
99+
100+
return $this;
99101
}
100102

101103
/**

lib/Github/HttpClient/HttpClientInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function setOption($name, $value);
8383
* Set HTTP headers
8484
*
8585
* @param array $headers
86+
* @return HttpClientInterface The current object instance
8687
*/
8788
public function setHeaders(array $headers);
8889
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?php
2+
3+
namespace Github\Tests\Api;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* AbstractApi test case
9+
*
10+
* @author Leszek Prabucki <[email protected]>
11+
*/
12+
class AbstractApiTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @test
16+
*/
17+
public function shouldPassGETRequestToClient()
18+
{
19+
$expectedArray = array('value');
20+
21+
$client = $this->getClientMock();
22+
$client
23+
->expects($this->once())
24+
->method('get')
25+
->with('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))
26+
->will($this->returnValue($expectedArray));
27+
28+
$api = $this->getAbstractApiObject($client);
29+
30+
$this->assertEquals($expectedArray, $api->get('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function shouldPassPOSTRequestToClient()
37+
{
38+
$expectedArray = array('value');
39+
40+
$client = $this->getClientMock();
41+
$client
42+
->expects($this->once())
43+
->method('post')
44+
->with('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))
45+
->will($this->returnValue($expectedArray));
46+
47+
$api = $this->getAbstractApiObject($client);
48+
49+
$this->assertEquals($expectedArray, $api->post('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
50+
}
51+
52+
/**
53+
* @test
54+
*/
55+
public function shouldPassPATCHRequestToClient()
56+
{
57+
$expectedArray = array('value');
58+
59+
$client = $this->getClientMock();
60+
$client
61+
->expects($this->once())
62+
->method('patch')
63+
->with('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))
64+
->will($this->returnValue($expectedArray));
65+
66+
$api = $this->getAbstractApiObject($client);
67+
68+
$this->assertEquals($expectedArray, $api->patch('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
69+
}
70+
71+
/**
72+
* @test
73+
*/
74+
public function shouldPassPUTRequestToClient()
75+
{
76+
$expectedArray = array('value');
77+
78+
$client = $this->getClientMock();
79+
$client
80+
->expects($this->once())
81+
->method('put')
82+
->with('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))
83+
->will($this->returnValue($expectedArray));
84+
85+
$api = $this->getAbstractApiObject($client);
86+
87+
$this->assertEquals($expectedArray, $api->put('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
88+
}
89+
90+
/**
91+
* @test
92+
*/
93+
public function shouldPassDELETERequestToClient()
94+
{
95+
$expectedArray = array('value');
96+
97+
$client = $this->getClientMock();
98+
$client
99+
->expects($this->once())
100+
->method('delete')
101+
->with('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))
102+
->will($this->returnValue($expectedArray));
103+
104+
$api = $this->getAbstractApiObject($client);
105+
106+
$this->assertEquals($expectedArray, $api->delete('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
107+
}
108+
109+
protected function getAbstractApiObject($client)
110+
{
111+
return new AbstractApiTestInstance($client);
112+
}
113+
114+
protected function getClientMock()
115+
{
116+
return $this->getMockBuilder('Github\Client')
117+
->disableOriginalConstructor()
118+
->getMock();
119+
}
120+
}
121+
122+
class AbstractApiTestInstance extends AbstractApi
123+
{
124+
/**
125+
* {@inheritDoc}
126+
*/
127+
public function get($path, array $parameters = array(), $requestOptions = array())
128+
{
129+
return parent::get($path, $parameters, $requestOptions);
130+
}
131+
132+
/**
133+
* {@inheritDoc}
134+
*/
135+
public function post($path, array $parameters = array(), $requestOptions = array())
136+
{
137+
return parent::post($path, $parameters, $requestOptions);
138+
}
139+
140+
/**
141+
* {@inheritDoc}
142+
*/
143+
public function patch($path, array $parameters = array(), $requestOptions = array())
144+
{
145+
return parent::patch($path, $parameters, $requestOptions);
146+
}
147+
148+
/**
149+
* {@inheritDoc}
150+
*/
151+
public function put($path, array $parameters = array(), $requestOptions = array())
152+
{
153+
return parent::put($path, $parameters, $requestOptions);
154+
}
155+
156+
/**
157+
* {@inheritDoc}
158+
*/
159+
public function delete($path, array $parameters = array(), $requestOptions = array())
160+
{
161+
return parent::delete($path, $parameters, $requestOptions);
162+
}
163+
}

test/Github/Tests/Api/CommitTest.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)