Skip to content

Commit

Permalink
Test added to cover Guzzle RequestException
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Oct 26, 2018
1 parent 3df6445 commit 53f627a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

namespace TK\Test\Unit;

use TK\SDK\Exception\RequestException;
use TK\SDK\Client;
use TK\SDK\ValueObject\Factory\RetrieveReservationDetailParametersFactory;
use TK\SDK\ClientBuilder;
use TK\Test\Unit\Resources\ExampleEndpoint;
use Dotenv;
use ReflectionMethod;

class ClientTest extends \Codeception\Test\Unit
{
Expand All @@ -14,6 +18,9 @@ class ClientTest extends \Codeception\Test\Unit
*/
protected $tester;

/**
* @var Client
*/
private $client;

protected function _before()
Expand Down Expand Up @@ -67,4 +74,17 @@ public function shouldThrowExceptionForInvalidArgument() : void
{
$this->client->retrieveReservationDetail([]);
}

/**
* @test
* @expectedException \TK\SDK\Exception\RequestException
*/
public function shouldThrowExceptionForGuzzleRequestError() : void
{
$endpoint = new ExampleEndpoint();

$httpRequest = new ReflectionMethod($this->client, 'httpRequest');
$httpRequest->setAccessible(true);
$httpRequest->invoke($this->client, $endpoint);
}
}
17 changes: 17 additions & 0 deletions tests/unit/Resources/ExampleEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace TK\Test\Unit\Resources;

use TK\SDK\Endpoint\EndpointAbstract;
use TK\SDK\Endpoint\EndpointInterface;

class ExampleEndpoint extends EndpointAbstract implements EndpointInterface
{
public function __construct()
{
$this->endpoint = '/nonExistedEndpoint';
$this->responseRoot = 'none';
$this->queryParameters = [];
}
}

0 comments on commit 53f627a

Please sign in to comment.