Passed
Push — master ( 403b97...3809dd )
by Vinai
02:33
created

testReturnsTheFractionDigitsForGivenCurrency()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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