Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit 7d899b3

Browse files
committed
Added getLastResponse method to client
1 parent 3b83d37 commit 7d899b3

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/Api/Api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function get(string $uri, array $query = []): array
3434
{
3535
$response = $this->client->getHttpClient()->request('GET', '/api/' . $this->version
3636
. $uri, ['query' => $query]);
37+
$this->client->setLastResponse($response);
3738

3839
return $this->transformer->transform($response);
3940
}

src/CoinGeckoClient.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Codenixsv\CoinGeckoApi\Api\StatusUpdates;
1919
use Exception;
2020
use GuzzleHttp\Client;
21+
use Psr\Http\Message\ResponseInterface;
2122

2223
/**
2324
* Class CoinGeckoClient
@@ -30,6 +31,9 @@ class CoinGeckoClient
3031
/** @var Client */
3132
private $httpClient;
3233

34+
/** @var ResponseInterface|null */
35+
protected $lastResponse;
36+
3337
public function __construct(?Client $client = null)
3438
{
3539
$this->httpClient = $client ?: new Client(['base_uri' => self::BASE_URI]);
@@ -103,4 +107,14 @@ public function globals(): Globals
103107
{
104108
return new Globals($this);
105109
}
110+
111+
public function setLastResponse(ResponseInterface $response)
112+
{
113+
return $this->lastResponse = $response;
114+
}
115+
116+
public function getLastResponse(): ?ResponseInterface
117+
{
118+
return $this->lastResponse;
119+
}
106120
}

tests/CoinGeckoClientTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Codenixsv\CoinGeckoApi\CoinGeckoClient;
1919
use GuzzleHttp\Client;
2020
use PHPUnit\Framework\TestCase;
21+
use Psr\Http\Message\ResponseInterface;
2122

2223
class CoinGeckoClientTest extends TestCase
2324
{
@@ -111,4 +112,20 @@ public function testGlobals()
111112

112113
$this->assertInstanceOf(Globals::class, $client->globals());
113114
}
115+
116+
public function testGetLastResponseIsNull()
117+
{
118+
$client = new CoinGeckoClient();
119+
120+
$this->assertNull($client->getLastResponse());
121+
}
122+
123+
public function testSetLastResponse()
124+
{
125+
$client = new CoinGeckoClient();
126+
$response = $this->createMock(ResponseInterface::class);
127+
$client->setLastResponse($response);
128+
129+
$this->assertInstanceOf(ResponseInterface::class, $client->getLastResponse());
130+
}
114131
}

0 commit comments

Comments
 (0)