1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace StraTDeS\VO\Tests\Single; |
4
|
|
|
|
5
|
|
|
use StraTDeS\VO\Single\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
|
|
|
public function testGivenTwoEqualCurrenciesEqualReturnsTrue(): void |
49
|
|
|
{ |
50
|
|
|
// Arrange |
51
|
|
|
$currency1 = Currency::fromValue(Currency::USD); |
52
|
|
|
$currency2 = Currency::fromValue(Currency::USD); |
53
|
|
|
|
54
|
|
|
// Act |
55
|
|
|
$equal = $currency1->equal($currency2); |
56
|
|
|
|
57
|
|
|
// Assert |
58
|
|
|
$this->assertTrue($equal); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testGivenTwoNotEqualCurrenciesEqualReturnsFalse(): void |
62
|
|
|
{ |
63
|
|
|
// Arrange |
64
|
|
|
$currency1 = Currency::fromValue(Currency::USD); |
65
|
|
|
$currency2 = Currency::fromValue(Currency::EUR); |
66
|
|
|
|
67
|
|
|
// Act |
68
|
|
|
$equal = $currency1->equal($currency2); |
69
|
|
|
|
70
|
|
|
// Assert |
71
|
|
|
$this->assertFalse($equal); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|