Skip to content

Commit

Permalink
Merge pull request #39 from denlapaev/rcb-nominal-support
Browse files Browse the repository at this point in the history
Added support currency nominal for Russian Central Bank
  • Loading branch information
florianv authored Mar 15, 2018
2 parents 7f44f79 + 204fa12 commit 77af7ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Service/RussianCentralBank.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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());
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/Tests/Service/RussianCentralBankTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 77af7ee

Please sign in to comment.