Skip to content

Commit 4363f6f

Browse files
committed
Extend issue comments to latest API changes, add some functional tests for it.
1 parent 488ada5 commit 4363f6f

File tree

3 files changed

+125
-6
lines changed

3 files changed

+125
-6
lines changed

lib/Github/Api/Issue/Comments.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@
1111
*/
1212
class Comments extends AbstractApi
1313
{
14+
public function configure($bodyType = null)
15+
{
16+
switch ($bodyType) {
17+
case 'raw':
18+
$header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getOption('api_version'));
19+
break;
20+
21+
case 'text':
22+
$header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getOption('api_version'));
23+
break;
24+
25+
case 'html':
26+
$header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getOption('api_version'));
27+
break;
28+
29+
default:
30+
$header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getOption('api_version'));
31+
}
32+
33+
$this->client->setHeaders(array($header));
34+
}
35+
1436
public function all($username, $repository, $issue, $page = 1)
1537
{
1638
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/comments', array(
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
namespace Github\Tests\Functional;
4+
5+
class IssueCommentTest extends TestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldRetrieveCommentsForIssue()
11+
{
12+
$username = 'KnpLabs';
13+
$repo = 'php-github-api';
14+
$issue = 13;
15+
16+
$comments = $this->client->api('issue')->comments()->all($username, $repo, $issue);
17+
$comment = array_pop($comments);
18+
19+
$this->assertArrayHasKey('id', $comment);
20+
$this->assertArrayHasKey('url', $comment);
21+
$this->assertArrayHasKey('body', $comment);
22+
$this->assertArrayHasKey('user', $comment);
23+
$this->assertArrayHasKey('created_at', $comment);
24+
$this->assertArrayHasKey('updated_at', $comment);
25+
26+
return $comment['id'];
27+
}
28+
29+
/**
30+
* @test
31+
* @depends shouldRetrieveCommentsForIssue
32+
*/
33+
public function shouldRetrieveSingleComment($commentId)
34+
{
35+
$username = 'KnpLabs';
36+
$repo = 'php-github-api';
37+
38+
$comment = $this->client->api('issue')->comments()->show($username, $repo, $commentId);
39+
40+
$this->assertArrayHasKey('id', $comment);
41+
$this->assertArrayHasKey('url', $comment);
42+
$this->assertArrayHasKey('body', $comment);
43+
$this->assertArrayHasKey('user', $comment);
44+
$this->assertArrayHasKey('created_at', $comment);
45+
$this->assertArrayHasKey('updated_at', $comment);
46+
}
47+
48+
/**
49+
* @test
50+
*/
51+
public function shouldCreateCommentForIssue()
52+
{
53+
$username = 'KnpLabs';
54+
$repo = 'php-github-api';
55+
$issue = 13;
56+
$params = array('body' => '%');
57+
58+
$comment = $this->client->api('issue')->comments()->create($username, $repo, $issue, $params);
59+
60+
$this->assertArrayHasKey('id', $comment);
61+
$this->assertArrayHasKey('url', $comment);
62+
$this->assertArrayHasKey('body', $comment);
63+
$this->assertArrayHasKey('user', $comment);
64+
$this->assertArrayHasKey('created_at', $comment);
65+
$this->assertArrayHasKey('updated_at', $comment);
66+
67+
return $comment['id'];
68+
}
69+
/**
70+
* @test
71+
* @depends shouldCreateCommentForIssue
72+
*/
73+
public function shouldUpdateCommentByCommentId($commentId)
74+
{
75+
$username = 'KnpLabs';
76+
$repo = 'php-github-api';
77+
$params = array('body' => 'test update');
78+
79+
$comment = $this->client->api('issue')->comments()->update($username, $repo, $commentId, $params);
80+
81+
$this->assertArrayHasKey('id', $comment);
82+
$this->assertArrayHasKey('url', $comment);
83+
$this->assertArrayHasKey('body', $comment);
84+
$this->assertArrayHasKey('user', $comment);
85+
$this->assertArrayHasKey('created_at', $comment);
86+
$this->assertArrayHasKey('updated_at', $comment);
87+
88+
return $comment['id'];
89+
}
90+
91+
/**
92+
* @test
93+
* @depends shouldUpdateCommentByCommentId
94+
*/
95+
public function shouldRemoveCommentByCommentId($commentId)
96+
{
97+
$username = 'KnpLabs';
98+
$repo = 'php-github-api';
99+
100+
$this->client->api('issue')->comments()->remove($username, $repo, $commentId);
101+
}
102+
}

test/Github/Tests/Functional/UserTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ public function shouldGetFollowersUsers()
5757
{
5858
$username = 'KnpLabs';
5959

60-
$this->client = new Client();
61-
try {
62-
$users = $this->client->api('user')->followers($username);
63-
} catch (ApiLimitExceedException $e) {
64-
$this->markTestSkipped('API limit reached. Skipping to prevent unnecessary failure.');
65-
}
60+
$users = $this->client->api('user')->followers($username);
6661
$user = array_pop($users);
6762

6863
$this->assertArrayHasKey('id', $user);

0 commit comments

Comments
 (0)