Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"php-http/discovery": "^1.6",
"psr/http-factory": "^1.0.2",
"php-http/client-implementation": "^1.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
"symfony/http-client": "^5.4",
"php-http/message-factory": "^1.1"
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^7 || ^8 || ^9.4",
"php-http/message": "^1.7",
"php-http/mock-client": "^1.0",
"php-http/message-factory": "^1.1",
"symfony/http-client": "^5.4 || ^6.4 || ^7.0",
"nyholm/psr7": "^1.0"
},
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion src/Service/HttpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace Exchanger\Service;

use Http\Client\HttpClient;
use Http\Discovery\Exception\NotFoundException;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
Expand Down Expand Up @@ -50,7 +52,11 @@ abstract class HttpService extends Service
public function __construct($httpClient = null, RequestFactoryInterface $requestFactory = null, array $options = [])
{
if (null === $httpClient) {
$httpClient = HttpClientDiscovery::find();
try {
$httpClient = Psr18ClientDiscovery::find();
} catch (NotFoundException $e) {
$httpClient = HttpClientDiscovery::find();
}
} else {
if (!$httpClient instanceof ClientInterface && !$httpClient instanceof HttpClient) {
throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Psr\\Http\\Client\\ClientInterface');
Expand Down
2 changes: 1 addition & 1 deletion tests/Tests/Service/CentralBankOfCzechRepublicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function it_fetches_idr_rate()
$pair = CurrencyPair::createFromString('IDR/CZK');
$rate = $this->createService()->getExchangeRate(new ExchangeRateQuery($pair));

$this->assertSame(0.001798, $rate->getValue());
$this->assertSame(0.001798, (float)\number_format($rate->getValue(), 6));
$this->assertEquals('central_bank_of_czech_republic', $rate->getProviderName());
$this->assertSame($pair, $rate->getCurrencyPair());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Tests/Service/CurrencyLayerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function it_fetches_a_historical_rate_normal_mode()
$content = file_get_contents(__DIR__.'/../../Fixtures/Service/CurrencyLayer/historical_success.json');
$date = new \DateTime('2015-05-06');
$expectedDate = new \DateTime();
$expectedDate->setTimestamp(1430870399);
$expectedDate->setTimestamp(1430784000);

$service = new CurrencyLayer($this->getHttpAdapterMock($uri, $content), null, ['access_key' => 'secret']);
$rate = $service->getExchangeRate(new HistoricalExchangeRateQuery($pair, $date));
Expand All @@ -126,7 +126,7 @@ public function it_fetches_a_historical_rate_enterprise_mode()
$content = file_get_contents(__DIR__.'/../../Fixtures/Service/CurrencyLayer/historical_success.json');
$date = new \DateTime('2015-05-06');
$expectedDate = new \DateTime();
$expectedDate->setTimestamp(1430870399);
$expectedDate->setTimestamp(1430784000);

$pair = CurrencyPair::createFromString('USD/AED');
$service = new CurrencyLayer($this->getHttpAdapterMock($uri, $content), null, ['access_key' => 'secret', 'enterprise' => true]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Tests/Service/HttpServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function initialize_with_httplug_client()
*/
public function initialize_with_null_as_client()
{
$this->expectException(\Http\Discovery\Exception\NotFoundException::class);
$this->expectExceptionMessage('No HTTPlug clients found. Make sure to install a package providing "php-http/client-implementation"');
$this->expectNotToPerformAssertions();
// if null is passed a new instance HttpClient is generated in the HttpService.
$this->createAnonymousClass(null);
}

Expand Down