CurrencyInfoTest   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 130
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A assertStaticMethodWasCalled() 0 5 1
A assertStaticMethodWasCalledWithParams() 0 8 2
A __callStatic() 0 5 1
A setUp() 0 7 1
A testImplementsCurrencyInfoInterface() 0 4 1
A testGetMapIsDelegatedToTheStaticCurrencyInfo() 0 6 1
A testGetMapForCurrencyIsDelegatedToTheStaticCurrencyInfo() 0 6 1
A testGetSymbolMapIsDelegatedToTheStaticCurrencyInfo() 0 6 1
A testGetSymbolForCurrencyIsDelegatedToTheStaticCurrencyInfo() 0 6 1
A testGetNativeSymbolMapIsDelegatedToTheStaticCurrencyInfo() 0 6 1
A testGetNativeSymbolForCurrencyIsDelegatedToTheStaticCurrencyInfo() 0 6 1
A testGetFractionDigitMapIsDelegatedToTheStaticCurrencyInfo() 0 6 1
A testGetFractionDigitForCurrencyIsDelegatedToTheStaticCurrencyInfo() 0 6 1
A testGetRoundingMapIsDelegatedToTheStaticCurrencyInfo() 0 6 1
A testGetRoundingForCurrencyIsDelegatedToTheStaticCurrencyInfo() 0 6 1
1
<?php
2
3
namespace VinaiKopp\CurrencyInfo;
4
5
/**
6
 * @covers \VinaiKopp\CurrencyInfo\CurrencyInfo
7
 */
8
class CurrencyInfoTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @var array
12
     */
13
    private static $staticMethodCalls;
14
15
    /**
16
     * @var mixed
17
     */
18
    private static $staticMethodCallReturnValue;
19
20
    /**
21
     * @var CurrencyInfo
22
     */
23
    private $currencyInfo;
24
25
    private function assertStaticMethodWasCalled($methodName)
26
    {
27
        $message = sprintf('Static method "%s" was not called', $methodName);
28
        $this->assertArrayHasKey($methodName, self::$staticMethodCalls, $message);
29
    }
30
31
    /**
32
     * @param string $methodName
33
     * @param mixed[] $expectedArgs
34
     */
35
    private function assertStaticMethodWasCalledWithParams($methodName, ...$expectedArgs)
36
    {
37
        if (!isset(self::$staticMethodCalls[$methodName])) {
38
            $this->fail(sprintf('Static method "%s" was not called', $methodName));
39
        }
40
        $message = 'Expected static method call arguments do not match';
41
        $this->assertSame($expectedArgs, self::$staticMethodCalls[$methodName], $message);
42
    }
43
44
    /**
45
     * @param string $name
46
     * @param mixed[] $arguments
47
     * @return mixed
48
     */
49
    public static function __callStatic($name, array $arguments)
50
    {
51
        self::$staticMethodCalls[$name] = $arguments;
52
        return self::$staticMethodCallReturnValue;
53
    }
54
55
    protected function setUp()
56
    {
57
        self::$staticMethodCalls = [];
58
        self::$staticMethodCallReturnValue = [];
59
        $this->currencyInfo = new CurrencyInfo();
60
        $this->currencyInfo->staticCurrencyInfoClass = __CLASS__;
61
    }
62
63
    public function testImplementsCurrencyInfoInterface()
64
    {
65
        $this->assertInstanceOf(CurrencyInfoInterface::class, $this->currencyInfo);
66
    }
67
68
    public function testGetMapIsDelegatedToTheStaticCurrencyInfo()
69
    {
70
        self::$staticMethodCallReturnValue = ['dummy' => ['foo' => 'bar']];
71
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getMap());
72
        $this->assertStaticMethodWasCalled('getMap');
73
    }
74
75
    public function testGetMapForCurrencyIsDelegatedToTheStaticCurrencyInfo()
76
    {
77
        self::$staticMethodCallReturnValue = ['dummy' => ['buz' => 'qux']];
78
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getMapForCurrency('XXX'));
79
        $this->assertStaticMethodWasCalledWithParams('getMapForCurrency', 'XXX');
80
    }
81
82
    public function testGetSymbolMapIsDelegatedToTheStaticCurrencyInfo()
83
    {
84
        self::$staticMethodCallReturnValue = ['foo' => 'bar'];
85
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getSymbolMap());
86
        $this->assertStaticMethodWasCalledWithParams('getSymbolMap');
87
    }
88
89
    public function testGetSymbolForCurrencyIsDelegatedToTheStaticCurrencyInfo()
90
    {
91
        self::$staticMethodCallReturnValue = 'BAR';
92
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getSymbolForCurrency('YYY'));
93
        $this->assertStaticMethodWasCalledWithParams('getSymbolForCurrency', 'YYY');
94
    }
95
96
    public function testGetNativeSymbolMapIsDelegatedToTheStaticCurrencyInfo()
97
    {
98
        self::$staticMethodCallReturnValue = ['some' => 'map'];
99
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getNativeSymbolMap());
100
        $this->assertStaticMethodWasCalled('getNativeSymbolMap');
101
    }
102
103
    public function testGetNativeSymbolForCurrencyIsDelegatedToTheStaticCurrencyInfo()
104
    {
105
        self::$staticMethodCallReturnValue = 'Foo';
106
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getNativeSymbolForCurrency('ZZZ'));
107
        $this->assertStaticMethodWasCalledWithParams('getNativeSymbolForCurrency', 'ZZZ');
108
    }
109
110
    public function testGetFractionDigitMapIsDelegatedToTheStaticCurrencyInfo()
111
    {
112
        self::$staticMethodCallReturnValue = ['another' => 'map'];
113
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getFractionDigitsMap());
114
        $this->assertStaticMethodWasCalled('getFractionDigitsMap');
115
    }
116
117
    public function testGetFractionDigitForCurrencyIsDelegatedToTheStaticCurrencyInfo()
118
    {
119
        self::$staticMethodCallReturnValue = 'Qux';
120
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getFractionDigitsForCurrency('AAA'));
121
        $this->assertStaticMethodWasCalledWithParams('getFractionDigitsForCurrency', 'AAA');
122
    }
123
124
    public function testGetRoundingMapIsDelegatedToTheStaticCurrencyInfo()
125
    {
126
        self::$staticMethodCallReturnValue = ['rounding' => 'stuff'];
127
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getRoundingMap());
128
        $this->assertStaticMethodWasCalled('getRoundingMap');
129
    }
130
131
    public function testGetRoundingForCurrencyIsDelegatedToTheStaticCurrencyInfo()
132
    {
133
        self::$staticMethodCallReturnValue = '111';
134
        $this->assertSame(self::$staticMethodCallReturnValue, $this->currencyInfo->getRoundingForCurrency('BBB'));
135
        $this->assertStaticMethodWasCalledWithParams('getRoundingForCurrency', 'BBB');
136
    }
137
}
138