Skip to content

Commit

Permalink
Added getLastResponse method to client
Browse files Browse the repository at this point in the history
  • Loading branch information
codenix-sv committed Jun 8, 2020
1 parent 3b83d37 commit 7d899b3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 14 additions & 0 deletions src/CoinGeckoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Codenixsv\CoinGeckoApi\Api\StatusUpdates;
use Exception;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;

/**
* Class CoinGeckoClient
Expand All @@ -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]);
Expand Down Expand Up @@ -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;
}
}
17 changes: 17 additions & 0 deletions tests/CoinGeckoClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Codenixsv\CoinGeckoApi\CoinGeckoClient;
use GuzzleHttp\Client;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;

class CoinGeckoClientTest extends TestCase
{
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 7d899b3

Please sign in to comment.