Skip to content

Commit 488ada5

Browse files
committed
Fix repository comments to latest API changes, add some functional tests for it.
1 parent 2265581 commit 488ada5

File tree

3 files changed

+128
-36
lines changed

3 files changed

+128
-36
lines changed

lib/Github/Api/Repository/Comments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function show($username, $repository, $comment)
4949

5050
public function create($username, $repository, $sha, array $params)
5151
{
52-
if (!isset($params['body'], $params['path'], $params['position'])) {
53-
throw new MissingArgumentException(array('body', 'path', 'position'));
52+
if (!isset($params['body'])) {
53+
throw new MissingArgumentException('body');
5454
}
5555

5656
return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/commits/'.urlencode($sha).'/comments', $params);

test/Github/Tests/Api/Repository/CommentsTest.php

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Github\Tests\Api\TestCase;
66

77
/**
8-
* Repository comments api test case
8+
* Repository comments api test case
99
*
1010
* @author Leszek Prabucki <leszek.prabucki@gmail.com>
1111
*/
@@ -37,10 +37,10 @@ public function shouldGetSpecificCommitRepositoryComments()
3737
$api = $this->getApiMock();
3838
$api->expects($this->once())
3939
->method('get')
40-
->with('repos/KnpLabs/php-github-api/commits/123456/comments')
40+
->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/comments')
4141
->will($this->returnValue($expectedValue));
4242

43-
$this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', '123456'));
43+
$this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 'commitSHA123456'));
4444
}
4545

4646
/**
@@ -74,36 +74,6 @@ public function shouldNotCreateWithoutBody()
7474
$api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data);
7575
}
7676

77-
/**
78-
* @test
79-
* @expectedException Github\Exception\MissingArgumentException
80-
*/
81-
public function shouldNotCreateWithoutPath()
82-
{
83-
$data = array('body' => 'body', 'line' => 11, 'position' => 2);
84-
85-
$api = $this->getApiMock();
86-
$api->expects($this->never())
87-
->method('post');
88-
89-
$api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data);
90-
}
91-
92-
/**
93-
* @test
94-
* @expectedException Github\Exception\MissingArgumentException
95-
*/
96-
public function shouldNotCreateWithoutPosition()
97-
{
98-
$data = array('body' => 'body', 'path' => 'test.php', 'line' => 2);
99-
100-
$api = $this->getApiMock();
101-
$api->expects($this->never())
102-
->method('post');
103-
104-
$api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data);
105-
}
106-
10777
/**
10878
* @test
10979
*/
@@ -165,7 +135,7 @@ public function shouldUpdateComment()
165135
->with('repos/KnpLabs/php-github-api/comments/123', $data)
166136
->will($this->returnValue($expectedValue));
167137

168-
$this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', '123', $data));
138+
$this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data));
169139
}
170140

171141
/**
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
namespace Github\Tests\Functional;
4+
5+
class RepoCommentTest extends TestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldRetrieveComments()
11+
{
12+
$username = 'fabpot';
13+
$repo = 'Twig';
14+
15+
$comments = $this->client->api('repo')->comments()->all($username, $repo);
16+
$comment = array_pop($comments);
17+
18+
$this->assertArrayHasKey('line', $comment);
19+
$this->assertArrayHasKey('body', $comment);
20+
$this->assertArrayHasKey('user', $comment);
21+
$this->assertArrayHasKey('created_at', $comment);
22+
$this->assertArrayHasKey('id', $comment);
23+
$this->assertArrayHasKey('url', $comment);
24+
}
25+
26+
/**
27+
* @test
28+
*/
29+
public function shouldRetrieveCommentsForCommit()
30+
{
31+
$username = 'fabpot';
32+
$repo = 'Twig';
33+
$sha = '3506cfad1d946f4a87e8c55849a18044efe2d5dc';
34+
35+
$comments = $this->client->api('repo')->comments()->all($username, $repo, $sha);
36+
$comment = array_pop($comments);
37+
38+
$this->assertArrayHasKey('line', $comment);
39+
$this->assertArrayHasKey('body', $comment);
40+
$this->assertArrayHasKey('user', $comment);
41+
$this->assertArrayHasKey('created_at', $comment);
42+
$this->assertArrayHasKey('id', $comment);
43+
$this->assertArrayHasKey('url', $comment);
44+
}
45+
46+
/**
47+
* @test
48+
*/
49+
public function shouldCreateCommentForCommit()
50+
{
51+
$username = 'KnpLabs';
52+
$repo = 'php-github-api';
53+
$sha = '22655813eb54e7d4e21545e396f919bcd245b50d';
54+
$params = array('body' => '%');
55+
56+
$comment = $this->client->api('repo')->comments()->create($username, $repo, $sha, $params);
57+
58+
$this->assertArrayHasKey('created_at', $comment);
59+
$this->assertArrayHasKey('updated_at', $comment);
60+
$this->assertArrayHasKey('url', $comment);
61+
$this->assertArrayHasKey('id', $comment);
62+
$this->assertArrayHasKey('body', $comment);
63+
$this->assertArrayHasKey('user', $comment);
64+
65+
return $comment['id'];
66+
}
67+
68+
/**
69+
* @test
70+
* @depends shouldCreateCommentForCommit
71+
*/
72+
public function shouldShowCommentByCommentId($commentId)
73+
{
74+
$username = 'KnpLabs';
75+
$repo = 'php-github-api';
76+
77+
$comment = $this->client->api('repo')->comments()->show($username, $repo, $commentId);
78+
79+
$this->assertArrayHasKey('created_at', $comment);
80+
$this->assertArrayHasKey('updated_at', $comment);
81+
$this->assertArrayHasKey('url', $comment);
82+
$this->assertArrayHasKey('id', $comment);
83+
$this->assertArrayHasKey('body', $comment);
84+
$this->assertArrayHasKey('user', $comment);
85+
86+
return $comment['id'];
87+
}
88+
89+
/**
90+
* @test
91+
* @depends shouldShowCommentByCommentId
92+
*/
93+
public function shouldUpdateCommentByCommentId($commentId)
94+
{
95+
$username = 'KnpLabs';
96+
$repo = 'php-github-api';
97+
$params = array('body' => 'test update');
98+
99+
$comment = $this->client->api('repo')->comments()->update($username, $repo, $commentId, $params);
100+
101+
$this->assertArrayHasKey('created_at', $comment);
102+
$this->assertArrayHasKey('updated_at', $comment);
103+
$this->assertArrayHasKey('url', $comment);
104+
$this->assertArrayHasKey('id', $comment);
105+
$this->assertArrayHasKey('body', $comment);
106+
$this->assertArrayHasKey('user', $comment);
107+
108+
return $comment['id'];
109+
}
110+
111+
/**
112+
* @test
113+
* @depends shouldUpdateCommentByCommentId
114+
*/
115+
public function shouldRemoveCommentByCommentId($commentId)
116+
{
117+
$username = 'KnpLabs';
118+
$repo = 'php-github-api';
119+
120+
$this->client->api('repo')->comments()->remove($username, $repo, $commentId);
121+
}
122+
}

0 commit comments

Comments
 (0)