Skip to content

Commit

Permalink
Add tests for BadResponseException from guzzle without response objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed May 6, 2016
1 parent c8c4a75 commit 00db46f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/HttpClient/Guzzle5HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Jsor\HalClient\HttpClient;

use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use GuzzleHttp\Exception\BadResponseException as GuzzleBadResponseException;
use GuzzleHttp\Exception\RequestException as GuzzleRequestException;
use GuzzleHttp\Message\Request as GuzzleRequest;
use GuzzleHttp\Message\Response as GuzzleResponse;
Expand Down Expand Up @@ -142,4 +143,37 @@ public function it_will_transform_exception_with_404_response()

$client->request('GET', '/');
}

/**
* @test
* @expectedException \Jsor\HalClient\Exception\BadResponseException
*/
public function it_will_transform_bad_response_exception_without_response()
{
$guzzleRequest = new GuzzleRequest('GET', '/', []);

$guzzleClient = $this->getMock('GuzzleHttp\ClientInterface');

$guzzleClient
->expects($this->once())
->method('createRequest')
->will($this->returnValue($guzzleRequest));

$guzzleClient
->expects($this->once())
->method('send')
->will($this->returnCallback(function ($request) {
throw new GuzzleBadResponseException(
'Error',
$request
);
}));

$client = new HalClient(
'http://propilex.herokuapp.com',
new Guzzle5HttpClient($guzzleClient)
);

$client->request('GET', '/');
}
}
27 changes: 27 additions & 0 deletions tests/HttpClient/Guzzle6HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Jsor\HalClient\HttpClient;

use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use GuzzleHttp\Exception\BadResponseException as GuzzleBadResponseException;
use GuzzleHttp\Exception\RequestException as GuzzleRequestException;
use GuzzleHttp\Psr7\Response;
use Jsor\HalClient\HalClient;
Expand Down Expand Up @@ -114,4 +115,30 @@ public function it_will_transform_exception_with_404_response()

$client->request('GET', '/');
}

/**
* @test
* @expectedException \Jsor\HalClient\Exception\BadResponseException
*/
public function it_will_transform_bad_response_exception_without_response()
{
$guzzleClient = $this->getMock('GuzzleHttp\ClientInterface');

$guzzleClient
->expects($this->once())
->method('send')
->will($this->returnCallback(function ($request) {
throw new GuzzleBadResponseException(
'Error',
$request
);
}));

$client = new HalClient(
'http://propilex.herokuapp.com',
new Guzzle6HttpClient($guzzleClient)
);

$client->request('GET', '/');
}
}

0 comments on commit 00db46f

Please sign in to comment.