|
4 | 4 |
|
5 | 5 | use Github\Api\Issue;
|
6 | 6 | use Github\Api\Organization\Members;
|
| 7 | +use Github\Api\Repo; |
7 | 8 | use Github\Api\Repository\Statuses;
|
8 | 9 | use Github\Api\Search;
|
9 | 10 | use Github\Client;
|
@@ -116,6 +117,40 @@ public function shouldGetAllSearchResults()
|
116 | 117 | $this->assertCount($amountLoops * count($content['items']), $result);
|
117 | 118 | }
|
118 | 119 |
|
| 120 | + /** |
| 121 | + * @test |
| 122 | + */ |
| 123 | + public function shouldHandleEmptyContributorListWith204Header() |
| 124 | + { |
| 125 | + // Set up a 204 response with an empty body |
| 126 | + $response = new Response(204, [], ''); |
| 127 | + $username = 'testuser'; |
| 128 | + $reponame = 'testrepo'; |
| 129 | + |
| 130 | + // Mock the HttpClient to return the empty response |
| 131 | + $httpClientMock = $this->getMockBuilder(HttpClient::class) |
| 132 | + ->onlyMethods(['sendRequest']) |
| 133 | + ->getMock(); |
| 134 | + $httpClientMock |
| 135 | + ->method('sendRequest') |
| 136 | + ->willReturn($response); |
| 137 | + |
| 138 | + $client = Client::createWithHttpClient($httpClientMock); |
| 139 | + |
| 140 | + $repoApi = new Repo($client); |
| 141 | + |
| 142 | + $paginator = $this->getMockBuilder(ResultPager::class) |
| 143 | + ->setConstructorArgs([$client]) // Pass the Client in the constructor |
| 144 | + ->onlyMethods(['fetchAll']) |
| 145 | + ->getMock(); |
| 146 | + $paginator->expects($this->once()) |
| 147 | + ->method('fetchAll') |
| 148 | + ->with($repoApi, 'contributors', [$username, $reponame]) |
| 149 | + ->willReturn([]); |
| 150 | + |
| 151 | + $this->assertEquals([], $paginator->fetchAll($repoApi, 'contributors', [$username, $reponame])); |
| 152 | + } |
| 153 | + |
119 | 154 | public function testFetch()
|
120 | 155 | {
|
121 | 156 | $result = ['foo'];
|
@@ -201,6 +236,34 @@ public function testFetchAllWithoutKeys()
|
201 | 236 | $this->assertCount(9, $result);
|
202 | 237 | }
|
203 | 238 |
|
| 239 | + public function testFetchAll() |
| 240 | + { |
| 241 | + $content = [ |
| 242 | + ['title' => 'issue 1'], |
| 243 | + ['title' => 'issue 2'], |
| 244 | + ['title' => 'issue 3'], |
| 245 | + ]; |
| 246 | + |
| 247 | + $response = new PaginatedResponse(3, $content); |
| 248 | + |
| 249 | + // httpClient mock |
| 250 | + $httpClientMock = $this->getMockBuilder(HttpClient::class) |
| 251 | + ->onlyMethods(['sendRequest']) |
| 252 | + ->getMock(); |
| 253 | + $httpClientMock |
| 254 | + ->expects($this->exactly(3)) |
| 255 | + ->method('sendRequest') |
| 256 | + ->willReturn($response); |
| 257 | + |
| 258 | + $client = Client::createWithHttpClient($httpClientMock); |
| 259 | + |
| 260 | + $api = new Issue($client); |
| 261 | + $paginator = new ResultPager($client); |
| 262 | + $result = $paginator->fetchAll($api, 'all', ['knplabs', 'php-github-api']); |
| 263 | + |
| 264 | + $this->assertCount(9, $result); |
| 265 | + } |
| 266 | + |
204 | 267 | /**
|
205 | 268 | * @group legacy
|
206 | 269 | */
|
|
0 commit comments