Skip to content

Commit 798fd9d

Browse files
committed
Fixed/improve tests. Added new composer autoload.php for test to avoid
DEPRECIATED message
1 parent 9a8afa5 commit 798fd9d

File tree

7 files changed

+278
-48
lines changed

7 files changed

+278
-48
lines changed

lib/Github/Api/Issue.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@ class Issue extends Api
1818
* @param string $username the username
1919
* @param string $repo the repo
2020
* @param string $state the issue state, can be open or closed
21+
* @param array $state the additional parameters like milestone, assignee, lables, sort, direction
2122
* @return array list of issues found
2223
*/
23-
public function getList($username, $repo, $state = 'open')
24+
public function getList($username, $repo, $state = null, $parameters = array())
2425
{
25-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues?state='.urlencode($state));
26+
$url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/issues';
27+
if ($state) {
28+
$parameters['state'] = $state;
29+
}
30+
if ($parameters) {
31+
$url .= '?'.http_build_query($parameters);
32+
}
33+
34+
return $this->get($url);
2635
}
2736

2837
/**
2938
* Search issues by username, repo, state and search term
30-
* http://develop.github.com/p/issues.html#list_a_projects_issues
3139
*
3240
* @param string $username the username
3341
* @param string $repo the repo
@@ -88,7 +96,7 @@ public function open($username, $repo, $title, $body)
8896

8997
/**
9098
* Close an existing issue by username, repo and issue number. Requires authentication.
91-
* http://develop.github.com/p/issues.html#open_and_close_issues
99+
* @link http://developer.github.com/v3/issues/
92100
*
93101
* @param string $username the username
94102
* @param string $repo the repo
@@ -102,7 +110,7 @@ public function close($username, $repo, $number)
102110

103111
/**
104112
* Update issue informations by username, repo and issue number. Requires authentication.
105-
* http://develop.github.com/p/issues.html#edit_existing_issues
113+
* @link http://developer.github.com/v3/issues/
106114
*
107115
* @param string $username the username
108116
* @param string $repo the repo
@@ -113,12 +121,12 @@ public function close($username, $repo, $number)
113121
*/
114122
public function update($username, $repo, $number, array $data)
115123
{
116-
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number), $data);
124+
return $this->patch('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number), $data);
117125
}
118126

119127
/**
120128
* Repoen an existing issue by username, repo and issue number. Requires authentication.
121-
* http://develop.github.com/p/issues.html#open_and_close_issues
129+
* @link http://developer.github.com/v3/issues/
122130
*
123131
* @param string $username the username
124132
* @param string $repo the repo
@@ -132,7 +140,7 @@ public function reOpen($username, $repo, $number)
132140

133141
/**
134142
* List an issue comments by username, repo and issue number
135-
* http://develop.github.com/p/issues.html#list_an_issues_comments
143+
* @link http://developer.github.com/v3/issues/comments/
136144
*
137145
* @param string $username the username
138146
* @param string $repo the repo
@@ -150,13 +158,12 @@ public function getComments($username, $repo, $number)
150158
*
151159
* @param string $username the username
152160
* @param string $repo the repo
153-
* @param string $number the issue number
154161
* @param string $id the comment id
155162
* @return array list of issue comments
156163
*/
157-
public function getComment($username, $repo, $number, $id)
164+
public function getComment($username, $repo, $id)
158165
{
159-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number).'/comments/'.urlencode($id));
166+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/comments/'.urlencode($id));
160167
}
161168

162169
/**

lib/Github/Api/PullRequest.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ class PullRequest extends Api
2121
* The API seems to automatically default to 'open'
2222
* @return array array of pull requests for the project
2323
*/
24-
public function listPullRequests($username, $repo, $state = 'open')
24+
public function listPullRequests($username, $repo, $state = null)
2525
{
26-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls?state='.urlencode($state));
26+
$url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/pulls';
27+
if ($state) {
28+
$url .= '?state='.urlencode($state);
29+
}
30+
31+
return $this->get($url);
2732
}
2833

