Skip to content

Commit

Permalink
test: add test for network error
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 16, 2024
1 parent e8727de commit 624291d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/feature/BasicPagesTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

use App\Libraries\GitHub;
use CodeIgniter\Test\DatabaseTestTrait;
use CodeIgniter\Test\FeatureTestTrait;
use Config\Services;
use Tests\Support\ProjectTestCase;

/**
Expand All @@ -20,6 +22,32 @@ public function testCanViewHome()
$result->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 GuzzleHttp\Exception\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 GuzzleHttp\Psr7\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');
Expand Down

0 comments on commit 624291d

Please sign in to comment.