/**
  * @expectedException \Exception
  */
 public function testCurrencyRateNotFoundThrowsException()
 {
     $localAdapter = $this->getMock('Elcodi\\Component\\Currency\\Adapter\\LocaleProvider\\Interfaces\\LocaleProviderAdapterInterface');
     $localAdapter->expects($this->any())->method('getLocaleIso')->will($this->returnValue('es_ES'));
     $priceExtension = new PrintMoneyExtension($this->getMock('Elcodi\\Component\\Currency\\Services\\CurrencyConverter', [], [], '', false), $this->getMock('Elcodi\\Component\\Currency\\Wrapper\\CurrencyWrapper', [], [], '', false), $localAdapter);
     $currencyFactory = new CurrencyFactory();
     $currencyFactory->setEntityNamespace('Elcodi\\Component\\Currency\\Entity\\Currency');
     $priceExtension->printMoney(Money::create(1000, $currencyFactory->create()->setIso('US1')), 'US1');
 }
Beispiel #2
0
 /**
  * @expectedException \Exception
  */
 public function testCurrencyRateNotFoundThrowsException()
 {
     $locale = $this->getMock('Elcodi\\Component\\Language\\Entity\\Interfaces\\LocaleInterface');
     $locale->expects($this->any())->method('getIso')->willReturn('es_ES');
     $priceExtension = new MoneyPrinter($this->getMock('Elcodi\\Component\\Currency\\Services\\CurrencyConverter', [], [], '', false), $this->getMock('Elcodi\\Component\\Currency\\Wrapper\\CurrencyWrapper', [], [], '', false), Locale::create($locale));
     $currencyFactory = new CurrencyFactory();
     $currencyFactory->setEntityNamespace('Elcodi\\Component\\Currency\\Entity\\Currency');
     $currencyFactory->setDateTimeFactory(new DateTimeFactory());
     $priceExtension->printMoney(Money::create(1000, $currencyFactory->create()->setIso('US1')), 'US1');
 }
 /**
  * Test convert money
  *
  * @dataProvider dataConvertMoney
  */
 public function testConvertMoney($isoFrom, $isoTo, $amount, $resultAmount)
 {
     $currencyManager = $this->getMockBuilder('Elcodi\\Component\\Currency\\Services\\CurrencyManager')->setMethods(['getExchangeRateList'])->disableOriginalConstructor()->getMock();
     $currencyFactory = new CurrencyFactory();
     $currencyFactory->setEntityNamespace('Elcodi\\Component\\Currency\\Entity\\Currency');
     $currencyFactory->setDateTimeFactory(new DateTimeFactory());
     $currencyBase = 'USD';
     /**
      * @var CurrencyManager $currencyManager
      */
     $currencyManager->expects($this->any())->method('getExchangeRateList')->will($this->returnValue(['EUR' => ['rate' => '0.7365960000', 'currency' => $currencyFactory->create()], 'GBP' => ['rate' => '0.5887650000', 'currency' => $currencyFactory->create()], 'JPY' => ['rate' => '101.8226250000', 'currency' => $currencyFactory->create()]]));
     $currencyConverter = new CurrencyConverter($currencyManager, $currencyBase);
     $currencyFrom = $currencyFactory->create();
     $currencyFrom->setIso($isoFrom);
     $currencyTo = $currencyFactory->create();
     $currencyTo->setIso($isoTo);
     $money = Money::create($amount, $currencyFrom);
     $moneyResult = $currencyConverter->convertMoney($money, $currencyTo);
     $this->assertEquals($moneyResult->getAmount(), $resultAmount);
     $this->assertEquals($moneyResult->getCurrency(), $currencyTo);
 }