From 8e3060617f25bb0b31d23a524ca02b0deff8b2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Thu, 3 Oct 2019 17:17:59 +0200 Subject: [PATCH 1/3] Add $params to files from pull request --- lib/Github/Api/PullRequest.php | 9 +++-- test/Github/Tests/Api/PullRequestTest.php | 40 ++++++++++++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 1f22137afbd..ca11c8882a1 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -90,9 +90,14 @@ public function commits($username, $repository, $id) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits'); } - public function files($username, $repository, $id) + public function files($username, $repository, $id, array $params = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files'); + $parameters = array_merge([ + 'page' => 1, + 'per_page' => 30, + ], $params); + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files', $parameters); } /** diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 3f2acceb913..31f1625e258 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -97,12 +97,28 @@ public function shouldShowFilesFromPullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls/15/files') + ->with('/repos/ezsystems/ezpublish/pulls/15/files', ['page' => 1, 'per_page' => 30]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->files('ezsystems', 'ezpublish', '15')); } + /** + * @test + */ + public function shouldShowFilesFromPullRequestForPage() + { + $expectedArray = [['id' => 'id', 'sha' => '123123']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/ezsystems/ezpublish/pulls/15/files', ['page' => 2, 'per_page' => 30]) + ->willReturn($expectedArray); + + $this->assertSame($expectedArray, $api->files('ezsystems', 'ezpublish', '15', ['page' => 2, 'per_page' => 30])); + } + /** * @test */ @@ -211,10 +227,10 @@ public function shouldMergePullRequestWithMergeMethod() public function shouldCreatePullRequestUsingTitle() { $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API', + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ]; $api = $this->getApiMock(); @@ -231,8 +247,8 @@ public function shouldCreatePullRequestUsingTitle() public function shouldCreatePullRequestUsingIssueId() { $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'issue' => 25, ]; @@ -251,9 +267,9 @@ public function shouldNotCreatePullRequestWithoutBase() { $this->expectException(MissingArgumentException::class); $data = [ - 'head' => 'virtualtestbranch', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API', + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ]; $api = $this->getApiMock(); @@ -270,9 +286,9 @@ public function shouldNotCreatePullRequestWithoutHead() { $this->expectException(MissingArgumentException::class); $data = [ - 'base' => 'master', + 'base' => 'master', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API', + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ]; $api = $this->getApiMock(); @@ -289,8 +305,8 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() { $this->expectException(MissingArgumentException::class); $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', ]; From fad45b075eec20f0c06051461384864e2f271fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Thu, 10 Oct 2019 18:31:56 +0200 Subject: [PATCH 2/3] Do not set the default values for requests --- lib/Github/Api/PullRequest.php | 16 +++------------- test/Github/Tests/Api/PullRequestTest.php | 6 +++--- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index ca11c8882a1..fbb763dc5bf 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -55,17 +55,12 @@ public function configure($bodyType = null, $apiVersion = null) * * @param string $username the username * @param string $repository the repository - * @param array $params a list of extra parameters. + * @param array $parameters a list of extra parameters. * * @return array array of pull requests for the project */ - public function all($username, $repository, array $params = []) + public function all($username, $repository, array $parameters = []) { - $parameters = array_merge([ - 'page' => 1, - 'per_page' => 30, - ], $params); - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); } @@ -90,13 +85,8 @@ public function commits($username, $repository, $id) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits'); } - public function files($username, $repository, $id, array $params = []) + public function files($username, $repository, $id, array $parameters = []) { - $parameters = array_merge([ - 'page' => 1, - 'per_page' => 30, - ], $params); - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files', $parameters); } diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 31f1625e258..49be44fbf2f 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -32,7 +32,7 @@ public function shouldGetOpenPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'open', 'per_page' => 30, 'page' => 1]) + ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'open']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', ['state' => 'open'])); @@ -48,7 +48,7 @@ public function shouldGetClosedPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'closed', 'per_page' => 30, 'page' => 1]) + ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'closed']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', ['state' => 'closed'])); @@ -97,7 +97,7 @@ public function shouldShowFilesFromPullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls/15/files', ['page' => 1, 'per_page' => 30]) + ->with('/repos/ezsystems/ezpublish/pulls/15/files') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->files('ezsystems', 'ezpublish', '15')); From b718781d931b5b6db7af9493504408fc434e89e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Thu, 10 Oct 2019 19:52:09 +0200 Subject: [PATCH 3/3] Trigger Travis