Commit 7ad21182 authored by Mathias Verraes's avatar Mathias Verraes
Browse files

Merge branch 'master' of github.com:mathiasverraes/money

parents b198c6c6 7334c249
......@@ -5,7 +5,9 @@ Money
PHP 5.3+ library to make working with money safer, easier, and fun!
In short: You probably shouldn't represent monetary values by a float. Wherever
> "If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- [Bill Karwin](https://twitter.com/billkarwin/status/347561901460447232)
In short: You shouldn't represent monetary values by a float. Wherever
you need to represent money, use this Money value object.
```php
......
......@@ -52,8 +52,12 @@ class CurrencyPair
$matches = array();
if (!preg_match($pattern, $iso, $matches)) {
// @todo better exception
throw new \Exception();
throw new InvalidArgumentException(
sprintf(
"Can't create currency pair from ISO string '%s', format of string is invalid",
$iso
)
);
}
return new static(new Currency($matches[1]), new Currency($matches[2]), $matches[3]);
......
......@@ -38,4 +38,14 @@ class CurrencyPairTest extends PHPUnit_Framework_TestCase
$expected = new CurrencyPair(new Currency('EUR'), new Currency('USD'), 1.2500);
$this->assertEquals($expected, $pair);
}
/**
* @test
* @expectedException \Money\InvalidArgumentException
* @expectedExceptionMessage Can't create currency pair from ISO string '1.2500', format of string is invalid
*/
public function ParsesIsoWithException()
{
CurrencyPair::createFromIso('1.2500');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment