Skip to content

Gist comments #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions lib/Github/Api/Gist/Comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Github\Api\Gist;

use Github\Api\AbstractApi;

/**
* @link https://developer.github.com/v3/gists/comments/
* @author Kayla Daniels <kayladnls@gmail.com>
*/
class Comments extends AbstractApi
{
public function all($gist)
{
return $this->get('gists/'.rawurlencode($gist).'/comments');
}

public function show($gist, $comment)
{
return $this->get('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment));
}

public function create($gist, $body)
{
return $this->post('gists/'.rawurlencode($gist).'/comments', array($body));
}

public function update($gist, $comment_id, $body)
{
return $this->patch('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array($body));
}

public function remove($gist, $comment)
{
return $this->delete('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment));
}
}
14 changes: 13 additions & 1 deletion lib/Github/Api/Gists.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -73,4 +73,16 @@ public function unstar($id)
{
return $this->delete('gists/'.rawurlencode($id).'/star');
}

/**
* Get a gist's comments.
*
* @link http://developer.github.com/v3/gists/comments/
*
* @return Comments
*/
public function comments()
{
return new Comments($this->client);
}
}
94 changes: 94 additions & 0 deletions test/Github/Tests/Api/Gist/CommentsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Github\Tests\Api\Gist;

use Github\Tests\Api\TestCase;

class CommentsTest extends TestCase
{
/**
* @test
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the phpdoc should be just above the method it documents

public function shouldGetAllGistComments()
{
$expectedValue = array(array('comment1data'), array('comment2data'));

$api = $this->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';
}
}
12 changes: 11 additions & 1 deletion test/Github/Tests/Api/GistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -216,4 +226,4 @@ protected function getApiClass()
{
return 'Github\Api\Gists';
}
}
}