Commit 840e81d6 authored by Thorsten Buss's avatar Thorsten Buss

allow empty amounts in constructor (null, empty string, 0.0) also they are not ints

parent 0533f794
......@@ -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');
}
......
......@@ -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();
}
}
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