Skip to content
This repository was archived by the owner on May 1, 2019. It is now read-only.

Commit a71a432

Browse files
committed
Update RepositoryRetriever to catch EdpGithub exception and return false
1 parent 61fd11f commit a71a432

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

module/Application/src/Application/Service/RepositoryRetriever.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ public function getUserRepositoryMetadata($user, $module)
4646
* @param string $user
4747
* @param array $params
4848
*
49-
* @return RepositoryCollection
49+
* @return RepositoryCollection|bool
5050
*/
5151
public function getUserRepositories($user, $params = [])
5252
{
53-
return $this->githubClient->api('user')->repos($user, $params);
53+
try {
54+
return $this->githubClient->api('user')->repos($user, $params);
55+
}
56+
catch (RuntimeException $e) {
57+
return false;
58+
}
5459
}
5560

5661
/**
@@ -140,10 +145,15 @@ public function getRepositoryFileMetadata($user, $module, $filePath)
140145
*
141146
* @param array $params
142147
*
143-
* @return RepositoryCollection
148+
* @return RepositoryCollection|bool
144149
*/
145150
public function getAuthenticatedUserRepositories($params = [])
146151
{
147-
return $this->githubClient->api('current_user')->repos($params);
152+
try {
153+
return $this->githubClient->api('current_user')->repos($params);
154+
}
155+
catch (RuntimeException $e) {
156+
return false;
157+
}
148158
}
149159
}

module/Application/test/ApplicationTest/Service/RepositoryRetrieverTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ public function testCanRetrieveUserRepositories()
4545
$this->assertEquals(count($payload), $count);
4646
}
4747

48+
public function testGetUserRepositoriesReturnsFalseOnRemoteFailure()
49+
{
50+
$client = $this->getClientMock(
51+
new Api\User(),
52+
[]
53+
);
54+
$client->expects($this->any())
55+
->method('api')
56+
->willThrowException(new Exception\RuntimeException());
57+
58+
$service = new RepositoryRetriever($client);
59+
60+
$repositories = $service->getUserRepositories('foo');
61+
$this->assertFalse($repositories);
62+
}
63+
4864
public function testCanRetrieveUserRepositoryMetadata()
4965
{
5066
$payload = [
@@ -202,6 +218,22 @@ public function testCanRetrieveAuthenticatedUserRepositories()
202218
$this->assertEquals(count($payload), $count);
203219
}
204220

221+
public function testGetAuthenticatedUserRepositoriesReturnsFalseOnRemoteFailure()
222+
{
223+
$client = $this->getClientMock(
224+
new Api\CurrentUser(),
225+
[]
226+
);
227+
$client->expects($this->any())
228+
->method('api')
229+
->willThrowException(new Exception\RuntimeException());
230+
231+
$service = new RepositoryRetriever($client);
232+
233+
$repositories = $service->getAuthenticatedUserRepositories();
234+
$this->assertFalse($repositories);
235+
}
236+
205237
public function testRepositoryFileContentFails()
206238
{
207239
$clientMock = $this->getMock('EdpGithub\Client');

0 commit comments

Comments
 (0)