Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
M
money-datatype
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
package
money-datatype
Commits
840e81d6
Commit
840e81d6
authored
Oct 30, 2017
by
Thorsten Buss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow empty amounts in constructor (null, empty string, 0.0) also they are not ints
parent
0533f794
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
1 deletion
+10
-1
Money.php
src/Money/Money.php
+2
-0
MoneyTest.php
tests/Money/MoneyTest.php
+8
-1
No files found.
src/Money/Money.php
View file @
840e81d6
...
...
@@ -38,6 +38,8 @@ class Money implements \JsonSerializable, Jsonable, Arrayable {
* @throws MoneyException
*/
public
function
__construct
(
$amount
,
$currency
=
null
)
{
if
(
empty
(
$amount
))
// FIX: if something empty is given (empty string, null, 0.0 etc) everything shoul work the same
$amount
=
0
;
if
(
!
is_int
(
$amount
)
&&
!
ctype_digit
(
$amount
))
{
throw
new
MoneyException
(
'Amount must be an integer'
);
}
...
...
tests/Money/MoneyTest.php
View file @
840e81d6
...
...
@@ -318,5 +318,12 @@ class MoneyTest extends \PHPUnit_Framework_TestCase {
$this
->
assertFalse
(
$m5
->
isNegative
());
$this
->
assertFalse
(
$m6
->
isPositive
());
}
public
function
testEmptyAmounts
()
{
$this
->
money
(
0
);
$this
->
money
(
''
);
$this
->
money
(
null
);
$this
->
money
(
0.00
);
$this
->
isTrue
();
}
}
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