Skip to content

Commit 157bd55

Browse files
t-kuniacrobat
authored andcommitted
Improve to can specify parameters on issue comments api. (#815)
* Improve to can specify properties on issue comments api. (cherry picked from commit 9900b21) * fix typo. * Add message which tell deprecated.
1 parent de9322c commit 157bd55

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

lib/Github/Api/Issue/Comments.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,25 @@ public function configure($bodyType = null)
4141
*
4242
* @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
4343
*
44-
* @param string $username
45-
* @param string $repository
46-
* @param int $issue
47-
* @param int $page
44+
* @param string $username
45+
* @param string $repository
46+
* @param int $issue
47+
* @param int|array $page Passing integer is deprecated and will throw an exception in php-github-api version 3.0. Pass an array instead.
4848
*
4949
* @return array
5050
*/
5151
public function all($username, $repository, $issue, $page = 1)
5252
{
53-
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', [
54-
'page' => $page,
55-
]);
53+
if (is_array($page)) {
54+
$parameters = $page;
55+
} else {
56+
@trigger_error(sprintf('Passing integer to the "page" argument in "%s" is deprecated and will throw an exception in php-github-api version 3.0. Pass an array instead.', __METHOD__), E_USER_DEPRECATED);
57+
$parameters = [
58+
'page' => $page,
59+
];
60+
}
61+
62+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $parameters);
5663
}
5764

5865
/**

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ public function shouldGetAllIssueComments()
2323
$this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123));
2424
}
2525

26+
/**
27+
* @test
28+
*/
29+
public function shouldGetAllIssueCommentsBySpecifyParameters()
30+
{
31+
$expectedValue = [['comment1data'], ['comment2data']];
32+
33+
$api = $this->getApiMock();
34+
$api->expects($this->once())
35+
->method('get')
36+
->with('/repos/KnpLabs/php-github-api/issues/123/comments', ['since' => '1990-08-03T00:00:00Z'])
37+
->will($this->returnValue($expectedValue));
38+
39+
$this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123, [
40+
'since' => '1990-08-03T00:00:00Z',
41+
]));
42+
}
43+
2644
/**
2745
* @test
2846
*/

0 commit comments

Comments
 (0)