Skip to content

Commit

Permalink
Add test for Toxiproxy->handleHttpClientException().
Browse files Browse the repository at this point in the history
  • Loading branch information
ihsw committed Jan 1, 2018
1 parent a3a6bc0 commit 8487251
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tests/ToxiproxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
namespace Ihsw\ToxyproxyTests\Integration;

use GuzzleHttp\Client as HttpClient;
use Ihsw\Toxiproxy\Proxy;
use GuzzleHttp\Exception\ClientException as HttpClientException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Ihsw\Toxiproxy\Test\AbstractTest;
use Ihsw\Toxiproxy\Toxiproxy;
use Ihsw\Toxiproxy\Proxy;
use Ihsw\Toxiproxy\Exception\InvalidToxicException;
use Ihsw\Toxiproxy\Exception\UnexpectedStatusCodeException;
use Ihsw\Toxiproxy\Exception\ProxyExistsException;
use Ihsw\Toxiproxy\Exception\NotFoundException;
use Ihsw\Toxiproxy\Exception\UnexpectedStatusCodeException;

class ToxiproxyTest extends AbstractTest
{
Expand Down Expand Up @@ -94,4 +98,20 @@ public function testDeleteNotFound()

$this->assertTrue(false);
}

public function testHandleHttpClientException()
{
$toxiproxy = $this->createToxiproxy();
$table = [
["status" => Toxiproxy::CONFLICT, "expected" => ProxyExistsException::class],
["status" => Toxiproxy::NOT_FOUND, "expected" => NotFoundException::class],
["status" => Toxiproxy::BAD_REQUEST, "expected" => InvalidToxicException::class],
["status" => -1, "expected" => UnexpectedStatusCodeException::class]
];

foreach ($table as $item) {
$e = new HttpClientException("", new Request("POST", "/"), new Response($item["status"]));
$this->assertInstanceOf($item["expected"], $toxiproxy->handleHttpClientException($e));
}
}
}

0 comments on commit 8487251

Please sign in to comment.