Skip to content

Commit 7ad2118

Browse files
Merge branch 'master' of github.com:mathiasverraes/money
2 parents b198c6c + 7334c24 commit 7ad2118

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Money
55

66
PHP 5.3+ library to make working with money safer, easier, and fun!
77

8-
In short: You probably shouldn't represent monetary values by a float. Wherever
8+
> "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)
9+
10+
In short: You shouldn't represent monetary values by a float. Wherever
911
you need to represent money, use this Money value object.
1012

1113
```php

lib/Money/CurrencyPair.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ public static function createFromIso($iso)
5252

5353
$matches = array();
5454
if (!preg_match($pattern, $iso, $matches)) {
55-
// @todo better exception
56-
throw new \Exception();
55+
throw new InvalidArgumentException(
56+
sprintf(
57+
"Can't create currency pair from ISO string '%s', format of string is invalid",
58+
$iso
59+
)
60+
);
5761
}
5862

5963
return new static(new Currency($matches[1]), new Currency($matches[2]), $matches[3]);

tests/Money/Tests/CurrencyPairTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,14 @@ public function ParsesIso()
3838
$expected = new CurrencyPair(new Currency('EUR'), new Currency('USD'), 1.2500);
3939
$this->assertEquals($expected, $pair);
4040
}
41+
42+
/**
43+
* @test
44+
* @expectedException \Money\InvalidArgumentException
45+
* @expectedExceptionMessage Can't create currency pair from ISO string '1.2500', format of string is invalid
46+
*/
47+
public function ParsesIsoWithException()
48+
{
49+
CurrencyPair::createFromIso('1.2500');
50+
}
4151
}

0 commit comments

Comments
 (0)