|
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\Decoder\Record; |
|
10
|
|
|
use Genkgo\Camt\DTO; |
|
11
|
|
|
use PHPUnit\Framework; |
|
12
|
|
|
use SimpleXMLElement; |
|
13
|
|
|
|
|
14
|
|
|
class RecordTest extends Framework\TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var Decoder\Entry&Framework\MockObject\MockObject |
|
18
|
|
|
*/ |
|
19
|
|
|
private $mockedEntryDecoder; |
|
20
|
|
|
|
|
21
|
|
|
private Record $decoder; |
|
22
|
|
|
|
|
23
|
|
|
protected function setUp(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$this->mockedEntryDecoder = $this->createMock(Decoder\Entry::class); |
|
26
|
|
|
$this->decoder = new Record($this->mockedEntryDecoder, new Decoder\Date()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testItDoesNotAddBalancesIfThereAreNoneInXml(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$record = $this->createMock(Camt053\DTO\Statement::class); |
|
32
|
|
|
|
|
33
|
|
|
$record |
|
34
|
|
|
->expects(self::never()) |
|
35
|
|
|
->method('addBalance') |
|
36
|
|
|
->with(self::anything()); |
|
37
|
|
|
|
|
38
|
|
|
$xmlRecord = new SimpleXMLElement('<content></content>'); |
|
39
|
|
|
$this->decoder->addBalances($record, $xmlRecord); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testItAddsBalancesIfThereArePresentInXml(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$record = $this->createMock(Camt053\DTO\Statement::class); |
|
45
|
|
|
|
|
46
|
|
|
$record |
|
47
|
|
|
->expects(self::exactly(2)) |
|
48
|
|
|
->method('addBalance') |
|
49
|
|
|
->with(self::isInstanceOf(DTO\Balance::class)); |
|
50
|
|
|
|
|
51
|
|
|
$this->decoder->addBalances($record, $this->getXmlRecord()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testItAddsNoEntriesIfThereAreNoneInXml(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$record = $this->createMock(DTO\Record::class); |
|
57
|
|
|
|
|
58
|
|
|
$record |
|
59
|
|
|
->expects(self::never()) |
|
60
|
|
|
->method('addEntry') |
|
61
|
|
|
->with(self::anything()); |
|
62
|
|
|
|
|
63
|
|
|
$this->mockedEntryDecoder |
|
64
|
|
|
->expects(self::never()) |
|
65
|
|
|
->method('addTransactionDetails') |
|
66
|
|
|
->with( |
|
67
|
|
|
self::anything(), |
|
68
|
|
|
self::anything(), |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$xmlRecord = new SimpleXMLElement('<content></content>'); |
|
72
|
|
|
|
|
73
|
|
|
$this->decoder->addEntries($record, $xmlRecord); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testItAddsEntriesIfThereArePresentInXml(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$record = $this->createMock(DTO\Record::class); |
|
79
|
|
|
|
|
80
|
|
|
$record |
|
81
|
|
|
->expects(self::once()) |
|
82
|
|
|
->method('addEntry') |
|
83
|
|
|
->with(self::isInstanceOf(DTO\Entry::class)); |
|
84
|
|
|
|
|
85
|
|
|
$this->mockedEntryDecoder |
|
86
|
|
|
->expects(self::once()) |
|
87
|
|
|
->method('addTransactionDetails') |
|
88
|
|
|
->with( |
|
89
|
|
|
self::isInstanceOf(DTO\Entry::class), |
|
90
|
|
|
self::isInstanceOf(SimpleXMLElement::class), |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
$this->decoder->addEntries($record, $this->getXmlRecord()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
private function getXmlRecord(): SimpleXMLElement |
|
97
|
|
|
{ |
|
98
|
|
|
$xmlContent = <<<XML |
|
99
|
|
|
<content> |
|
100
|
|
|
<Bal> |
|
101
|
|
|
<Amt Ccy="EUR">24.22</Amt> |
|
102
|
|
|
<Dt> |
|
103
|
|
|
<Dt>2014-12-30</Dt> |
|
104
|
|
|
</Dt> |
|
105
|
|
|
<CdtDbtInd>DBIT</CdtDbtInd> |
|
106
|
|
|
<Tp> |
|
107
|
|
|
<CdOrPrtry> |
|
108
|
|
|
<Cd>OPBD</Cd> |
|
109
|
|
|
</CdOrPrtry> |
|
110
|
|
|
</Tp> |
|
111
|
|
|
</Bal> |
|
112
|
|
|
<Bal> |
|
113
|
|
|
<Amt Ccy="EUR">80.22</Amt> |
|
114
|
|
|
<Dt> |
|
115
|
|
|
<Dt>2014-12-30</Dt> |
|
116
|
|
|
</Dt> |
|
117
|
|
|
<Tp> |
|
118
|
|
|
<CdOrPrtry> |
|
119
|
|
|
<Cd>CLAV</Cd> |
|
120
|
|
|
</CdOrPrtry> |
|
121
|
|
|
</Tp> |
|
122
|
|
|
<CdtDbtInd>DBIT</CdtDbtInd> |
|
123
|
|
|
</Bal> |
|
124
|
|
|
<Ntry> |
|
125
|
|
|
<Amt Ccy="EUR">1.42</Amt> |
|
126
|
|
|
<BookgDt> |
|
127
|
|
|
<Dt></Dt> |
|
128
|
|
|
</BookgDt> |
|
129
|
|
|
<ValDt> |
|
130
|
|
|
<Dt></Dt> |
|
131
|
|
|
</ValDt> |
|
132
|
|
|
<CdtDbtInd>DBIT</CdtDbtInd> |
|
133
|
|
|
<RvslInd>true</RvslInd> |
|
134
|
|
|
<NtryRef>lorem</NtryRef> |
|
135
|
|
|
<AcctSvcrRef>ipsum</AcctSvcrRef> |
|
136
|
|
|
<NtryDtls> |
|
137
|
|
|
<Btch> |
|
138
|
|
|
<PmtInfId>id</PmtInfId> |
|
139
|
|
|
</Btch> |
|
140
|
|
|
</NtryDtls> |
|
141
|
|
|
</Ntry> |
|
142
|
|
|
</content> |
|
143
|
|
|
XML; |
|
144
|
|
|
|
|
145
|
|
|
return new SimpleXMLElement($xmlContent); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|