|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace StraTDeS\VO\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use StraTDeS\VO\Currency; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class CurrencyTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function dataProvider(): array |
|
11
|
|
|
{ |
|
12
|
|
|
return [ |
|
13
|
|
|
['EUR', true, 978, 2], |
|
14
|
|
|
['USD', true, 840, 2], |
|
15
|
|
|
['BHD', true, 48, 3], |
|
16
|
|
|
['BIF', true, 108, 0], |
|
17
|
|
|
['BMD', true, 60, 2], |
|
18
|
|
|
['BND', true, 96, 2], |
|
19
|
|
|
['AAA', false, null, null], |
|
20
|
|
|
['BBB', false, null, null], |
|
21
|
|
|
['CCC', false, null, null], |
|
22
|
|
|
['DDD', false, null, null], |
|
23
|
|
|
]; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param string $currency |
|
28
|
|
|
* @param bool $isValid |
|
29
|
|
|
* @param int|null $iso |
|
30
|
|
|
* @param int|null $decimals |
|
31
|
|
|
* @dataProvider dataProvider |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testGivenACurrencyItIsValidAndHaveAValidConfigOrIsInvalidAndThrowsException( |
|
34
|
|
|
string $currency, bool $isValid, ?int $iso, ?int $decimals |
|
35
|
|
|
): void |
|
36
|
|
|
{ |
|
37
|
|
|
if(!$isValid) { |
|
38
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
39
|
|
|
$this->expectExceptionMessage("$currency is not an allowed currency"); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$currency = Currency::fromValue($currency); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals($iso, $currency->config()->iso()); |
|
45
|
|
|
$this->assertEquals($decimals, $currency->config()->decimals()); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|