/** * This function calculate rates. * * @param float|int $amount * @param string $toCurrency * @param null $fromCurrency * * @return float */ public function calculateRate($amount, $toCurrency, $fromCurrency = null) { if (!isset($fromCurrency)) { $fromCurrency = $this->defaultCurrency; } if ($this->rates->getBaseCurrency() != $fromCurrency) { $amount = $amount / $this->getCurrencyRate($fromCurrency); } if ($toCurrency == $this->rates->getBaseCurrency()) { return $amount; } return $amount * $this->getCurrencyRate($toCurrency); }
/** * Exception when rates are not loaded. * * @expectedException \ONGR\CurrencyExchangeBundle\Exception\RatesNotLoadedException */ public function testException() { $this->repositoryMock->expects($this->any())->method('execute')->willReturn([]); $pool = $this->getCachePool(); $pool->expects($this->any())->method('getItem')->with('ongr_currency')->willReturn($this->getCacheItem([])); $service = new CurrencyRatesService($this->getDriverMock('EUR', []), $this->esManagerMock, $pool, false); $service->setLogger($this->getLogger()); $service->getRates(); }