Skip to content

Commit

Permalink
Test that a 400 or 500 response is not a success
Browse files Browse the repository at this point in the history
Specifically this should not throw an exception
  • Loading branch information
Joel Dodge committed Aug 8, 2018
1 parent 3154756 commit b61c24a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ protected function make_request($url, $params = array(), $req_method = self::GET
'Accept' => 'application/json, text/javascript, */*; q=0.01',
'Content-Type' => 'application/vnd.api+json',
],
'http_errors' => false,
];

switch ($req_method) {
Expand Down
16 changes: 16 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public function testInvalidAccountId()
new \Drip\Client("abc123", "");
}

public function testErrorResponseReturned()
{
$mocked_requests = [];
$client = GuzzleHelpers::mocked_client($mocked_requests, [
// default client request option "http_errors" will throw
// GuzzleHttp\Exception\ClientException but we set it false so
// no exception is thrown.
new Response(401, [], '{"error":"hello"}'),
new Response(502, [], 'timeout'),
]);
$response401 = $client->fetch_campaign(['campaign_id' => 1]);
$this->assertFalse($response401->is_success());
$response502 = $client->fetch_campaign(['campaign_id' => 1]);
$this->assertFalse($response502->is_success());
}

////////////////////////// C A M P A I G N S //////////////////////////

// #get_campaigns
Expand Down

0 comments on commit b61c24a

Please sign in to comment.