forked from moneyphp/money
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrencyPairSpec.php
61 lines (48 loc) · 1.89 KB
/
CurrencyPairSpec.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace spec\Money;
use Money\Currency;
use Money\CurrencyPair;
use PhpSpec\ObjectBehavior;
final class CurrencyPairSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(new Currency('EUR'), new Currency('USD'), 1.250000);
}
function it_is_initializable()
{
$this->shouldHaveType(CurrencyPair::class);
}
function it_is_json_serializable()
{
$this->shouldImplement(\JsonSerializable::class);
}
function it_has_currencies_and_ratio()
{
$this->beConstructedWith($base = new Currency('EUR'), $counter = new Currency('USD'), $ratio = 1.0);
$this->getBaseCurrency()->shouldReturn($base);
$this->getCounterCurrency()->shouldReturn($counter);
$this->getConversionRatio()->shouldReturn($ratio);
}
function it_throws_an_exception_when_ratio_is_not_numeric()
{
$this->beConstructedWith(new Currency('EUR'), new Currency('USD'), 'NON_NUMERIC');
$this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation();
}
function it_equals_to_another_currency_pair()
{
$this->equals(new CurrencyPair(new Currency('GBP'), new Currency('USD'), 1.250000))->shouldReturn(false);
$this->equals(new CurrencyPair(new Currency('EUR'), new Currency('GBP'), 1.250000))->shouldReturn(false);
$this->equals(new CurrencyPair(new Currency('EUR'), new Currency('USD'), 1.5000))->shouldReturn(false);
$this->equals(new CurrencyPair(new Currency('EUR'), new Currency('USD'), 1.250000))->shouldReturn(true);
}
function it_parses_an_iso_string()
{
$pair = $this->createFromIso('EUR/USD 1.250000');
$this->equals($pair)->shouldReturn(true);
}
function it_throws_an_exception_when_iso_string_cannot_be_parsed()
{
$this->shouldThrow(\InvalidArgumentException::class)->duringCreateFromIso('1.250000');
}
}