Permalink
Browse files

Fixed/improve tests. Added new composer autoload.php for test to avoid

DEPRECIATED message
  • Loading branch information...
l3l0 committed May 26, 2012
1 parent 9a8afa5 commit 798fd9d369335b561198f765278c5cafecddb726
View
@@ -18,16 +18,24 @@ class Issue extends Api
* @param string $username the username
* @param string $repo the repo
* @param string $state the issue state, can be open or closed
+ * @param array $state the additional parameters like milestone, assignee, lables, sort, direction
* @return array list of issues found
*/
- public function getList($username, $repo, $state = 'open')
+ public function getList($username, $repo, $state = null, $parameters = array())
{
- return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues?state='.urlencode($state));
+ $url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/issues';
+ if ($state) {
+ $parameters['state'] = $state;
+ }
+ if ($parameters) {
+ $url .= '?'.http_build_query($parameters);
+ }
+
+ return $this->get($url);
}
/**
* Search issues by username, repo, state and search term
- * http://develop.github.com/p/issues.html#list_a_projects_issues
*
* @param string $username the username
* @param string $repo the repo
@@ -88,7 +96,7 @@ public function open($username, $repo, $title, $body)
/**
* Close an existing issue by username, repo and issue number. Requires authentication.
- * http://develop.github.com/p/issues.html#open_and_close_issues
+ * @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repo the repo
@@ -102,7 +110,7 @@ public function close($username, $repo, $number)
/**
* Update issue informations by username, repo and issue number. Requires authentication.
- * http://develop.github.com/p/issues.html#edit_existing_issues
+ * @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repo the repo
@@ -113,12 +121,12 @@ public function close($username, $repo, $number)
*/
public function update($username, $repo, $number, array $data)
{
- return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number), $data);
+ return $this->patch('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number), $data);
}
/**
* Repoen an existing issue by username, repo and issue number. Requires authentication.
- * http://develop.github.com/p/issues.html#open_and_close_issues
+ * @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repo the repo
@@ -132,7 +140,7 @@ public function reOpen($username, $repo, $number)
/**
* List an issue comments by username, repo and issue number
- * http://develop.github.com/p/issues.html#list_an_issues_comments
+ * @link http://developer.github.com/v3/issues/comments/
*
* @param string $username the username
* @param string $repo the repo
@@ -150,13 +158,12 @@ public function getComments($username, $repo, $number)
*
* @param string $username the username
* @param string $repo the repo
- * @param string $number the issue number
* @param string $id the comment id
* @return array list of issue comments
*/
- public function getComment($username, $repo, $number, $id)
+ public function getComment($username, $repo, $id)
{
- return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number).'/comments/'.urlencode($id));
+ return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/comments/'.urlencode($id));
}
/**
@@ -21,9 +21,14 @@ class PullRequest extends Api
* The API seems to automatically default to 'open'
* @return array array of pull requests for the project
*/
- public function listPullRequests($username, $repo, $state = 'open')
+ public function listPullRequests($username, $repo, $state = null)
{
- return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls?state='.urlencode($state));
+ $url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/pulls';
+ if ($state) {
+ $url .= '?state='.urlencode($state);
+ }
+
+ return $this->get($url);
}
/**
@@ -43,7 +48,7 @@ public function show($username, $repo, $id)
/**
* Create a pull request
*
- * @link http://develop.github.com/p/pulls.html
+ * @link http://developer.github.com/v3/pulls/
* @param string $username the username
* @param string $repo the repo
* @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)
* specify the username first: "my-user:some-branch".
* @param string $title The String title of the Pull Request. Used in pair with $body.
* @param string $body The String body of the Pull Request. Used in pair with $title.
+ * @param string $issueNumber The issue number. Used when title and body is not set.
* @return array array of pull requests for the project
*/
- public function create($username, $repo, $base, $head, $title, $body = null)
+ public function create($username, $repo, $base, $head, $title, $body = null, $issueNumber = null)
{
- return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls', array(
+ $input = array(
'head' => $head,
'base' => $base,
- 'title' => $title,
- 'body' => $body,
- ));
+ );
+
+ if ($title || $body) {
+ $input['title'] = $title;
+ $input['body'] = $body;
+ } else {
+ $input['issue'] = $issueNumber;
+ }
+
+ return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls', $input);
}
}
@@ -6,17 +6,207 @@
class IssueTest extends ApiTestCase
{
- public function testGetList()
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForGetList()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
- ->with('issues/list/ornicar/php-github-api/open');
+ ->with('repos/ornicar/php-github-api/issues?state=open');
$api->getList('ornicar', 'php-github-api', 'open');
}
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForGetListWithAdditionalParameters()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('get')
+ ->with('repos/ornicar/php-github-api/issues?milestone=%2A&assignee=l3l0&mentioned=l3l0&labels=bug%2C%40high&sort=created&direction=asc&state=open');
+
+ $api->getList('ornicar', 'php-github-api', 'open', array(
+ 'milestone' => '*',
+ 'assignee' => 'l3l0',
+ 'mentioned' => 'l3l0',
+ 'labels' => 'bug,@high',
+ 'sort' => 'created',
+ 'direction' => 'asc'
+ ));
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForShow()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('get')
+ ->with('repos/ornicar/php-github-api/issues/14');
+
+ $api->show('ornicar', 'php-github-api', 14);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForOpen()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('post')
+ ->with('repos/ornicar/php-github-api/issues', array(
+ 'title' => 'some title',
+ 'body' => 'some body'
+ ));
+
+ $api->open('ornicar', 'php-github-api', 'some title', 'some body');
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForClose()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('patch')
+ ->with('repos/ornicar/php-github-api/issues/14', array(
+ 'state' => 'closed',
+ ));
+
+ $api->close('ornicar', 'php-github-api', 14);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForReOpen()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('patch')
+ ->with('repos/ornicar/php-github-api/issues/14', array(
+ 'state' => 'open',
+ ));
+
+ $api->reOpen('ornicar', 'php-github-api', 14);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForGetComments()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('get')
+ ->with('repos/ornicar/php-github-api/issues/14/comments');
+
+ $api->getComments('ornicar', 'php-github-api', 14);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForGetComment()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('get')
+ ->with('repos/ornicar/php-github-api/issues/comments/666');
+
+ $api->getComment('ornicar', 'php-github-api', 666);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForAddComment()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('post')
+ ->with('repos/ornicar/php-github-api/issues/14/comments', array(
+ 'body' => 'some body'
+ ));
+
+ $api->addComment('ornicar', 'php-github-api', 14, 'some body');
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForGetLabels()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('get')
+ ->with('repos/ornicar/php-github-api/labels');
+
+ $api->getLabels('ornicar', 'php-github-api');
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForGetLabel()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('get')
+ ->with('repos/ornicar/php-github-api/labels/my-label');
+
+ $api->getLabel('ornicar', 'php-github-api', 'my-label');
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForAddLabel()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('post')
+ ->with('repos/ornicar/php-github-api/labels', array(
+ 'name' => 'my-label',
+ 'color' => 'FFFFFF'
+ ));
+
+ $api->addLabel('ornicar', 'php-github-api', 'my-label', 'FFFFFF');
+ }
+
+ /**
+ * @test
+ */
+ public function shouldBuildValidQueryForRemoveLabel()
+ {
+ $api = $this->getApiMock();
+
+ $api->expects($this->once())
+ ->method('delete')
+ ->with('repos/ornicar/php-github-api/labels/my-label');
+
+ $api->removeLabel('ornicar', 'php-github-api', 'my-label');
+ }
+
protected function getApiClass()
{
return 'Github\Api\Issue';
Oops, something went wrong.

0 comments on commit 798fd9d

Please sign in to comment.