/** * @param string $iso String representation of the form "EUR/USD 1.2500" * @expectedException \Exception * @return \Money\CurrencyPair */ public static function createFromIso($iso) { $currency = "([A-Z]{2,3})"; $ratio = "([0-9]*\\.?[0-9]+)"; // @see http://www.regular-expressions.info/floatingpoint.html $pattern = '#' . $currency . '/' . $currency . ' ' . $ratio . '#'; $matches = array(); if (!preg_match($pattern, $iso, $matches)) { throw new InvalidArgumentException(sprintf("Can't create currency pair from ISO string '%s', format of string is invalid", $iso)); } return new static(CurrencyProxy::determine($matches[1]), CurrencyProxy::determine($matches[2]), $matches[3]); }
public function testCurrencyName() { $this->assertEquals((string) CurrencyProxy::determine('USD'), 'U.S. Dollar'); }
public function provideEqualityComparisonPairs() { $usd = CurrencyProxy::determine('USD'); $eur = CurrencyProxy::determine('EUR'); $gbp = CurrencyProxy::determine('GBP'); return array('Base Mismatch EUR != GBP' => array(new CurrencyPair($eur, $usd, 1.25), new CurrencyPair($gbp, $usd, 1.25), false), 'Counter Mismatch USD != GBP' => array(new CurrencyPair($eur, $usd, 1.25), new CurrencyPair($eur, $gbp, 1.25), false), 'Ratio Mismatch 1.2500 != 1.5000' => array(new CurrencyPair($eur, $usd, 1.25), new CurrencyPair($eur, $usd, 1.5), false), 'Full Equality EUR/USD 1.2500' => array(new CurrencyPair($eur, $usd, 1.25), new CurrencyPair($eur, $usd, 1.25), true)); }
public function testAlias() { $this->assertEquals(new \Money\Currency\CurrencyPound(), CurrencyProxy::determine('gbp')); $this->assertEquals(new \Money\Currency\CurrencyAustralian(), CurrencyProxy::determine('aud')); $this->assertEquals(new \Money\Currency\CurrencyUSD(), CurrencyProxy::determine('Usd')); }
public function testAllocationOrderIsImportant() { $m = new Money(5, CurrencyProxy::determine('EUR')); list($part1, $part2) = $m->allocate(array(3, 7)); $this->assertEquals(new Money(2, CurrencyProxy::determine('EUR')), $part1); $this->assertEquals(new Money(3, CurrencyProxy::determine('EUR')), $part2); $m = new Money(5, CurrencyProxy::determine('EUR')); list($part1, $part2) = $m->allocate(array(7, 3)); $this->assertEquals(new Money(4, CurrencyProxy::determine('EUR')), $part1); $this->assertEquals(new Money(1, CurrencyProxy::determine('EUR')), $part2); }
/** * Convenience factory method for a Money object * @example $fiveDollar = Money::USD(500); * @param string $method * @param array $arguments * @return Money */ public static function __callStatic($method, $arguments) { $currency = CurrencyProxy::determine($method); return new Money($arguments[0], new $currency()); }