Skip to content

Commit 3db6f27

Browse files
authored
feature #1132 Fix type error in ResultPager::fetch (nunoplopes)
This PR was merged into the 3.14-dev branch. Discussion ---------- When using etags, the reply from github may be empty and the underlying APIs will return an empty string. We need to flip those to empty arrays. e.g.: ```php $github_builder ->addPlugin(new Http\Client\Common\Plugin\HeaderSetPlugin([ 'If-None-Match' => $etag, ])); $api = $github_client->user('user'); $paginator = new \Github\ResultPager($github_client); $data = $paginator->fetch($api, 'events', [$username]); // $data should be [] if $etag is the latest ``` Commits ------- 773747a Fix type error in ResultPager::fetch
2 parents a6f0f4f + 773747a commit 3db6f27

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Github/ResultPager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function fetch(AbstractApi $api, string $method, array $parameters = []):
8686
$api = $closure($api);
8787
$result = $api->$method(...$parameters);
8888

89-
if ($result === '' && $this->client->getLastResponse()->getStatusCode() === 204) {
89+
if ($result === '') {
9090
$result = [];
9191
}
9292

test/Github/Tests/ResultPagerTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Github\Api\Repo;
88
use Github\Api\Repository\Statuses;
99
use Github\Api\Search;
10+
use Github\Api\User;
1011
use Github\Client;
1112
use Github\ResultPager;
1213
use Github\Tests\Mock\PaginatedResponse;
@@ -176,6 +177,29 @@ public function testFetch()
176177
$this->assertEquals($result, $paginator->fetch($api, $method, $parameters));
177178
}
178179

180+
public function testEmptyFetch()
181+
{
182+
$parameters = ['username'];
183+
$api = $this->getMockBuilder(User::class)
184+
->disableOriginalConstructor()
185+
->onlyMethods(['events'])
186+
->getMock();
187+
$api->expects($this->once())
188+
->method('events')
189+
->with(...$parameters)
190+
->willReturn('');
191+
192+
$paginator = $this->getMockBuilder(ResultPager::class)
193+
->disableOriginalConstructor()
194+
->onlyMethods(['postFetch'])
195+
->getMock();
196+
197+
$paginator->expects($this->once())
198+
->method('postFetch');
199+
200+
$this->assertEquals([], $paginator->fetch($api, 'events', $parameters));
201+
}
202+
179203
public function testFetchAllPreserveKeys()
180204
{
181205
$content = [

0 commit comments

Comments
 (0)