Skip to content

Commit

Permalink
Improve code coverage for exception handling
Browse files Browse the repository at this point in the history
In the new guzzle version ConnectException does not extend RequestException anymore, so our testcase was not testing the path it was supposed to.
  • Loading branch information
darthmaim committed May 10, 2023
1 parent 2cd7391 commit 5f35a74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/V2/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function getSchema() {
* @param string $method
* @param array $options
* @return ApiResponse
* @throws ApiException|GuzzleException
*/
protected function request( array $query = [], $url = null, $method = 'GET', $options = [] ) {
$request = $this->createRequest( $query, $url, $method, $options );
Expand Down
10 changes: 5 additions & 5 deletions tests/ApiExceptionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;
Expand Down Expand Up @@ -62,10 +62,10 @@ public function testUnknownException() {
/**
*/
public function testRequestExceptionWithoutResponse() {
$this->expectException(\GuzzleHttp\Exception\ConnectException::class, 'RequestExceptionWithoutResponse');
$this->expectException(RequestException::class, 'RequestExceptionWithoutResponse');

$this->mockResponse(
new ConnectException('RequestExceptionWithoutResponse', new Request('GET', 'test/exception'))
new RequestException('RequestExceptionWithoutResponse', new Request('GET', 'test/exception'))
);

$this->getEndpoint()->test();
Expand All @@ -75,14 +75,14 @@ public function testRequestExceptionWithoutResponse() {
/**
*/
public function testRequestManyExceptionWithoutResponse() {
$this->expectException(\GuzzleHttp\Exception\ConnectException::class, 'RequestManyExceptionWithoutResponse');
$this->expectException(RequestException::class, 'RequestManyExceptionWithoutResponse');

$this->mockResponse( new Response(
200, [ 'X-Result-Total' => 10, 'Content-Type' => 'application/json; charset=utf-8' ],
Utils::streamFor( '[1,2,3]' )
));
$this->mockResponse(
new ConnectException('RequestManyExceptionWithoutResponse', new Request('GET', 'test/exception'))
new RequestException('RequestManyExceptionWithoutResponse', new Request('GET', 'test/exception'))
);

$this->getEndpoint()->testMany(2);
Expand Down

0 comments on commit 5f35a74

Please sign in to comment.