2934
/**
@@ -43,7 +48,7 @@ public function show($username, $repo, $id)
4348
/**
4449
* Create a pull request
4550
*
46-
* @link http://develop.github.com/p/pulls.html
51+
* @link http://developer.github.com/v3/pulls/
4752
* @param string $username the username
4853
* @param string $repo the repo
4954
* @param string $base A String of the branch or commit SHA that you want your changes to be pulled to.
@@ -52,15 +57,23 @@ public function show($username, $repo, $id)
5257
* specify the username first: "my-user:some-branch".
5358
* @param string $title The String title of the Pull Request. Used in pair with $body.
5459
* @param string $body The String body of the Pull Request. Used in pair with $title.
60+
* @param string $issueNumber The issue number. Used when title and body is not set.
5561
* @return array array of pull requests for the project
5662
*/
57-
public function create($username, $repo, $base, $head, $title, $body = null)
63+
public function create($username, $repo, $base, $head, $title, $body = null, $issueNumber = null)
5864
{
59-
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls', array(
65+
$input = array(
6066
'head' => $head,
6167
'base' => $base,
62-
'title' => $title,
63-
'body' => $body,
64-
));
68+
);
69+
70+
if ($title || $body) {
71+
$input['title'] = $title;
72+
$input['body'] = $body;
73+
} else {
74+
$input['issue'] = $issueNumber;
75+
}
76+
77+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls', $input);
6578
}
6679
}

test/Github/Tests/Api/IssueTest.php

Lines changed: 192 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,207 @@
66

