1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace hiqdev\php\billing\tests\unit\Money; |
6
|
|
|
|
7
|
|
|
use Generator; |
8
|
|
|
use hiqdev\php\billing\Money\MultipliedMoney; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class MultipliedMoneyTest |
13
|
|
|
* |
14
|
|
|
* @author Dmytro Naumenko <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class MultipliedMoneyTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param numeric-string $amountCents |
|
|
|
|
20
|
|
|
* @dataProvider moneyParsingProvider |
21
|
|
|
*/ |
22
|
|
|
public function testMultipliedMoneyParsing(string $amountCents, string $expectedCents, int $expectedMultiplier): void |
23
|
|
|
{ |
24
|
|
|
$currencyCode = 'USD'; |
25
|
|
|
$multipliedMoney = MultipliedMoney::create($amountCents, $currencyCode); |
26
|
|
|
$this->assertSame($currencyCode, $multipliedMoney->getCurrency()->getCode()); |
|
|
|
|
27
|
|
|
$this->assertSame($expectedCents, $multipliedMoney->getAmount()); |
28
|
|
|
$this->assertSame($expectedMultiplier, $multipliedMoney->multiplier()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function moneyParsingProvider(): Generator |
32
|
|
|
{ |
33
|
|
|
yield ['0', '0', 1]; |
34
|
|
|
yield ['1', '100', 1]; |
35
|
|
|
yield ['103', '10300', 1]; |
36
|
|
|
yield ['1.32', '13200', 100]; |
37
|
|
|
yield ['0.01', '100', 100]; |
38
|
|
|
yield ['0.001', '100', 1000]; |
39
|
|
|
yield ['0.0001', '100', 10000]; |
40
|
|
|
yield ['2.1', '2100', 10]; |
41
|
|
|
yield ['-2.234', '-223400', 1000]; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|