Skip to content

Commit 53f627a

Browse files
committed
Test added to cover Guzzle RequestException
1 parent 3df6445 commit 53f627a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

tests/unit/ClientTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33

44
namespace TK\Test\Unit;
55

6+
use TK\SDK\Exception\RequestException;
7+
use TK\SDK\Client;
68
use TK\SDK\ValueObject\Factory\RetrieveReservationDetailParametersFactory;
79
use TK\SDK\ClientBuilder;
10+
use TK\Test\Unit\Resources\ExampleEndpoint;
811
use Dotenv;
12+
use ReflectionMethod;
913

1014
class ClientTest extends \Codeception\Test\Unit
1115
{
@@ -14,6 +18,9 @@ class ClientTest extends \Codeception\Test\Unit
1418
*/
1519
protected $tester;
1620

21+
/**
22+
* @var Client
23+
*/
1724
private $client;
1825

1926
protected function _before()
@@ -67,4 +74,17 @@ public function shouldThrowExceptionForInvalidArgument() : void
6774
{
6875
$this->client->retrieveReservationDetail([]);
6976
}
77+
78+
/**
79+
* @test
80+
* @expectedException \TK\SDK\Exception\RequestException
81+
*/
82+
public function shouldThrowExceptionForGuzzleRequestError() : void
83+
{
84+
$endpoint = new ExampleEndpoint();
85+
86+
$httpRequest = new ReflectionMethod($this->client, 'httpRequest');
87+
$httpRequest->setAccessible(true);
88+
$httpRequest->invoke($this->client, $endpoint);
89+
}
7090
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace TK\Test\Unit\Resources;
5+
6+
use TK\SDK\Endpoint\EndpointAbstract;
7+
use TK\SDK\Endpoint\EndpointInterface;
8+
9+
class ExampleEndpoint extends EndpointAbstract implements EndpointInterface
10+
{
11+
public function __construct()
12+
{
13+
$this->endpoint = '/nonExistedEndpoint';
14+
$this->responseRoot = 'none';
15+
$this->queryParameters = [];
16+
}
17+
}

0 commit comments

Comments
 (0)