diff --git a/app/Controllers/Contribute.php b/app/Controllers/Contribute.php index cd976775..8fdff2e9 100644 --- a/app/Controllers/Contribute.php +++ b/app/Controllers/Contribute.php @@ -2,7 +2,7 @@ namespace App\Controllers; -use Github\Exception\ExceptionInterface; +use Psr\Http\Client\ClientExceptionInterface; class Contribute extends BaseController { @@ -16,7 +16,9 @@ public function index() // Contributors are already sorted, so grab the first 12 $data['contributors'][$id] = array_slice($contributors, 0, 12); } - } catch (ExceptionInterface $e) { + } catch (ClientExceptionInterface $e) { + log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + $data['contributors'] = null; } diff --git a/app/Controllers/Download.php b/app/Controllers/Download.php index 0bcfe437..c1e01de7 100644 --- a/app/Controllers/Download.php +++ b/app/Controllers/Download.php @@ -2,7 +2,7 @@ namespace App\Controllers; -use Github\Exception\ExceptionInterface; +use Psr\Http\Client\ClientExceptionInterface; class Download extends BaseController { @@ -18,7 +18,9 @@ public function index() 'v3link' => end($releases['framework3'])->download_url, 'v4link' => end($releases['framework4'])->download_url, ]; - } catch (ExceptionInterface $e) { + } catch (ClientExceptionInterface $e) { + log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + $data = [ 'v3name' => 'unknown', 'v4name' => 'unknown', diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 610f063e..cd4f63be 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -2,7 +2,7 @@ namespace App\Controllers; -use Github\Exception\ExceptionInterface; +use Psr\Http\Client\ClientExceptionInterface; class Home extends BaseController { @@ -17,7 +17,9 @@ public function index() 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count), ]; - } catch (ExceptionInterface $e) { + } catch (ClientExceptionInterface $e) { + log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + $data = [ 'html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', diff --git a/tests/feature/BasicPagesTest.php b/tests/feature/BasicPagesTest.php index 4a52da30..df13be5f 100644 --- a/tests/feature/BasicPagesTest.php +++ b/tests/feature/BasicPagesTest.php @@ -1,7 +1,11 @@ assertSee('The small framework with powerful features'); } + public function testCanViewHomeWhenConnectException() + { + $github = $this->getMockBuilder(GitHub::class) + ->disableOriginalConstructor() + ->disableOriginalClone() + ->disableArgumentCloning() + ->disallowMockingUnknownTypes() + ->onlyMethods(['getRepos']) + ->getMock(); + $github->method('getRepos')->willThrowException( + new ConnectException( + 'cURL error 6: Could not resolve host: api.github.com (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.github.com/repos/bcit-ci/CodeIgniter', + new Request( + 'GET', + 'https://api.github.com/repos/bcit-ci/CodeIgniter' + ) + ) + ); + Services::injectMock('github', $github); + + $result = $this->get('/'); + + $result->assertStatus(200); + $result->assertSee('The small framework with powerful features'); + } + public function testCanViewDiscuss() { $result = $this->get('/discuss');