|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Genkgo\TestCamt\Util; |
|
6
|
|
|
|
|
7
|
|
|
use Genkgo\Camt\Util\MoneyFactory; |
|
8
|
|
|
use Money\Money; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use SimpleXMLElement; |
|
11
|
|
|
|
|
12
|
|
|
class MoneyFactoryTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @dataProvider providerCreate |
|
16
|
|
|
*/ |
|
17
|
|
|
public function testCreate(string $amount, ?string $CdtDbtInd, Money $expected): void |
|
18
|
|
|
{ |
|
19
|
|
|
$factory = new MoneyFactory(); |
|
20
|
|
|
|
|
21
|
|
|
$xmlAmount = new SimpleXMLElement($amount); |
|
22
|
|
|
$xmlCdtDbtInd = $CdtDbtInd ? new SimpleXMLElement($CdtDbtInd) : null; |
|
23
|
|
|
$actual = $factory->create($xmlAmount, $xmlCdtDbtInd); |
|
24
|
|
|
|
|
25
|
|
|
self::assertTrue($actual->equals($expected)); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public static function providerCreate(): array |
|
29
|
|
|
{ |
|
30
|
|
|
return [ |
|
31
|
|
|
['<Amt Ccy="CHF">27.50</Amt>', null, Money::CHF(2750)], |
|
32
|
|
|
['<Amt Ccy="CHF">27.50</Amt>', '<CdtDbtInd>DBIT</CdtDbtInd>', Money::CHF(-2750)], |
|
33
|
|
|
['<Amt Ccy="CHF">27.50</Amt>', '<CdtDbtInd>CRDT</CdtDbtInd>', Money::CHF(2750)], |
|
34
|
|
|
['<Amt Ccy="JPY">27</Amt>', null, Money::JPY(27)], |
|
35
|
|
|
['<Amt Ccy="JPY">27</Amt>', '<CdtDbtInd>DBIT</CdtDbtInd>', Money::JPY(-27)], |
|
36
|
|
|
['<Amt Ccy="JPY">27</Amt>', '<CdtDbtInd>CRDT</CdtDbtInd>', Money::JPY(27)], |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|