1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace StraTDeS\VO\Tests; |
4
|
|
|
|
5
|
|
|
use StraTDeS\VO\Currency; |
6
|
|
|
use StraTDeS\VO\Money; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class MoneyTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function dataProvider(): array |
12
|
|
|
{ |
13
|
|
|
return [ |
14
|
|
|
[12456, 124.56, Currency::fromValue(Currency::EUR), 'EUR 124.56'], |
15
|
|
|
[2346656, 23466.56, Currency::fromValue(Currency::USD), 'USD 23,466.56'], |
16
|
|
|
[536435345, 53643.5345, Currency::fromValue(Currency::UYW), 'UYW 53,643.5345'], |
17
|
|
|
]; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @dataProvider dataProvider |
22
|
|
|
* @param int $amount |
23
|
|
|
* @param float $amountFloat |
24
|
|
|
* @param Currency $currency |
25
|
|
|
* @param string $formatted |
26
|
|
|
*/ |
27
|
|
|
public function testGivenValidDataItReturnsAValidMoneyVO( |
28
|
|
|
int $amount, |
29
|
|
|
float $amountFloat, |
30
|
|
|
Currency $currency, |
31
|
|
|
string $formatted |
32
|
|
|
): void |
33
|
|
|
{ |
34
|
|
|
// Act |
35
|
|
|
$money = Money::create($amount, $currency); |
36
|
|
|
|
37
|
|
|
// Assert |
38
|
|
|
$this->assertInstanceOf(Money::class, $money); |
39
|
|
|
$this->assertEquals($amount, $money->amount()); |
40
|
|
|
$this->assertEquals($currency, $money->currency()); |
41
|
|
|
$this->assertEquals($amountFloat, $money->amountFloat()); |
42
|
|
|
$this->assertEquals($formatted, $money->formatted()); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|