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
7334c249
Commit
7334c249
authored
Sep 18, 2013
by
Mathias Verraes
Browse files
Merge pull request #30 from camspiers/currency-pair-exception
Added better exception for failure to parse currency pair ISO string
parents
7ffda0d4
6b51878d
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/Money/CurrencyPair.php
View file @
7334c249
...
...
@@ -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 @
7334c249
...
...
@@ -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