1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Genkgo\TestCamt\Unit\Decoder; |
6
|
|
|
|
7
|
|
|
use Genkgo\Camt\Camt053; |
8
|
|
|
use Genkgo\Camt\Decoder; |
9
|
|
|
use Genkgo\Camt\DTO; |
10
|
|
|
use Genkgo\TestCamt\AbstractTestCase; |
11
|
|
|
use Prophecy\Argument; |
12
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
13
|
|
|
use SimpleXMLElement; |
14
|
|
|
|
15
|
|
|
class RecordTest extends AbstractTestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var ObjectProphecy |
19
|
|
|
*/ |
20
|
|
|
private $mockedEntryDecoder; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Decoder\Record |
24
|
|
|
*/ |
25
|
|
|
private $decoder; |
26
|
|
|
|
27
|
|
|
protected function setUp(): void |
28
|
|
|
{ |
29
|
|
|
$entryTransactionDetail = $this->prophesize(Decoder\EntryTransactionDetail::class); |
30
|
|
|
$this->mockedEntryDecoder = $this |
31
|
|
|
->prophesize(Decoder\Entry::class) |
32
|
|
|
->willBeConstructedWith([$entryTransactionDetail->reveal()]); |
33
|
|
|
$this->decoder = new Decoder\Record($this->mockedEntryDecoder->reveal(), new Decoder\Date()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testItDoesNotAddBalancesIfThereAreNoneInXml(): void |
37
|
|
|
{ |
38
|
|
|
$record = $this->prophesize(Camt053\DTO\Statement::class); |
39
|
|
|
$record->addBalance(Argument::any())->shouldNotBeCalled(); |
40
|
|
|
|
41
|
|
|
$xmlRecord = new SimpleXMLElement('<content></content>'); |
42
|
|
|
$this->decoder->addBalances($record->reveal(), $xmlRecord); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testItAddsBalancesIfThereArePresentInXml(): void |
46
|
|
|
{ |
47
|
|
|
$record = $this->prophesize(Camt053\DTO\Statement::class); |
48
|
|
|
$record->addBalance(Argument::type(DTO\Balance::class))->shouldBeCalled(); |
49
|
|
|
|
50
|
|
|
$this->decoder->addBalances($record->reveal(), $this->getXmlRecord()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testItAddsNoEntriesIfThereAreNoneInXml(): void |
54
|
|
|
{ |
55
|
|
|
$record = $this->prophesize(DTO\Record::class); |
56
|
|
|
$this->mockedEntryDecoder->addTransactionDetails(Argument::any(), Argument::any())->shouldNotBeCalled(); |
57
|
|
|
$record->addEntry(Argument::any())->shouldNotBeCalled(); |
58
|
|
|
$xmlRecord = new SimpleXMLElement('<content></content>'); |
59
|
|
|
|
60
|
|
|
$this->decoder->addEntries($record->reveal(), $xmlRecord); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testItAddsEntriesIfThereArePresentInXml(): void |
64
|
|
|
{ |
65
|
|
|
$record = $this->prophesize(DTO\Record::class); |
66
|
|
|
$this |
67
|
|
|
->mockedEntryDecoder |
68
|
|
|
->addTransactionDetails( |
69
|
|
|
Argument::type(DTO\Entry::class), |
70
|
|
|
Argument::type('\SimpleXMLElement') |
71
|
|
|
) |
72
|
|
|
->shouldBeCalled(); |
73
|
|
|
$record->addEntry(Argument::type(DTO\Entry::class))->shouldBeCalled(); |
74
|
|
|
|
75
|
|
|
$this->decoder->addEntries($record->reveal(), $this->getXmlRecord()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function getXmlRecord(): SimpleXMLElement |
79
|
|
|
{ |
80
|
|
|
$xmlContent = <<<XML |
81
|
|
|
<content> |
82
|
|
|
<Bal> |
83
|
|
|
<Amt Ccy="EUR">24.22</Amt> |
84
|
|
|
<Dt> |
85
|
|
|
<Dt>2014-12-30</Dt> |
86
|
|
|
</Dt> |
87
|
|
|
<CdtDbtInd>DBIT</CdtDbtInd> |
88
|
|
|
<Tp> |
89
|
|
|
<CdOrPrtry> |
90
|
|
|
<Cd>OPBD</Cd> |
91
|
|
|
</CdOrPrtry> |
92
|
|
|
</Tp> |
93
|
|
|
</Bal> |
94
|
|
|
<Ntry> |
95
|
|
|
<Amt Ccy="EUR">1.42</Amt> |
96
|
|
|
<BookgDt> |
97
|
|
|
<Dt></Dt> |
98
|
|
|
</BookgDt> |
99
|
|
|
<ValDt> |
100
|
|
|
<Dt></Dt> |
101
|
|
|
</ValDt> |
102
|
|
|
<CdtDbtInd>DBIT</CdtDbtInd> |
103
|
|
|
<RvslInd>true</RvslInd> |
104
|
|
|
<NtryRef>lorem</NtryRef> |
105
|
|
|
<AcctSvcrRef>ipsum</AcctSvcrRef> |
106
|
|
|
<NtryDtls> |
107
|
|
|
<Btch> |
108
|
|
|
<PmtInfId>id</PmtInfId> |
109
|
|
|
</Btch> |
110
|
|
|
</NtryDtls> |
111
|
|
|
</Ntry> |
112
|
|
|
</content> |
113
|
|
|
XML; |
114
|
|
|
|
115
|
|
|
return new SimpleXMLElement($xmlContent); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|