|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Genkgo\TestCamt\Unit\Camt053; |
|
4
|
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
|
6
|
|
|
use Genkgo\Camt\DTO\Message; |
|
7
|
|
|
use Genkgo\TestCamt\AbstractTestCase; |
|
8
|
|
|
use Genkgo\Camt\Camt053\MessageFormat; |
|
9
|
|
|
use Genkgo\Camt\Camt053\DTO as Camt053DTO; |
|
10
|
|
|
use Genkgo\Camt\DTO; |
|
11
|
|
|
use Genkgo\Camt\Exception\InvalidMessageException; |
|
12
|
|
|
|
|
13
|
|
|
class EndToEndTest extends AbstractTestCase |
|
14
|
|
|
{ |
|
15
|
|
|
protected function getV2Message() |
|
16
|
|
|
{ |
|
17
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
|
18
|
|
|
$dom->load(__DIR__.'/Stubs/camt053.v2.minimal.xml'); |
|
19
|
|
|
|
|
20
|
|
|
return (new MessageFormat\V02)->getDecoder()->decode($dom); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function getV2UltimateMessage() |
|
24
|
|
|
{ |
|
25
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
|
26
|
|
|
$dom->load(__DIR__.'/Stubs/camt053.v2.minimal.ultimate.xml'); |
|
27
|
|
|
|
|
28
|
|
|
return (new MessageFormat\V02)->getDecoder()->decode($dom); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function getV3Message() |
|
32
|
|
|
{ |
|
33
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
|
34
|
|
|
$dom->load(__DIR__.'/Stubs/camt053.v3.xml'); |
|
35
|
|
|
|
|
36
|
|
|
return (new MessageFormat\V03)->getDecoder()->decode($dom); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function getV4Message() |
|
40
|
|
|
{ |
|
41
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
|
42
|
|
|
$dom->load(__DIR__.'/Stubs/camt053.v4.xml'); |
|
43
|
|
|
|
|
44
|
|
|
return (new MessageFormat\V04)->getDecoder()->decode($dom); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testWrongDocument() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->expectException(InvalidMessageException::class); |
|
50
|
|
|
|
|
51
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
|
52
|
|
|
$dom->load(__DIR__.'/Stubs/camt053.v2.wrong.xml'); |
|
53
|
|
|
|
|
54
|
|
|
return (new MessageFormat\V02)->getDecoder()->decode($dom); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testFiveDecimalsStatement() |
|
58
|
|
|
{ |
|
59
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
|
60
|
|
|
$dom->load(__DIR__.'/Stubs/camt053.v2.five.decimals.xml'); |
|
61
|
|
|
$this->assertInstanceOf(Message::class, (new MessageFormat\V02)->getDecoder()->decode($dom)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testV3Document() |
|
65
|
|
|
{ |
|
66
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
|
67
|
|
|
$dom->load(__DIR__.'/Stubs/camt053.v3.xml'); |
|
68
|
|
|
$this->assertInstanceOf(Message::class, (new MessageFormat\V03)->getDecoder()->decode($dom)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testV4Document() |
|
72
|
|
|
{ |
|
73
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
|
74
|
|
|
$dom->load(__DIR__.'/Stubs/camt053.v4.xml'); |
|
75
|
|
|
$this->assertInstanceOf(Message::class, (new MessageFormat\V04)->getDecoder()->decode($dom)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testGroupHeader() |
|
79
|
|
|
{ |
|
80
|
|
|
$messages = [ |
|
81
|
|
|
$this->getV2Message(), |
|
82
|
|
|
$this->getV3Message(), |
|
83
|
|
|
$this->getV4Message(), |
|
84
|
|
|
$this->getV2UltimateMessage(), |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
foreach ($messages as $message) { |
|
88
|
|
|
$groupHeader = $message->getGroupHeader(); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertInstanceOf(DTO\GroupHeader::class, $groupHeader); |
|
91
|
|
|
$this->assertEquals('CAMT053RIB000000000001', $groupHeader->getMessageId()); |
|
92
|
|
|
$this->assertEquals(new DateTimeImmutable('2015-03-10T18:43:50+00:00'), $groupHeader->getCreatedOn()); |
|
93
|
|
|
$this->assertEquals('Group header additional information', $groupHeader->getAdditionalInformation()); |
|
94
|
|
|
$msgRecipient = $groupHeader->getMessageRecipient(); |
|
95
|
|
|
$this->assertInstanceOf(DTO\Recipient::class, $msgRecipient); |
|
96
|
|
|
$this->assertEquals('COMPANY BVBA', $msgRecipient->getName()); |
|
97
|
|
|
$this->assertEquals('NL', $msgRecipient->getCountryOfResidence()); |
|
98
|
|
|
$this->assertInstanceOf(DTO\Address::class, $msgRecipient->getAddress()); |
|
99
|
|
|
$this->assertEquals('12 Oxford Street', $msgRecipient->getAddress()->getStreetName()); |
|
100
|
|
|
$this->assertEquals('UK', $msgRecipient->getAddress()->getCountry()); |
|
101
|
|
|
$this->assertInstanceOf(DTO\Identification::class, $msgRecipient->getIdentification()); |
|
102
|
|
|
$this->assertEquals('DABAIE2D', $msgRecipient->getIdentification()->getBic()); |
|
|
|
|
|
|
103
|
|
|
$this->assertEquals('Some other Id', $msgRecipient->getIdentification()->getOtherId()); |
|
|
|
|
|
|
104
|
|
|
$this->assertEquals('Some other Issuer', $msgRecipient->getIdentification()->getOtherIssuer()); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function testStatements() |
|
109
|
|
|
{ |
|
110
|
|
|
$messages = [ |
|
111
|
|
|
$this->getV2Message(), |
|
112
|
|
|
$this->getV3Message(), |
|
113
|
|
|
$this->getV4Message(), |
|
114
|
|
|
$this->getV2UltimateMessage() |
|
115
|
|
|
]; |
|
116
|
|
|
|
|
117
|
|
|
foreach ($messages as $message) { |
|
118
|
|
|
$statements = $message->getRecords(); |
|
119
|
|
|
|
|
120
|
|
|
$this->assertCount(1, $statements); |
|
121
|
|
|
foreach ($statements as $statement) { |
|
122
|
|
|
$this->assertInstanceOf(Camt053DTO\Statement::class, $statement); |
|
123
|
|
|
$this->assertEquals('253EURNL26VAYB8060476890', $statement->getId()); |
|
124
|
|
|
$this->assertEquals('NL26VAYB8060476890', $statement->getAccount()->getIdentification()); |
|
125
|
|
|
$this->assertEquals(new DateTimeImmutable('2015-03-10T18:43:50+00:00'), $statement->getCreatedOn()); |
|
126
|
|
|
|
|
127
|
|
|
$this->assertEquals('12312', $statement->getElectronicSequenceNumber()); |
|
128
|
|
|
$this->assertEquals('12312', $statement->getLegalSequenceNumber()); |
|
129
|
|
|
$this->assertEquals('CODU', $statement->getCopyDuplicateIndicator()); |
|
130
|
|
|
$this->assertEquals(new DateTimeImmutable('2007-10-18T08:00:00+01:00'), $statement->getFromDate()); |
|
131
|
|
|
$this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $statement->getToDate()); |
|
132
|
|
|
$this->assertEquals('Additional Information', $statement->getAdditionalInformation()); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$statementV4 = $messages[2]->getRecords()[0]; |
|
137
|
|
|
$this->assertInstanceOf(DTO\Pagination::class, $statementV4->getPagination()); |
|
138
|
|
|
$this->assertEquals('2', $statementV4->getPagination()->getPageNumber()); |
|
139
|
|
|
$this->assertEquals(true, $statementV4->getPagination()->isLastPage()); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function testBalance() |
|
143
|
|
|
{ |
|
144
|
|
|
$messages = [ |
|
145
|
|
|
$this->getV2Message(), |
|
146
|
|
|
$this->getV3Message(), |
|
147
|
|
|
$this->getV4Message(), |
|
148
|
|
|
$this->getV2UltimateMessage(), |
|
149
|
|
|
]; |
|
150
|
|
|
|
|
151
|
|
|
foreach ($messages as $message) { |
|
152
|
|
|
$statements = $message->getRecords(); |
|
153
|
|
|
|
|
154
|
|
|
$this->assertCount(1, $statements); |
|
155
|
|
|
foreach ($statements as $statement) { |
|
156
|
|
|
$balances = $statement->getBalances(); |
|
|
|
|
|
|
157
|
|
|
$this->assertCount(2, $balances); |
|
158
|
|
|
|
|
159
|
|
|
foreach ($balances as $item => $balance) { |
|
160
|
|
|
if ($item === 0) { |
|
161
|
|
|
$this->assertEquals(1815, $balance->getAmount()->getAmount()); |
|
162
|
|
|
$this->assertEquals('EUR', $balance->getAmount()->getCurrency()->getCode()); |
|
163
|
|
|
$this->assertEquals('opening', $balance->getType()); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
if ($item === 1) { |
|
167
|
|
|
$this->assertEquals(-2700, $balance->getAmount()->getAmount()); |
|
168
|
|
|
$this->assertEquals('SEK', $balance->getAmount()->getCurrency()->getCode()); |
|
169
|
|
|
$this->assertEquals('closing', $balance->getType()); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function testEntries() |
|
177
|
|
|
{ |
|
178
|
|
|
$messages = [ |
|
179
|
|
|
$this->getV2Message(), |
|
180
|
|
|
$this->getV3Message(), |
|
181
|
|
|
$this->getV4Message(), |
|
182
|
|
|
$this->getV2UltimateMessage(), |
|
183
|
|
|
]; |
|
184
|
|
|
|
|
185
|
|
|
foreach ($messages as $message) { |
|
186
|
|
|
$statements = $message->getRecords(); |
|
187
|
|
|
|
|
188
|
|
|
$this->assertCount(1, $statements); |
|
189
|
|
|
foreach ($statements as $statement) { |
|
190
|
|
|
$entries = $statement->getEntries(); |
|
191
|
|
|
$this->assertCount(1, $entries); |
|
192
|
|
|
|
|
193
|
|
|
foreach ($entries as $entry) { |
|
194
|
|
|
$this->assertEquals(885, $entry->getAmount()->getAmount()); |
|
195
|
|
|
$this->assertEquals('EUR', $entry->getAmount()->getCurrency()->getCode()); |
|
196
|
|
|
$this->assertEquals('2014-12-31', $entry->getBookingDate()->format('Y-m-d')); |
|
197
|
|
|
$this->assertEquals('2015-01-02', $entry->getValueDate()->format('Y-m-d')); |
|
198
|
|
|
|
|
199
|
|
|
$details = $entry->getTransactionDetails(); |
|
200
|
|
|
$this->assertCount(1, $details); |
|
201
|
|
|
foreach ($details as $detail) { |
|
202
|
|
|
$parties = $detail->getRelatedParties(); |
|
203
|
|
|
$this->assertCount(2, $parties); |
|
204
|
|
|
|
|
205
|
|
|
foreach ($parties as $party) { |
|
206
|
|
|
if ($party->getRelatedPartyType() instanceof DTO\Creditor) { |
|
207
|
|
|
if ($party->getRelatedPartyType() instanceof DTO\UltimateCreditor) { |
|
208
|
|
|
$this->assertEquals('CREDITOR NAME NM', $party->getRelatedPartyType()->getName()); |
|
209
|
|
|
$this->assertEquals(["CREDITOR NAME", "CREDITOR ADD"], $party->getRelatedPartyType()->getAddress()->getAddressLines()); |
|
210
|
|
|
} else { |
|
211
|
|
|
$this->assertEquals('Company Name', $party->getRelatedPartyType()->getName()); |
|
212
|
|
|
$this->assertEquals('NL', $party->getRelatedPartyType()->getAddress()->getCountry()); |
|
213
|
|
|
$this->assertEquals([], $party->getRelatedPartyType()->getAddress()->getAddressLines()); |
|
214
|
|
|
$this->assertEquals('NL56AGDH9619008421', (string) $party->getAccount()->getIdentification()); |
|
215
|
|
|
} |
|
216
|
|
|
} elseif ($party->getRelatedPartyType() instanceof DTO\Debtor) { |
|
217
|
|
|
if ($party->getRelatedPartyType() instanceof DTO\UltimateDebtor) { |
|
218
|
|
|
$this->assertEquals('DEBTOR NAME NM', $party->getRelatedPartyType()->getName()); |
|
219
|
|
|
$this->assertEquals(["DEBTOR NAME", "DEBTOR ADD"], $party->getRelatedPartyType()->getAddress()->getAddressLines()); |
|
220
|
|
|
} else { |
|
221
|
|
|
$this->assertEquals('NAME NAME', $party->getRelatedPartyType()->getName()); |
|
222
|
|
|
$this->assertEquals('NL', $party->getRelatedPartyType()->getAddress()->getCountry()); |
|
223
|
|
|
$this->assertEquals(['ADDR ADDR 10', '2000 ANTWERPEN'], $party->getRelatedPartyType()->getAddress()->getAddressLines()); |
|
224
|
|
|
$this->assertEquals('NL56AGDH9619008421', (string) $party->getAccount()->getIdentification()); |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
$references = $detail->getReferences(); |
|
230
|
|
|
$this->assertCount(1, $references); |
|
231
|
|
|
foreach ($references as $reference) { |
|
232
|
|
|
$this->assertEquals('LegalSequenceNumber', $reference->getProprietaries()[0]->getType()); |
|
233
|
|
|
$this->assertEquals('100', $reference->getProprietaries()[0]->getReference()); |
|
234
|
|
|
$this->assertNull($reference->getMandateId()); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
$remittanceInformation = $detail->getRemittanceInformation(); |
|
238
|
|
|
$this->assertEquals('4654654654654654', $remittanceInformation->getCreditorReferenceInformation()->getRef()); |
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
public function testStructuredMessage() |
|
246
|
|
|
{ |
|
247
|
|
|
$messages = [ |
|
248
|
|
|
$this->getV2Message(), |
|
249
|
|
|
$this->getV3Message(), |
|
250
|
|
|
$this->getV4Message(), |
|
251
|
|
|
$this->getV2UltimateMessage(), |
|
252
|
|
|
]; |
|
253
|
|
|
|
|
254
|
|
|
foreach ($messages as $message) { |
|
255
|
|
|
$statements = $message->getRecords(); |
|
256
|
|
|
|
|
257
|
|
|
$this->assertCount(1, $statements); |
|
258
|
|
|
foreach ($statements as $statement) { |
|
259
|
|
|
$entries = $statement->getEntries(); |
|
260
|
|
|
$this->assertCount(1, $entries); |
|
261
|
|
|
|
|
262
|
|
|
foreach ($entries as $entry) { |
|
263
|
|
|
$details = $entry->getTransactionDetails(); |
|
264
|
|
|
$this->assertCount(1, $details); |
|
265
|
|
|
foreach ($details as $detail) { |
|
266
|
|
|
$remittanceInformation = $detail->getRemittanceInformation(); |
|
267
|
|
|
$this->assertEquals('4654654654654654', $remittanceInformation->getMessage()); |
|
|
|
|
|
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
} |
|
274
|
|
|
|