Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
package
money
Commits
6b51878d
Commit
6b51878d
authored
Sep 18, 2013
by
Cam Spiers
Browse files
Added better exception for failure to parse currency pair ISO string
parent
7ffda0d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/Money/CurrencyPair.php
View file @
6b51878d
...
...
@@ -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
]);
...
...
tests/Money/Tests/CurrencyPairTest.php
View file @
6b51878d
...
...
@@ -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'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment