GenericCurrencyInfoAccessTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 56
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A infoTypeCodeDataProvider() 0 10 1
A testReturnsTheInfoTypeMapForGivenCurrency() 0 7 1
A testReturnsTheValueForGivenInfoTypeAndCurrency() 0 5 1
A testThrowsExceptionIfCurrencyIsNotKnown() 0 6 1
A testReturnsTheMapForAGivenCurrency() 0 8 1
1
<?php
2
3
namespace VinaiKopp\CurrencyInfo\StaticAccess\Internal;
4
5
use VinaiKopp\CurrencyInfo\Build\CurrencyInfoKeys;
6
use VinaiKopp\CurrencyInfo\StaticAccess\CurrencyInfo;
7
use VinaiKopp\CurrencyInfo\Exception\UnknownCurrencyException;
8
9
/**
10
 * @covers \VinaiKopp\CurrencyInfo\StaticAccess\Internal\GenericCurrencyInfoAccess
11
 */
12
class GenericCurrencyInfoAccessTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @return array[]
16
     */
17
    public function infoTypeCodeDataProvider()
18
    {
19
        return [
20
            [CurrencyInfo::SYMBOL, 'string'],
21
            [CurrencyInfo::SYMBOL_NATIVE, 'string'],
22
            [CurrencyInfo::CODE, 'string'],
23
            [CurrencyInfo::FRACTION_DIGITS, 'int'],
24
            [CurrencyInfo::ROUNDING, 'float'],
25
        ];
26
    }
27
28
    /**
29
     * @param string $infoType
30
     * @param string $expectedType
31
     * @dataProvider infoTypeCodeDataProvider
32
     */
33
    public function testReturnsTheInfoTypeMapForGivenCurrency($infoType, $expectedType)
34
    {
35
        $map = GenericCurrencyInfoAccess::getCurrencyInfoSubMap($infoType);
36
        $this->assertInternalType('array', $map);
37
        $this->assertNotEmpty($map);
38
        $this->assertContainsOnly($expectedType, $map);
39
    }
40
41
    /**
42
     * @param string $infoType
43
     * @param string $expectedType
44
     * @dataProvider infoTypeCodeDataProvider
45
     */
46
    public function testReturnsTheValueForGivenInfoTypeAndCurrency($infoType, $expectedType)
47
    {
48
        $value = GenericCurrencyInfoAccess::getCurrencyInfoItemForCurrency($infoType, 'EUR');
49
        $this->assertInternalType($expectedType, $value);
50
    }
51
52
    public function testThrowsExceptionIfCurrencyIsNotKnown()
53
    {
54
        $this->expectException(UnknownCurrencyException::class);
55
        $this->expectExceptionMessage('The currency "UNKNOWN" is not known');
56
        GenericCurrencyInfoAccess::getCurrencyInfoItemForCurrency(CurrencyInfo::SYMBOL, 'UNKNOWN');
57
    }
58
59
    public function testReturnsTheMapForAGivenCurrency()
60
    {
61
        $euroInfo = CurrencyInfo::getMapForCurrency('EUR');
62
        $currencyInfoKeys = new CurrencyInfoKeys();
63
        array_map(function ($infoKey) use ($euroInfo) {
64
            $this->assertArrayHasKey($infoKey, $euroInfo);
65
        }, $currencyInfoKeys->get());
66
    }
67
}
68