Skip to content

Commit d28330f

Browse files
committed
Merge branch 'dev-dependencies-should-stay-dev'
2 parents 3ad15f6 + ca4fd55 commit d28330f

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
"php-http/discovery": "^1.6",
3232
"psr/http-factory": "^1.0.2",
3333
"php-http/client-implementation": "^1.0",
34-
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
35-
"symfony/http-client": "^5.4",
36-
"php-http/message-factory": "^1.1"
34+
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
3735
},
3836
"require-dev": {
3937
"phpunit/phpunit": "^7 || ^8 || ^9.4",
4038
"php-http/message": "^1.7",
4139
"php-http/mock-client": "^1.0",
40+
"php-http/message-factory": "^1.1",
41+
"symfony/http-client": "^5.4 || ^6.4 || ^7.0",
4242
"nyholm/psr7": "^1.0"
4343
},
4444
"scripts": {

src/Service/HttpService.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
namespace Exchanger\Service;
1515

1616
use Http\Client\HttpClient;
17+
use Http\Discovery\Exception\NotFoundException;
1718
use Http\Discovery\HttpClientDiscovery;
1819
use Http\Discovery\Psr17FactoryDiscovery;
20+
use Http\Discovery\Psr18ClientDiscovery;
1921
use Psr\Http\Client\ClientInterface;
2022
use Psr\Http\Message\RequestFactoryInterface;
2123
use Psr\Http\Message\RequestInterface;
@@ -50,7 +52,11 @@ abstract class HttpService extends Service
5052
public function __construct($httpClient = null, RequestFactoryInterface $requestFactory = null, array $options = [])
5153
{
5254
if (null === $httpClient) {
53-
$httpClient = HttpClientDiscovery::find();
55+
try {
56+
$httpClient = Psr18ClientDiscovery::find();
57+
} catch (NotFoundException $e) {
58+
$httpClient = HttpClientDiscovery::find();
59+
}
5460
} else {
5561
if (!$httpClient instanceof ClientInterface && !$httpClient instanceof HttpClient) {
5662
throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Psr\\Http\\Client\\ClientInterface');

tests/Tests/Service/CentralBankOfCzechRepublicTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function it_fetches_idr_rate()
111111
$pair = CurrencyPair::createFromString('IDR/CZK');
112112
$rate = $this->createService()->getExchangeRate(new ExchangeRateQuery($pair));
113113

114-
$this->assertSame(0.001798, $rate->getValue());
114+
$this->assertSame(0.001798, (float)\number_format($rate->getValue(), 6));
115115
$this->assertEquals('central_bank_of_czech_republic', $rate->getProviderName());
116116
$this->assertSame($pair, $rate->getCurrencyPair());
117117
}

tests/Tests/Service/CurrencyLayerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function it_fetches_a_historical_rate_normal_mode()
106106
$content = file_get_contents(__DIR__.'/../../Fixtures/Service/CurrencyLayer/historical_success.json');
107107
$date = new \DateTime('2015-05-06');
108108
$expectedDate = new \DateTime();
109-
$expectedDate->setTimestamp(1430870399);
109+
$expectedDate->setTimestamp(1430784000);
110110

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

131131
$pair = CurrencyPair::createFromString('USD/AED');
132132
$service = new CurrencyLayer($this->getHttpAdapterMock($uri, $content), null, ['access_key' => 'secret', 'enterprise' => true]);

tests/Tests/Service/HttpServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public function initialize_with_httplug_client()
5050
*/
5151
public function initialize_with_null_as_client()
5252
{
53-
$this->expectException(\Http\Discovery\Exception\NotFoundException::class);
54-
$this->expectExceptionMessage('No HTTPlug clients found. Make sure to install a package providing "php-http/client-implementation"');
53+
$this->expectNotToPerformAssertions();
54+
// if null is passed a new instance HttpClient is generated in the HttpService.
5555
$this->createAnonymousClass(null);
5656
}
5757

0 commit comments

Comments
 (0)