Skip to content

Commit

Permalink
Add integration tests to supported APIs(providers)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmerioles committed Dec 3, 2024
1 parent 7b1b057 commit ba23531
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
Expand Down
1 change: 0 additions & 1 deletion src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Jimmerioles\BitcoinCurrencyConverter;

use GuzzleHttp\Client;
use Jimmerioles\BitcoinCurrencyConverter\Provider\CoinbaseProvider;
use Jimmerioles\BitcoinCurrencyConverter\Provider\ProviderInterface;
use Jimmerioles\BitcoinCurrencyConverter\Exception\InvalidArgumentException;
Expand Down
37 changes: 37 additions & 0 deletions tests/Integration/BitpayIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Test\Integration;

use GuzzleHttp\Client;
use Jimmerioles\BitcoinCurrencyConverter\Provider\BitpayProvider;
use Test\TestCase;

class BitpayIntegrationTest extends TestCase
{
private $client;

protected function setUp()
{
$this->client = new Client();
}

public function test_api_returns_expected_json_structure()
{
$response = $this->client->request(
'GET',
BitpayProvider::getApiEndpoint(),
['headers' => ['Accept' => 'application/json']]
);

$body = $response->getBody();
$responseArray = json_decode($body, true);

$this->assertEquals(200, $response->getStatusCode());
$this->assertNotEmpty($body);

foreach ($responseArray as $currency) {
$this->assertArrayHasKey('code', $currency);
$this->assertArrayHasKey('rate', $currency);
}
}
}
35 changes: 35 additions & 0 deletions tests/Integration/CoinbaseIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Test\Integration;

use GuzzleHttp\Client;
use Jimmerioles\BitcoinCurrencyConverter\Provider\CoinbaseProvider;
use Test\TestCase;

class CoinbaseIntegrationTest extends TestCase
{
private $client;

protected function setUp()
{
$this->client = new Client();
}

public function test_api_returns_expected_json_structure()
{
$response = $this->client->request(
'GET',
CoinbaseProvider::getApiEndpoint(),
['headers' => ['Accept' => 'application/json']]
);

$body = $response->getBody();
$responseArray = json_decode($body, true);

$this->assertEquals(200, $response->getStatusCode());
$this->assertNotEmpty($body);

$this->assertArrayHasKey('data', $responseArray);
$this->assertArrayHasKey('rates', $responseArray['data']);
}
}
39 changes: 39 additions & 0 deletions tests/Integration/CoindeskIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Test\Integration;

use GuzzleHttp\Client;
use Jimmerioles\BitcoinCurrencyConverter\Provider\CoindeskProvider;
use Test\TestCase;

class CoindeskIntegrationTest extends TestCase
{
private $client;

protected function setUp()
{
$this->client = new Client();
}

public function test_api_returns_expected_json_structure()
{
$response = $this->client->request(
'GET',
CoindeskProvider::getApiEndpoint(),
['headers' => ['Accept' => 'application/json']]
);

$body = $response->getBody();
$responseArray = json_decode($body, true);

$this->assertEquals(200, $response->getStatusCode());
$this->assertNotEmpty($body);

$this->assertArrayHasKey('bpi', $responseArray);

foreach ($responseArray['bpi'] as $currency) {
$this->assertArrayHasKey('code', $currency);
$this->assertArrayHasKey('rate_float', $currency);
}
}
}

0 comments on commit ba23531

Please sign in to comment.