diff --git a/src/Money/Money.php b/src/Money/Money.php index 013db3cb5a3339546f82f358491e0f7bc8c1bdf7..fa25ee45a57c068b654909d94671f6e5f5652b68 100644 --- a/src/Money/Money.php +++ b/src/Money/Money.php @@ -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'); } diff --git a/tests/Money/MoneyTest.php b/tests/Money/MoneyTest.php index 595156ec6b50a647dec3e00a2214d797976ccd00..9d61b21d11702a611ada0196b82dd53b4352fbd2 100644 --- a/tests/Money/MoneyTest.php +++ b/tests/Money/MoneyTest.php @@ -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(); + } }