Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

Commit

Permalink
Mock Test Support
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuilam authored May 21, 2021
1 parent 65e9e2d commit 540cb41
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/BaseApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -49,15 +51,21 @@ private function extra($data, $key)

private function http()
{
return new Client([
$options = [
'base_uri' => config('ssl.endpoint', 'https://sws.sslpki.com'),
]);
];

if (app()->offsetExists('sslcorp_mock')) {
$options['handler'] = app('sslcorp_mock');
}

return new Client($options);
}

protected function processErrror(ResponseInterface $response)
{
$json = json_decode($response->getBody()->__toString());
if ($response->getStatusCode() != 200 || (property_exists($json, 'errors') && $json->errors)) {
if ($response->getStatusCode() != 200 || !$json || (property_exists($json, 'errors') && $json->errors)) {
if (json_last_error() != JSON_ERROR_NONE) {
throw new ResponseErrorException($response->getReasonPhrase(), $response->getStatusCode(), null, $response->getBody()->__toString());
}
Expand Down

0 comments on commit 540cb41

Please sign in to comment.