diff --git a/src/Api/Api.php b/src/Api/Api.php index 8f06120..5d09ba6 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -34,6 +34,7 @@ public function get(string $uri, array $query = []): array { $response = $this->client->getHttpClient()->request('GET', '/api/' . $this->version . $uri, ['query' => $query]); + $this->client->setLastResponse($response); return $this->transformer->transform($response); } diff --git a/src/CoinGeckoClient.php b/src/CoinGeckoClient.php index daf5cbe..e4a824d 100644 --- a/src/CoinGeckoClient.php +++ b/src/CoinGeckoClient.php @@ -18,6 +18,7 @@ use Codenixsv\CoinGeckoApi\Api\StatusUpdates; use Exception; use GuzzleHttp\Client; +use Psr\Http\Message\ResponseInterface; /** * Class CoinGeckoClient @@ -30,6 +31,9 @@ class CoinGeckoClient /** @var Client */ private $httpClient; + /** @var ResponseInterface|null */ + protected $lastResponse; + public function __construct(?Client $client = null) { $this->httpClient = $client ?: new Client(['base_uri' => self::BASE_URI]); @@ -103,4 +107,14 @@ public function globals(): Globals { return new Globals($this); } + + public function setLastResponse(ResponseInterface $response) + { + return $this->lastResponse = $response; + } + + public function getLastResponse(): ?ResponseInterface + { + return $this->lastResponse; + } } diff --git a/tests/CoinGeckoClientTest.php b/tests/CoinGeckoClientTest.php index d0c9246..51432f4 100644 --- a/tests/CoinGeckoClientTest.php +++ b/tests/CoinGeckoClientTest.php @@ -18,6 +18,7 @@ use Codenixsv\CoinGeckoApi\CoinGeckoClient; use GuzzleHttp\Client; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseInterface; class CoinGeckoClientTest extends TestCase { @@ -111,4 +112,20 @@ public function testGlobals() $this->assertInstanceOf(Globals::class, $client->globals()); } + + public function testGetLastResponseIsNull() + { + $client = new CoinGeckoClient(); + + $this->assertNull($client->getLastResponse()); + } + + public function testSetLastResponse() + { + $client = new CoinGeckoClient(); + $response = $this->createMock(ResponseInterface::class); + $client->setLastResponse($response); + + $this->assertInstanceOf(ResponseInterface::class, $client->getLastResponse()); + } }