Пример #1
2
 /**
  * Tests for exchangeTo() method.
  */
 public function testExchange()
 {
     $exManager = ExchangeManager::getInstance();
     $exManager->add(new ExchangeRate("BGN/EUR 0.511280836"));
     $money = new Money("100 BGN");
     // with string
     $this->assertEquals("51.13 EUR", $money->exchangeTo("EUR")->__toString());
     // with Currency object
     $this->assertEquals("51.13 EUR", $money->exchangeTo(new Currency("EUR"))->__toString());
 }
Пример #2
0
 /**
  * Converts money to other currency.
  *
  * @param mixed $currency Currency Object or string (3-chars ISO code)
  *
  * @return Money
  */
 public function exchangeTo($currency)
 {
     if (is_string($currency)) {
         $currency = new Currency($currency);
     }
     return ExchangeManager::getInstance()->exchange($this, $currency);
 }
Пример #3
0
 public function testOverrideRateReturnsFirstFound()
 {
     $exManager = new ExchangeManager();
     $exManager->add(new ExchangeRate("EUR/USD 1.25"));
     $this->assertEquals("1.25 USD", $exManager->exchange(1, new Currency("EUR"), new Currency("USD"))->__toString());
     $exManager->add(new ExchangeRate("EUR/USD 1.50"));
     $this->assertEquals("1.25 USD", $exManager->exchange(1, new Currency("EUR"), new Currency("USD"))->__toString());
 }