public function __construct(ICurrency $currency, ICurrencyRateProvider $provider, \DateTime $date = null) { $this->currency = $currency; $this->date = $date; $this->provider = $provider; $this->message = sprintf('Rate not found for currency %s and provider %s', $currency->getCode(), $provider->getName()); }
/** * {@inheritdoc} */ public function getRate(ICurrency $currency, ICurrencyRateProvider $provider, \DateTime $rateDate = null) { $qb = $this->em->createQueryBuilder(); $qb->select('r')->from($this->currencyRateClassName, 'r')->leftJoin('r.currency', 'c')->where($qb->expr()->eq('c.code', ':currency'))->andWhere($qb->expr()->eq('r.providerName', ':provider'))->setParameters(['currency' => $currency->getCode(), 'provider' => $provider->getName()])->orderBy('r.date', 'DESC'); if (isset($rateDate)) { $qb->andWhere($qb->expr()->eq('r.date', ':date'))->setParameter('date', $rateDate->format('Y-m-d 00:00:00')); } $result = $qb->getQuery()->getResult(); $result = reset($result); return $result; }
public function setUp() { $this->currencyRateProvider = $this->getMock('\\RedCode\\Currency\\Rate\\Provider\\ICurrencyRateProvider'); $this->currencyRateProvider->method('getName')->willReturn('testName'); }
/** * Get currency rate * * @param ICurrency $currency * @param ICurrencyRateProvider $provider * @param null $date * @return float */ private function getRate(ICurrency $currency, ICurrencyRateProvider $provider, $date = null) { if ($currency->getCode() != $provider->getBaseCurrency()->getCode()) { $rate = $this->rateManager->getRate($currency, $provider, $date); if (!$rate) { return null; } if (!$provider->isInversed()) { $rate = $rate->getNominal() * $rate->getRate(); } else { $rate = $rate->getNominal() / $rate->getRate(); } } else { $rate = 1.0; } return $rate; }
public function setUp() { $this->provider = $this->getMock(self::PROVIDER_INTERFACE); $this->provider->method('getName')->willReturn($this->providerName); }