77
class IssueTest extends ApiTestCase
88
{
9-
public function testGetList()
9+
/**
10+
* @test
11+
*/
12+
public function shouldBuildValidQueryForGetList()
1013
{
1114
$api = $this->getApiMock();
1215

1316
$api->expects($this->once())
1417
->method('get')
15-
->with('issues/list/ornicar/php-github-api/open');
18+
->with('repos/ornicar/php-github-api/issues?state=open');
1619

1720
$api->getList('ornicar', 'php-github-api', 'open');
1821
}
1922

23+
/**
24+
* @test
25+
*/
26+
public function shouldBuildValidQueryForGetListWithAdditionalParameters()
27+
{
28+
$api = $this->getApiMock();
29+
30+
$api->expects($this->once())
31+
->method('get')
32+
->with('repos/ornicar/php-github-api/issues?milestone=%2A&assignee=l3l0&mentioned=l3l0&labels=bug%2C%40high&sort=created&direction=asc&state=open');
33+
34+
$api->getList('ornicar', 'php-github-api', 'open', array(
35+
'milestone' => '*',
36+
'assignee' => 'l3l0',
37+
'mentioned' => 'l3l0',
38+
'labels' => 'bug,@high',
39+
'sort' => 'created',
40+
'direction' => 'asc'
41+
));
42+
}
43+
44+
/**
45+
* @test
46+
*/
47+
public function shouldBuildValidQueryForShow()
48+
{
49+
$api = $this->getApiMock();
50+
51+
$api->expects($this->once())
52+
->method('get')
53+
->with('repos/ornicar/php-github-api/issues/14');
54+
55+
$api->show('ornicar', 'php-github-api', 14);
56+
}
57+
58+
/**
59+
* @test
60+
*/
61+
public function shouldBuildValidQueryForOpen()
62+
{
63+
$api = $this->getApiMock();
64+
65+
$api->expects($this->once())
66+
->method('post')
67+
->with('repos/ornicar/php-github-api/issues', array(
68+
'title' => 'some title',
69+
'body' => 'some body'
70+
));
71+
72+
$api->open('ornicar', 'php-github-api', 'some title', 'some body');
73+
}
74+
75+
/**
76+
* @test
77+
*/
78+
public function shouldBuildValidQueryForClose()
79+
{
80+
$api = $this->getApiMock();
81+
82+
$api->expects($this->once())
83+
->method('patch')
84+
->with('repos/ornicar/php-github-api/issues/14', array(
85+
'state' => 'closed',
86+
));
87+
88+
$api->close('ornicar', 'php-github-api', 14);
89+
}
90+
91+
/**
92+
* @test
93+
*/
94+
public function shouldBuildValidQueryForReOpen()
95+
{
96+
$api = $this->getApiMock();
97+
98+
$api->expects($this->once())
99+
->method('patch')
100+
->with('repos/ornicar/php-github-api/issues/14', array(
101+
'state' => 'open',
102+
));
103+
104+
$api->reOpen('ornicar', 'php-github-api', 14);
105+
}
106+
107+
/**
108+
* @test
109+
*/
110+
public function shouldBuildValidQueryForGetComments()
111+
{
112+
$api = $this->getApiMock();
113+
114+
$api->expects($this->once())
115+
->method('get')
116+
->with('repos/ornicar/php-github-api/issues/14/comments');
117+
118+
$api->getComments('ornicar', 'php-github-api', 14);
119+
}
120+
121+
/**
122+
* @test
123+
*/
124+
public function shouldBuildValidQueryForGetComment()
125+
{
126+
$api = $this->getApiMock();
127+
128+
$api->expects($this->once())
129+
->method('get')
130+
->with('repos/ornicar/php-github-api/issues/comments/666');
131+
132+
$api->getComment('ornicar', 'php-github-api', 666);
133+
}
134+
135+
/**
136+
* @test
137+
*/
138+
public function shouldBuildValidQueryForAddComment()
139+
{
140+
$api = $this->getApiMock();
141+
142+
$api->expects($this->once())
143+
->method('post')
144+
->with('repos/ornicar/php-github-api/issues/14/comments', array(
145+
'body' => 'some body'
146+
));
147+
148+
$api->addComment('ornicar', 'php-github-api', 14, 'some body');
149+
}
150+
151+
/**
152+
* @test
153+
*/
154+
public function shouldBuildValidQueryForGetLabels()
155+
{
156+
$api = $this->getApiMock();
157+
158+
$api->expects($this->once())
159+
->method('get')
160+
->with('repos/ornicar/php-github-api/labels');
161+
162+
$api->getLabels('ornicar', 'php-github-api');
163+
}
164+
165+
/**
166+
* @test
167+
*/
168+
public function shouldBuildValidQueryForGetLabel()
169+
{
170+
$api = $this->getApiMock();
171+
172+
$api->expects($this->once())
173+
->method('get')
174+
->with('repos/ornicar/php-github-api/labels/my-label');
175+
176+
$api->getLabel('ornicar', 'php-github-api', 'my-label');
177+
}
178+
179+
/**
180+
* @test
181+
*/
182+
public function shouldBuildValidQueryForAddLabel()
183+
{
184+
$api = $this->getApiMock();
185+
186+
$api->expects($this->once())
187+
->method('post')
188+
->with('repos/ornicar/php-github-api/labels', array(
189+
'name' => 'my-label',
190+
'color' => 'FFFFFF'
191+
));
192+
193+
$api->addLabel('ornicar', 'php-github-api', 'my-label', 'FFFFFF');
194+
}
195+
196+
/**
197+
* @test
198+
*/
199+
public function shouldBuildValidQueryForRemoveLabel()
200+
{
201+
$api = $this->getApiMock();
202+
203+
$api->expects($this->once())
204+
->method('delete')
205+
->with('repos/ornicar/php-github-api/labels/my-label');
206+
207+
$api->removeLabel('ornicar', 'php-github-api', 'my-label');
208+
}
209+
20210
protected function getApiClass()
21211
{
22212
return 'Github\Api\Issue';

0 commit comments

Comments
 (0)