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