From 25bdb5c1878a59de7e62a81f7ba86711f1af4e54 Mon Sep 17 00:00:00 2001 From: Kayla Daniels Date: Wed, 25 Mar 2015 21:17:51 -0400 Subject: [PATCH 1/2] Added support for gist comments --- lib/Github/Api/Gist/Comments.php | 44 +++++++++ lib/Github/Api/Gists.php | 15 +++- test/Github/Tests/Api/Gist/CommentsTest.php | 98 +++++++++++++++++++++ test/Github/Tests/Api/GistsTest.php | 10 +++ 4 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 lib/Github/Api/Gist/Comments.php create mode 100644 test/Github/Tests/Api/Gist/CommentsTest.php diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php new file mode 100644 index 00000000000..3e10caddf40 --- /dev/null +++ b/lib/Github/Api/Gist/Comments.php @@ -0,0 +1,44 @@ + + * @author Edoardo Rivello + */ +class Comments extends AbstractApi +{ + // GET /gists/:gist_id/comments + public function all($gist) + { + return $this->get('gists/'.rawurlencode($gist)."/comments"); + } + + //GET /gists/:gist_id/comments/:id + public function show($gist, $comment) + { + return $this->get('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); + } + + //POST /gists/:gist_id/comments + public function create($gist, $body) + { + return $this->post('gists/'.rawurlencode($gist)."/comments", array($body)); + } + + //PATCH /gists/:gist_id/comments/:id + public function update($gist, $comment_id, $body) + { + return $this->patch('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment_id), array($body)); + } + + //DELETE /gists/:gist_id/comments/:id + public function remove($gist, $comment) + { + return $this->delete('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment)); + } +} diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 12fe9ec5d00..442774fac83 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -2,8 +2,8 @@ namespace Github\Api; -use Github\Api\AbstractApi; use Github\Exception\MissingArgumentException; +use Github\Api\Gist\Comments; /** * Creating, editing, deleting and listing gists. @@ -73,4 +73,17 @@ public function unstar($id) { return $this->delete('gists/'.rawurlencode($id).'/star'); } + + /** + * List an gists comments. + * + * @link http://developer.github.com/v3/gists/comments/ + * + * @return Comments + */ + public function comments() + { + return new Comments($this->client); + } + } diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php new file mode 100644 index 00000000000..0055f6f95f1 --- /dev/null +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -0,0 +1,98 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('gists/123/comments') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('123')); + } + + /** + * @test + */ + public function shouldShowGistComment() + { + $expectedValue = array('comment1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('gists/123/comments/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show(123, 123)); + } + + + /** + * @test + */ + public function shouldCreateGistComment() + { + $expectedValue = array('comment1data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('gists/123/comments', array("Test body")) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('123', "Test body")); + } + + + /** + * @test + */ + public function shouldUpdateGistComment() + { + $expectedValue = array('comment1data'); + $data = array('body test'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('gists/123/comments/233', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update(123, 233, 'body test')); + } + + /** + * @test + */ + public function shouldRemoveComment() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('gists/123/comments/233') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove(123, 233)); + } + + protected function getApiClass() + { + return 'Github\Api\Gist\Comments'; + } +} diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 8a01dca3ddd..aa53b0f6176 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -68,6 +68,16 @@ public function shouldShowCommits() $this->assertEquals($expectedArray, $api->commits(123)); } + /** + * @test + */ + public function shouldGetCommentsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Gist\Comments', $api->comments()); + } + /** * @test */ From 6bbe4d819b58aeb9e247745e47f4e483837fdc18 Mon Sep 17 00:00:00 2001 From: Kayla Daniels Date: Wed, 25 Mar 2015 21:17:51 -0400 Subject: [PATCH 2/2] Added support for gist comments --- lib/Github/Api/Gist/Comments.php | 17 +++++------------ lib/Github/Api/Gists.php | 3 +-- test/Github/Tests/Api/Gist/CommentsTest.php | 10 +++------- test/Github/Tests/Api/GistsTest.php | 2 +- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index 3e10caddf40..2d889650015 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -5,40 +5,33 @@ use Github\Api\AbstractApi; /** - * * @link https://developer.github.com/v3/gists/comments/ * @author Kayla Daniels - * @author Edoardo Rivello */ class Comments extends AbstractApi { - // GET /gists/:gist_id/comments public function all($gist) { - return $this->get('gists/'.rawurlencode($gist)."/comments"); + return $this->get('gists/'.rawurlencode($gist).'/comments'); } - //GET /gists/:gist_id/comments/:id public function show($gist, $comment) { return $this->get('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); } - //POST /gists/:gist_id/comments public function create($gist, $body) { - return $this->post('gists/'.rawurlencode($gist)."/comments", array($body)); + return $this->post('gists/'.rawurlencode($gist).'/comments', array($body)); } - //PATCH /gists/:gist_id/comments/:id public function update($gist, $comment_id, $body) { - return $this->patch('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment_id), array($body)); + return $this->patch('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array($body)); } - //DELETE /gists/:gist_id/comments/:id public function remove($gist, $comment) { - return $this->delete('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment)); + return $this->delete('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); } -} +} \ No newline at end of file diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 442774fac83..eb24f0b3fdf 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -75,7 +75,7 @@ public function unstar($id) } /** - * List an gists comments. + * Get a gist's comments. * * @link http://developer.github.com/v3/gists/comments/ * @@ -85,5 +85,4 @@ public function comments() { return new Comments($this->client); } - } diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php index 0055f6f95f1..77f3ca50faa 100644 --- a/test/Github/Tests/Api/Gist/CommentsTest.php +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -9,8 +9,6 @@ class CommentsTest extends TestCase /** * @test */ - -// GET /gists/:gist_id/comments public function shouldGetAllGistComments() { $expectedValue = array(array('comment1data'), array('comment2data')); @@ -40,7 +38,6 @@ public function shouldShowGistComment() $this->assertEquals($expectedValue, $api->show(123, 123)); } - /** * @test */ @@ -51,13 +48,12 @@ public function shouldCreateGistComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('gists/123/comments', array("Test body")) + ->with('gists/123/comments', array('Test body')) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->create('123', "Test body")); + $this->assertEquals($expectedValue, $api->create('123', 'Test body')); } - /** * @test */ @@ -95,4 +91,4 @@ protected function getApiClass() { return 'Github\Api\Gist\Comments'; } -} +} \ No newline at end of file diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index aa53b0f6176..4d2cdf7f346 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -226,4 +226,4 @@ protected function getApiClass() { return 'Github\Api\Gists'; } -} +} \ No newline at end of file