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\Date; |
9
|
|
|
use Genkgo\Camt\DTO; |
10
|
|
|
use Genkgo\TestCamt\AbstractTestCase; |
11
|
|
|
use Money\Money; |
12
|
|
|
use Prophecy\Argument; |
13
|
|
|
use SimpleXMLElement; |
14
|
|
|
|
15
|
|
|
class EntryTransactionDetailTest extends AbstractTestCase |
16
|
|
|
{ |
17
|
|
|
public function testItDoesNotAddReferenceIfThereIsNoneInXml(): void |
18
|
|
|
{ |
19
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
20
|
|
|
$detail->setReference(Argument::any())->shouldNotBeCalled(); |
21
|
|
|
|
22
|
|
|
$xmlDetail = new SimpleXMLElement('<content></content>'); |
23
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addReference($detail->reveal(), $xmlDetail); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testItAddsReferenceIfItIsPresentInXml(): void |
27
|
|
|
{ |
28
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
29
|
|
|
$detail->setReference(Argument::type(DTO\Reference::class))->shouldBeCalled(); |
30
|
|
|
|
31
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addReference($detail->reveal(), $this->getXmlDetail()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testItDoesNotAddAdditionalTransactionInformationIfThereIsNoneInXml(): void |
35
|
|
|
{ |
36
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
37
|
|
|
$detail->setAdditionalTransactionInformation(Argument::any())->shouldNotBeCalled(); |
38
|
|
|
|
39
|
|
|
$xmlDetail = new SimpleXMLElement('<content></content>'); |
40
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addAdditionalTransactionInformation($detail->reveal(), $xmlDetail); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testItAddsAdditionalTransactionInformationIfItIsPresentInXml(): void |
44
|
|
|
{ |
45
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
46
|
|
|
$detail->setAdditionalTransactionInformation( |
47
|
|
|
Argument::type(DTO\AdditionalTransactionInformation::class) |
48
|
|
|
)->shouldBeCalled(); |
49
|
|
|
|
50
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addAdditionalTransactionInformation($detail->reveal(), $this->getXmlDetail()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testItDoesNotAddRemittanceInformationIfThereIsNoneInXml(): void |
54
|
|
|
{ |
55
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
56
|
|
|
$detail->setRemittanceInformation(Argument::any())->shouldNotBeCalled(); |
57
|
|
|
|
58
|
|
|
$xmlDetail = new SimpleXMLElement('<content></content>'); |
59
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRemittanceInformation($detail->reveal(), $xmlDetail); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testItAddsRemittanceInformationAndCreditorReferenceIfItIsPresentInXml(): void |
63
|
|
|
{ |
64
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
65
|
|
|
$detail->setRemittanceInformation(Argument::type(DTO\RemittanceInformation::class))->shouldBeCalled(); |
66
|
|
|
|
67
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRemittanceInformation($detail->reveal(), $this->getXmlDetail()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testItAddsRemittanceInformationIfItIsPresentInXml(): void |
71
|
|
|
{ |
72
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
73
|
|
|
$detail->setRemittanceInformation(Argument::type(DTO\RemittanceInformation::class))->shouldBeCalled(); |
74
|
|
|
|
75
|
|
|
$xmlDetail = new SimpleXMLElement('<content><RmtInf><Ustrd>Lorem</Ustrd></RmtInf></content>'); |
76
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRemittanceInformation($detail->reveal(), $xmlDetail); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testItDoesNotAddReturnInformationIfThereIsNoneInXml(): void |
80
|
|
|
{ |
81
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
82
|
|
|
$detail->setReturnInformation(Argument::any())->shouldNotBeCalled(); |
83
|
|
|
|
84
|
|
|
$xmlDetail = new SimpleXMLElement('<content></content>'); |
85
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addReturnInformation($detail->reveal(), $xmlDetail); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testItAddsReturnInformationIfItIsPresentInXml(): void |
89
|
|
|
{ |
90
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
91
|
|
|
$detail->setReturnInformation( |
92
|
|
|
Argument::type(DTO\ReturnInformation::class) |
93
|
|
|
)->shouldBeCalled(); |
94
|
|
|
|
95
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addReturnInformation($detail->reveal(), $this->getXmlDetail()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testItDoesNotAddRelatedPartiesIfThereIsNoneInXml(): void |
99
|
|
|
{ |
100
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
101
|
|
|
$detail->addRelatedParty(Argument::any())->shouldNotBeCalled(); |
102
|
|
|
|
103
|
|
|
$xmlDetail = new SimpleXMLElement('<content></content>'); |
104
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRelatedParties($detail->reveal(), $xmlDetail); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testItAddsRelatedPartiesIfIsPresentInXml(): void |
108
|
|
|
{ |
109
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
110
|
|
|
$detail->addRelatedParty(Argument::type(DTO\RelatedParty::class))->shouldBeCalled(); |
111
|
|
|
|
112
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRelatedParties($detail->reveal(), $this->getXmlDetail()); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testItDoesNotAddRelatedDatesIfThereIsNoneInXml(): void |
116
|
|
|
{ |
117
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
118
|
|
|
$detail->setRelatedDates(Argument::any())->shouldNotBeCalled(); |
119
|
|
|
|
120
|
|
|
$xmlDetail = new SimpleXMLElement('<content></content>'); |
121
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRelatedDates($detail->reveal(), $xmlDetail); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function testItAddsRelatedDatesIfIsPresentInXml(): void |
125
|
|
|
{ |
126
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
127
|
|
|
$detail->setRelatedDates(Argument::type(DTO\RelatedDates::class))->shouldBeCalled(); |
128
|
|
|
|
129
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRelatedDates($detail->reveal(), $this->getXmlDetail()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testItDoesNotAddChargesIfThereIsNoneInXml(): void |
133
|
|
|
{ |
134
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
135
|
|
|
$detail->setCharges(Argument::any())->shouldNotBeCalled(); |
136
|
|
|
|
137
|
|
|
$xmlDetail = new SimpleXMLElement('<content></content>'); |
138
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addCharges($detail->reveal(), $xmlDetail); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testItAddsChargesIfIsPresentInXml(): void |
142
|
|
|
{ |
143
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
144
|
|
|
$detail->setCharges(Argument::type(DTO\Charges::class))->shouldBeCalled(); |
145
|
|
|
|
146
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addCharges($detail->reveal(), $this->getXmlDetail()); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testItAddsAmountDetailsIfIsPresentInXmsl(): void |
150
|
|
|
{ |
151
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
152
|
|
|
$detail->setAmountDetails(Argument::type(Money::class))->shouldBeCalled(); |
153
|
|
|
|
154
|
|
|
$CdtDbtInd = new SimpleXMLElement('<content>DBIT</content>'); |
155
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addAmountDetails($detail->reveal(), $this->getXmlDetail(), $CdtDbtInd); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testItAddsAmountIfIsPresentInXmsl(): void |
159
|
|
|
{ |
160
|
|
|
$detail = $this->prophesize(DTO\EntryTransactionDetail::class); |
161
|
|
|
$detail->setAmount(Argument::type(Money::class))->shouldBeCalled(); |
162
|
|
|
|
163
|
|
|
$CdtDbtInd = new SimpleXMLElement('<content>DBIT</content>'); |
164
|
|
|
(new Camt053\Decoder\EntryTransactionDetail(new Date()))->addAmount($detail->reveal(), $this->getXmlDetail(), $CdtDbtInd); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
private function getXmlDetail(): SimpleXMLElement |
168
|
|
|
{ |
169
|
|
|
$xmlContent = <<<XML |
170
|
|
|
<content> |
171
|
|
|
<Refs> |
172
|
|
|
<EndToEndId>some end to end id</EndToEndId> |
173
|
|
|
<MndtId>some mandate id</MndtId> |
174
|
|
|
</Refs> |
175
|
|
|
<AddtlTxInf>additional transaction information</AddtlTxInf> |
176
|
|
|
<RtrInf> |
177
|
|
|
<Rsn> |
178
|
|
|
<Cd>lorem</Cd> |
179
|
|
|
</Rsn> |
180
|
|
|
<AddtlInf>ipsum</AddtlInf> |
181
|
|
|
</RtrInf> |
182
|
|
|
<RmtInf> |
183
|
|
|
<Strd> |
184
|
|
|
<CdtrRefInf> |
185
|
|
|
<Ref>Some reference</Ref> |
186
|
|
|
</CdtrRefInf> |
187
|
|
|
<Cd>lorem</Cd> |
188
|
|
|
</Strd> |
189
|
|
|
</RmtInf> |
190
|
|
|
<RltdDts> |
191
|
|
|
<AccptncDtTm>2017-02-27T15:23:45.446</AccptncDtTm> |
192
|
|
|
</RltdDts> |
193
|
|
|
<Chrgs> |
194
|
|
|
<TtlChrgsAndTaxAmt Ccy="CHF">1.79</TtlChrgsAndTaxAmt> |
195
|
|
|
<Rcrd> |
196
|
|
|
<Amt Ccy="CHF">1.75</Amt> |
197
|
|
|
<CdtDbtInd>DBIT</CdtDbtInd> |
198
|
|
|
<ChrgInclInd>false</ChrgInclInd> |
199
|
|
|
<Tp> |
200
|
|
|
<Prtry> |
201
|
|
|
<Id>2</Id> |
202
|
|
|
</Prtry> |
203
|
|
|
</Tp> |
204
|
|
|
</Rcrd> |
205
|
|
|
<Rcrd> |
206
|
|
|
<Amt Ccy="CHF">0.04</Amt> |
207
|
|
|
<CdtDbtInd>DBIT</CdtDbtInd> |
208
|
|
|
<ChrgInclInd>false</ChrgInclInd> |
209
|
|
|
<Tp> |
210
|
|
|
<Prtry> |
211
|
|
|
<Id>4</Id> |
212
|
|
|
</Prtry> |
213
|
|
|
</Tp> |
214
|
|
|
</Rcrd> |
215
|
|
|
</Chrgs> |
216
|
|
|
<RltdPties> |
217
|
|
|
<Cdtr> |
218
|
|
|
<Nm>Lorem</Nm> |
219
|
|
|
<PstlAdr> |
220
|
|
|
<Ctry>NL</Ctry> |
221
|
|
|
<AdrLine>NL</AdrLine> |
222
|
|
|
</PstlAdr> |
223
|
|
|
</Cdtr> |
224
|
|
|
<CdtrAcct> |
225
|
|
|
<Id> |
226
|
|
|
<IBAN>NL39ULSS6234823955</IBAN> |
227
|
|
|
</Id> |
228
|
|
|
</CdtrAcct> |
229
|
|
|
</RltdPties> |
230
|
|
|
<AmtDtls> |
231
|
|
|
<TxAmt> |
232
|
|
|
<Amt Ccy="CHF">3.1</Amt> |
233
|
|
|
</TxAmt> |
234
|
|
|
</AmtDtls> |
235
|
|
|
<Amt Ccy="CHF">3.1</Amt> |
236
|
|
|
</content> |
237
|
|
|
XML; |
238
|
|
|
|
239
|
|
|
return new SimpleXMLElement($xmlContent); |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|