From 1824da16e4ac40174a2ea5a7c5a3ac2d0e6e5ba6 Mon Sep 17 00:00:00 2001 From: tig Date: Fri, 4 Oct 2019 10:26:21 +0900 Subject: [PATCH 1/3] Improve to can specify properties on issue comments api. (cherry picked from commit 9900b21a5670b7c6dbecb5b46d93302ca0d2ef89) --- lib/Github/Api/Issue/Comments.php | 20 +++++++++++++------- test/Github/Tests/Api/Issue/CommentsTest.php | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index a664d533274..5ba3c3addce 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -41,18 +41,24 @@ 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 * * @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 { + $parameters = [ + 'page' => $page, + ]; + } + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $parameters); } /** diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index 51c67fe8f85..48330fe3849 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -22,6 +22,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 */ From 1048364d3fc52c259bd35bcb813649444e9cfffc Mon Sep 17 00:00:00 2001 From: tig Date: Tue, 8 Oct 2019 21:11:11 +0900 Subject: [PATCH 2/3] fix typo. --- test/Github/Tests/Api/Issue/CommentsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index 48330fe3849..b99bf06390f 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -36,7 +36,7 @@ public function shouldGetAllIssueCommentsBySpecifyParameters() ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123, [ - 'since' => '1990-08-03T00:00:00Z' + 'since' => '1990-08-03T00:00:00Z', ])); } From 6b2f88d8ac4d5727b627d1d8399615dcd60b6835 Mon Sep 17 00:00:00 2001 From: tig Date: Fri, 18 Oct 2019 01:24:41 +0900 Subject: [PATCH 3/3] Add message which tell deprecated. --- lib/Github/Api/Issue/Comments.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 5ba3c3addce..7dd2c96e9d2 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -44,7 +44,7 @@ public function configure($bodyType = null) * @param string $username * @param string $repository * @param int $issue - * @param int|array $page + * @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 */ @@ -53,6 +53,7 @@ public function all($username, $repository, $issue, $page = 1) 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, ];