Commit 8db9d6d3 authored by Thomas Bilk's avatar Thomas Bilk

Added some documentation and unit tests

parent 976a4d83
......@@ -10,6 +10,12 @@
namespace Money;
/**
* Class Money
* @package Money
* @method static $this USD(int $i) Convenience factory method for a Money object
* @method static $this EUR(int $i) Convenience factory method for a Money object
*/
class Money
{
const ROUND_HALF_UP = PHP_ROUND_HALF_UP;
......
......@@ -12,8 +12,7 @@ namespace Money\Tests;
require_once('MoneyTestCase.php');
use Money\CurrencyLookupRubyMoney;
use PHPUnit_Framework_TestCase;
use Money\InvalidArgumentException;
use Money\Money;
use Money\Currency;
......@@ -31,7 +30,8 @@ class MoneyTest extends MoneyTestCase {
);
}
public function testNewInstance() {
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());
......@@ -45,6 +45,22 @@ class MoneyTest extends MoneyTestCase {
$this->assertEquals(0, Money::newInstance('EUR', 0.0)->getAmount());
}
/**
* @expectedException InvalidArgumentException
*/
public function testFailNewInstanceFloatString()
{
Money::newInstance('EUR', '1.1');
}
/**
* @expectedException InvalidArgumentException
*/
public function testFailNewInstanceHexString()
{
Money::newInstance('EUR', 'c0ffee');
}
public function testGetters()
{
$m = new Money(100, $euro = new Currency('EUR'));
......@@ -53,11 +69,11 @@ class MoneyTest extends MoneyTestCase {
}
/**
* @expectedException Money\InvalidArgumentException
* @expectedException InvalidArgumentException
*/
public function testDecimalsThrowException()
{
$money = new Money(0.01, new Currency('EUR'));
new Money(0.01, new Currency('EUR'));
}
public function testEquality()
......@@ -87,7 +103,7 @@ class MoneyTest extends MoneyTestCase {
}
/**
* @expectedException Money\InvalidArgumentException
* @expectedException InvalidArgumentException
*/
public function testDifferentCurrenciesCannotBeAdded()
{
......@@ -111,7 +127,7 @@ class MoneyTest extends MoneyTestCase {
}
/**
* @expectedException Money\InvalidArgumentException
* @expectedException InvalidArgumentException
*/
public function testDifferentCurrenciesCannotBeSubtracted()
{
......@@ -158,7 +174,7 @@ class MoneyTest extends MoneyTestCase {
{
$euro1 = new Money(1, new Currency('EUR'));
$euro2 = new Money(2, new Currency('EUR'));
$usd = new Money(1, new Currency('USD'));
// $usd = new Money(1, new Currency('USD'));
$this->assertTrue($euro2->greaterThan($euro1));
$this->assertFalse($euro1->greaterThan($euro2));
......@@ -171,7 +187,7 @@ class MoneyTest extends MoneyTestCase {
}
/**
* @expectedException Money\InvalidArgumentException
* @expectedException InvalidArgumentException
*/
public function testDifferentCurrenciesCannotBeCompared()
{
......@@ -246,6 +262,8 @@ class MoneyTest extends MoneyTestCase {
/**
* @dataProvider provideStringsUSD
* @param $string
* @param $units
*/
public function testStringToUnitsUSD($string, $units)
{
......@@ -281,6 +299,8 @@ class MoneyTest extends MoneyTestCase {
/**
* @dataProvider provideStringsEUR
* @param $string
* @param $units
*/
public function testStringToUnitsEUR($string, $units)
{
......
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