Commit 976a4d83 authored by Thomas Bilk's avatar Thomas Bilk

Fixed recognition of integers in `Money` constructor.

parent 6143c8b9
language: php
php:
- 5.4
- 5.6
before_script:
- composer --dev install
Money
=====
PHP 5.3+ library to make working with money safer, easier, and fun!
PHP 5.6+ library to make working with money safer, easier, and fun!
This is a fork of [Mathias Verraes' Money Library][4], extended with:
* add CurrencyLookup, for different currency sources (example for json-file included)
......
1.2.0
\ No newline at end of file
1.3.4
\ No newline at end of file
......@@ -9,13 +9,17 @@
{
"name": "Thorsten Buss",
"email": "thorsten.buss@buss-networks.de"
},
{
"name": "Thomas Bilk",
"email": "thomas.bilk@buss-networks.de"
}
],
"require": {
"php": ">=5.3.3"
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
"phpunit/phpunit": "5.7.*"
},
"extra": {
"branch-alias": {
......
This diff is collapsed.
......@@ -37,7 +37,7 @@ class Money
*/
public function __construct($amount, $currency=null, $parseAmountAsMoneyString=false)
{
if (!$parseAmountAsMoneyString && !is_int($amount) && !ctype_digit($amount)) { // only numbers(int) - as string or int type
if (!$parseAmountAsMoneyString && !is_int($amount) && (strval($amount) != strval(intval($amount)))) { // only numbers(int) - as string or int type
throw new InvalidArgumentException("The first parameter of Money must be an integer. It's the amount, expressed in the smallest units of currency (eg cents)");
}
$this->currency = Currency::getInstance($currency);
......
......@@ -31,6 +31,20 @@ class MoneyTest extends MoneyTestCase {
);
}
public function testNewInstance() {
$this->assertEquals(-8000, Money::newInstance('EUR', '-8000')->getAmount());
$this->assertEquals(8000, Money::newInstance('EUR', '8000')->getAmount());
$this->assertEquals(0, Money::newInstance('EUR', '0')->getAmount());
$this->assertEquals(-8000, Money::newInstance('EUR', -8000)->getAmount());
$this->assertEquals(8000, Money::newInstance('EUR', 8000)->getAmount());
$this->assertEquals(0, Money::newInstance('EUR', 0)->getAmount());
$this->assertEquals(-8000, Money::newInstance('EUR', -8000.0)->getAmount());
$this->assertEquals(8000, Money::newInstance('EUR', 8000.0)->getAmount());
$this->assertEquals(0, Money::newInstance('EUR', 0.0)->getAmount());
}
public function testGetters()
{
$m = new Money(100, $euro = new Currency('EUR'));
......
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