diff --git a/src/Service/RussianCentralBank.php b/src/Service/RussianCentralBank.php index 14d98a8..b84d66a 100644 --- a/src/Service/RussianCentralBank.php +++ b/src/Service/RussianCentralBank.php @@ -34,8 +34,9 @@ protected function getLatestExchangeRate(ExchangeRateQuery $exchangeQuery) } $rate = str_replace(',', '.', (string) $elements['0']->Value); + $nominal = str_replace(',', '.', (string) $elements['0']->Nominal); - return new ExchangeRate($rate, $date); + return new ExchangeRate($rate / $nominal, $date); } /** @@ -60,8 +61,9 @@ protected function getHistoricalExchangeRate(HistoricalExchangeRateQuery $exchan } $rate = str_replace(',', '.', (string) $elements['0']->Value); + $nominal = str_replace(',', '.', (string) $elements['0']->Nominal); - return new ExchangeRate($rate, $exchangeQuery->getDate()); + return new ExchangeRate($rate / $nominal, $exchangeQuery->getDate()); } /** diff --git a/tests/Tests/Service/RussianCentralBankTest.php b/tests/Tests/Service/RussianCentralBankTest.php index 68d3394..37ce418 100644 --- a/tests/Tests/Service/RussianCentralBankTest.php +++ b/tests/Tests/Service/RussianCentralBankTest.php @@ -59,6 +59,21 @@ public function it_fetches_a_rate() $this->assertEquals(new \DateTime('2016-12-09'), $rate->getDate()); } + /** + * @test + */ + public function it_fetches_a_nominational_rate() + { + $url = 'http://www.cbr.ru/scripts/XML_daily.asp'; + $content = file_get_contents(__DIR__.'/../../Fixtures/Service/RussianCentralBank/success.xml'); + + $service = new RussianCentralBank($this->getHttpAdapterMock($url, $content)); + $rate = $service->getExchangeRate(new ExchangeRateQuery(CurrencyPair::createFromString('AMD/RUB'))); + + $this->assertSame('0.131783', $rate->getValue()); + $this->assertEquals(new \DateTime('2016-12-09'), $rate->getDate()); + } + /** * @test */