Commit 6b51878d authored by Cam Spiers's avatar Cam Spiers
Browse files

Added better exception for failure to parse currency pair ISO string

parent 7ffda0d4
......@@ -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