/
moneyTest.php
47 lines (44 loc) · 1.21 KB
/
moneyTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require 'money.php';
require 'currency.php';
require 'UnknownCurrencyException.php';
class moneyTest extends PHPUnit_Framework_TestCase
{
public function testCanBeCreated()
{
$money = money::USD(123);
$this->assertEquals(123, $money->getAmount());
$this->assertEquals('USD', $money->getCurrency()->getName());
}
/**
* @expectedException UnknownCurrencyException
*/
public function testCreatingUnknownCurrency()
{
$a = money::XYZ(123);
}
/**
* @expectedException InvalidArgumentException
*/
public function testAmountHaveToBeInteger()
{
$a = money::USD(12.34);
}
public function testToStringConversion()
{
$money = money::USD(123);
$this->assertEquals("1.23 USD", (string)$money);
}
public function testIsSameAmountNonStrict()
{
$a = money::USD(123);
$a->setRestrictionToSameCurrency(false);
$this->assertEquals(true, $a->isSameAmount(money::USD(123)));
}
public function testIsSameAmountStrict()
{
$a = money::USD(123);
$a->setRestrictionToSameCurrency(true);
$this->assertEquals(true, $a->isSameAmount(money::EUR(123)));
}
}