diff --git a/src/Services/NationalBankOfUkraine.php b/src/Services/NationalBankOfUkraine.php index 06c5b43..702d286 100644 --- a/src/Services/NationalBankOfUkraine.php +++ b/src/Services/NationalBankOfUkraine.php @@ -53,7 +53,10 @@ public function parseRateData(string $content, string $quoteCurrency): array throw new RuntimeException(trans('larate::error.badfloat', ['value' => $value])); } - return [$value, $date]; + return [ + 'value' => $value, + 'date' => $date, + ]; } /** @@ -70,7 +73,7 @@ public function getExchangeRate(CurrencyPairContract $currencyPair, DateTimeInte ]) : $this->makeRequest(['valcode' => $quoteCurrency]); - [$value, $responseDate] = $this->parseRateData($content, $quoteCurrency); + ['value' => $value, 'date' => $responseDate] = $this->parseRateData($content, $quoteCurrency); return new ExchangeRate($currencyPair, $value, $responseDate, $this->getName()); } diff --git a/src/Services/RussianCentralBank.php b/src/Services/RussianCentralBank.php index 1599958..156351b 100644 --- a/src/Services/RussianCentralBank.php +++ b/src/Services/RussianCentralBank.php @@ -61,7 +61,11 @@ public function parseRateData(string $content, string $quoteCurrency): array $nominalStr = (string) $quoteCurrencyData['0']->Nominal; $nominal = $fmt->parse($nominalStr); - return [$value, $nominal, $date]; + return [ + 'value' => $value, + 'nominal' => $nominal, + 'date' => $date, + ]; } /** @@ -75,7 +79,7 @@ public function getExchangeRate(CurrencyPairContract $currencyPair, DateTimeInte ? $this->makeRequest(['date_req' => $date->format('d/m/Y')]) : $this->makeRequest(); - [$value, $nominal, $responseDate] = $this->parseRateData($content, $quoteCurrency); + ['value' => $value, 'nominal' => $nominal, 'date' => $responseDate] = $this->parseRateData($content, $quoteCurrency); return new ExchangeRate($currencyPair, $value / $nominal, $responseDate, $this->getName()); } diff --git a/tests/Unit/NationalBankOfUkraineTest.php b/tests/Unit/NationalBankOfUkraineTest.php index a1a70c1..0c7ef41 100644 --- a/tests/Unit/NationalBankOfUkraineTest.php +++ b/tests/Unit/NationalBankOfUkraineTest.php @@ -6,6 +6,7 @@ use Dostrog\Larate\CurrencyPair; use Dostrog\Larate\Services\NationalBankOfUkraine; use Dostrog\Larate\Tests\TestCase; +use Exception; use Illuminate\Http\Client\Factory; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Http; @@ -53,7 +54,10 @@ public function nbu_parse_rate_data(): void CONTENT; - self::assertEquals([23.9821, Carbon::parse('16.01.2020')], $this->service->parseRateData($content, 'USD')); + self::assertEquals([ + 'value' => 23.9821, + 'date' => Carbon::parse('16.01.2020'), + ], $this->service->parseRateData($content, 'USD')); } /** @test */ @@ -207,7 +211,7 @@ public function rcb_get_exchange_rate_response_throw_exception(): void $httpClient = $this->mock(Factory::class); $httpClient->shouldReceive('get') ->withSomeOfArgs(['url' => NationalBankOfUkraine::URL]) - ->andThrow(\Exception::class); + ->andThrow(Exception::class); $rcb = new NationalBankOfUkraine($httpClient); $pair = new CurrencyPair(self::BASE_CURRENCY, self::QUOTE_CURRENCY); diff --git a/tests/Unit/RussianCentralBankTest.php b/tests/Unit/RussianCentralBankTest.php index 31bd079..d13e626 100644 --- a/tests/Unit/RussianCentralBankTest.php +++ b/tests/Unit/RussianCentralBankTest.php @@ -6,6 +6,7 @@ use Dostrog\Larate\CurrencyPair; use Dostrog\Larate\Services\RussianCentralBank; use Dostrog\Larate\Tests\TestCase; +use Exception; use Illuminate\Http\Client\Factory; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Http; @@ -53,7 +54,9 @@ public function rcb_parse_rate_data(): void CONTENT; - self::assertEquals([418.1800, 1.0, Carbon::parse('16.01.1996')], $this->service->parseRateData($content, 'EEK')); + self::assertEquals([ + 'value' => 418.1800, 'nominal' => 1.0, 'date' => Carbon::parse('16.01.1996') + ], $this->service->parseRateData($content, 'EEK')); } /** @test */ @@ -152,7 +155,7 @@ public function rcb_get_exchange_rate_for_holiday(): void $rate1 = $this->service->getExchangeRate($pair, Carbon::parse($date1))->getValue(); self::assertEquals($expected, $rate0); - self::assertEquals($rate0, $rate1); + self::assertSame($rate0, $rate1); } /** @test */ @@ -179,7 +182,7 @@ public function rcb_get_exchange_rate_response_throw_exception(): void $httpClient = $this->mock(Factory::class); $httpClient->shouldReceive('get') ->withSomeOfArgs(['url' => RussianCentralBank::URL]) - ->andThrow(\Exception::class); + ->andThrow(Exception::class); $rcb = new RussianCentralBank($httpClient); @@ -215,6 +218,6 @@ public function rcb_get_exchange_rate_for_past(): void /** @test */ public function rcb_get_name(): void { - self::assertEquals(self::PROVIDER_NAME, $this->service->getName()); + self::assertSame(self::PROVIDER_NAME, $this->service->getName()); } }