1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VinaiKopp\CurrencyInfo\StaticAccess; |
4
|
|
|
|
5
|
|
|
use VinaiKopp\CurrencyInfo\Build\CurrencyInfoKeys; |
6
|
|
|
use VinaiKopp\CurrencyInfo\Exception\UnknownCurrencyException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \VinaiKopp\CurrencyInfo\StaticAccess\CurrencyInfo |
10
|
|
|
*/ |
11
|
|
|
class CurrencyInfoTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
public function testReturnsTheCompleteCurrencyInfoArray() |
14
|
|
|
{ |
15
|
|
|
$currencyInfo = CurrencyInfo::getMap(); |
16
|
|
|
$this->assertInternalType('array', $currencyInfo); |
17
|
|
|
$this->assertNotEmpty($currencyInfo); |
18
|
|
|
$this->assertContainsOnly('array', $currencyInfo); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testReturnsAllRecordsForGivenCurrency() |
22
|
|
|
{ |
23
|
|
|
$euroInfo = CurrencyInfo::getMapForCurrency('EUR'); |
24
|
|
|
array_map(function ($infoKey) use ($euroInfo) { |
25
|
|
|
$this->assertArrayHasKey($infoKey, $euroInfo); |
26
|
|
|
}, CurrencyInfoKeys::getStatic()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testThrowsExceptionIfMapForCurrencyIsNotKnown() |
30
|
|
|
{ |
31
|
|
|
$this->expectException(UnknownCurrencyException::class); |
32
|
|
|
$this->expectExceptionMessage('The currency "XXX" is not known'); |
33
|
|
|
CurrencyInfo::getMapForCurrency('XXX'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function testReturnsTheSymbolMap() |
37
|
|
|
{ |
38
|
|
|
$map = CurrencyInfo::getSymbolMap(); |
39
|
|
|
$this->assertInternalType('array', $map); |
40
|
|
|
$this->assertNotEmpty($map); |
41
|
|
|
$this->assertContainsOnly('string', $map); |
42
|
|
|
$this->assertArrayHasKey('IDR', $map); |
43
|
|
|
$this->assertSame('IDR', $map['IDR']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testReturnsTheSymbolForGivenCurrency() |
47
|
|
|
{ |
48
|
|
|
$this->assertSame('€', CurrencyInfo::getSymbolForCurrency('EUR')); |
49
|
|
|
$this->assertSame('$', CurrencyInfo::getSymbolForCurrency('USD')); |
50
|
|
|
$this->assertSame('IDR', CurrencyInfo::getSymbolForCurrency('IDR')); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function testReturnsTheNativeSymbolMap() |
54
|
|
|
{ |
55
|
|
|
$map = CurrencyInfo::getNativeSymbolMap(); |
56
|
|
|
$this->assertInternalType('array', $map); |
57
|
|
|
$this->assertNotEmpty($map); |
58
|
|
|
$this->assertContainsOnly('string', $map); |
59
|
|
|
$this->assertArrayHasKey('IDR', $map); |
60
|
|
|
$this->assertSame('Rp', $map['IDR']); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testReturnsTheNativeSymbolForGivenCurrency() |
64
|
|
|
{ |
65
|
|
|
$this->assertSame('€', CurrencyInfo::getNativeSymbolForCurrency('EUR')); |
66
|
|
|
$this->assertSame('$', CurrencyInfo::getNativeSymbolForCurrency('USD')); |
67
|
|
|
$this->assertSame('Rp', CurrencyInfo::getNativeSymbolForCurrency('IDR')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
View Code Duplication |
public function testReturnsTheFractionDigitsMap() |
71
|
|
|
{ |
72
|
|
|
$map = CurrencyInfo::getFractionDigitsMap(); |
73
|
|
|
$this->assertInternalType('array', $map); |
74
|
|
|
$this->assertNotEmpty($map); |
75
|
|
|
$this->assertContainsOnly('int', $map); |
76
|
|
|
$this->assertArrayHasKey('IDR', $map); |
77
|
|
|
$this->assertSame(0, $map['IDR']); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testReturnsTheFractionDigitsForGivenCurrency() |
81
|
|
|
{ |
82
|
|
|
$this->assertSame(2, CurrencyInfo::getFractionDigitsForCurrency('EUR')); |
83
|
|
|
$this->assertSame(0, CurrencyInfo::getFractionDigitsForCurrency('IDR')); |
84
|
|
|
$this->assertSame(3, CurrencyInfo::getFractionDigitsForCurrency('JOD')); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
View Code Duplication |
public function testReturnsTheRoundingMap() |
88
|
|
|
{ |
89
|
|
|
$map = CurrencyInfo::getRoundingMap(); |
90
|
|
|
$this->assertInternalType('array', $map); |
91
|
|
|
$this->assertNotEmpty($map); |
92
|
|
|
$this->assertContainsOnly('float', $map); |
93
|
|
|
$this->assertSame(0.0, $map['IDR']); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testReturnsTheRoundingForGivenCurrency() |
97
|
|
|
{ |
98
|
|
|
$this->assertSame(0.0, CurrencyInfo::getRoundingForCurrency('EUR')); |
99
|
|
|
$this->assertGreaterThan(0.01, CurrencyInfo::getRoundingForCurrency('CHF')); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|