Skip to content

Commit

Permalink
Improve to can specify parameters on issue comments api. (#815)
Browse files Browse the repository at this point in the history
* Improve to can specify properties on issue comments api.

(cherry picked from commit 9900b21)

* fix typo.

* Add message which tell deprecated.
  • Loading branch information
t-kuni authored and acrobat committed Nov 1, 2019
1 parent de9322c commit 157bd55
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/Github/Api/Issue/Comments.php
Expand Up @@ -41,18 +41,25 @@ public function configure($bodyType = null)
*
* @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
*
* @param string $username
* @param string $repository
* @param int $issue
* @param int $page
* @param string $username
* @param string $repository
* @param int $issue
* @param int|array $page Passing integer is deprecated and will throw an exception in php-github-api version 3.0. Pass an array instead.
*
* @return array
*/
public function all($username, $repository, $issue, $page = 1)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', [
'page' => $page,
]);
if (is_array($page)) {
$parameters = $page;
} else {
@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);
$parameters = [
'page' => $page,
];
}

return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $parameters);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/Github/Tests/Api/Issue/CommentsTest.php
Expand Up @@ -23,6 +23,24 @@ public function shouldGetAllIssueComments()
$this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123));
}

/**
* @test
*/
public function shouldGetAllIssueCommentsBySpecifyParameters()
{
$expectedValue = [['comment1data'], ['comment2data']];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/issues/123/comments', ['since' => '1990-08-03T00:00:00Z'])
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123, [
'since' => '1990-08-03T00:00:00Z',
]));
}

/**
* @test
*/
Expand Down

0 comments on commit 157bd55

Please sign in to comment.