Failed Conditions
Push — master ( 65cf51...40aca8 )
by Adrien
03:16
created

EndToEndTest::getV2Message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Genkgo\TestCamt\Unit\Camt054;
4
5
use Genkgo\TestCamt\AbstractTestCase;
6
use Genkgo\Camt\Camt054\MessageFormat;
7
use Genkgo\Camt\Camt054\DTO as Camt054DTO;
8
use Genkgo\Camt\DTO;
9
use DateTimeImmutable;
10
11
class EndToEndTest extends AbstractTestCase
12
{
13
    protected function getV2Message()
14
    {
15
        $dom = new \DOMDocument('1.0', 'UTF-8');
16
        $dom->load(__DIR__.'/Stubs/camt054.v2.xml');
17
18
        return (new MessageFormat\V02)->getDecoder()->decode($dom);
19
    }
20
21
    protected function getV4Message()
22
    {
23
        $dom = new \DOMDocument('1.0', 'UTF-8');
24
        $dom->load(__DIR__.'/Stubs/camt054.v4.xml');
25
26
        return (new MessageFormat\V04)->getDecoder()->decode($dom);
27
    }
28
29
    public function testGroupHeader()
30
    {
31
        $messages = [
32
            $this->getV2Message(),
33
            $this->getV4Message(),
34
        ];
35
36
        foreach ($messages as $message) {
37
            $groupHeader = $message->getGroupHeader();
38
39
            $this->assertInstanceOf(DTO\GroupHeader::class, $groupHeader);
40
            $this->assertEquals('AAAASESS-FP-ACCR001', $groupHeader->getMessageId());
41
            $this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $groupHeader->getCreatedOn());
42
            $this->assertEquals('Group header additional information', $groupHeader->getAdditionalInformation());
43
            $this->assertInstanceOf(DTO\Pagination::class, $groupHeader->getPagination());
44
            $this->assertEquals('1', $groupHeader->getPagination()->getPageNumber());
45
            $this->assertEquals(true, $groupHeader->getPagination()->isLastPage());
46
            $msgRecipient = $groupHeader->getMessageRecipient();
47
            $this->assertInstanceOf(DTO\Recipient::class, $msgRecipient);
48
            $this->assertEquals('COMPANY BVBA', $msgRecipient->getName());
49
            $this->assertEquals('NL', $msgRecipient->getCountryOfResidence());
50
            $this->assertInstanceOf(DTO\Address::class, $msgRecipient->getAddress());
51
            $this->assertEquals('12 Oxford Street', $msgRecipient->getAddress()->getStreetName());
52
            $this->assertEquals('UK', $msgRecipient->getAddress()->getCountry());
53
            $this->assertInstanceOf(DTO\Identification::class, $msgRecipient->getIdentification());
54
            $this->assertEquals('DABAIE2D', $msgRecipient->getIdentification()->getBic());
0 ignored issues
show
Bug introduced by
The method getBic() does not exist on Genkgo\Camt\DTO\Identification. Since it exists in all sub-types, consider adding an abstract or default implementation to Genkgo\Camt\DTO\Identification. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
            $this->assertEquals('DABAIE2D', $msgRecipient->getIdentification()->/** @scrutinizer ignore-call */ getBic());
Loading history...
55
            $this->assertEquals('Some other Id', $msgRecipient->getIdentification()->getOtherId());
0 ignored issues
show
Bug introduced by
The method getOtherId() does not exist on Genkgo\Camt\DTO\Identification. Since it exists in all sub-types, consider adding an abstract or default implementation to Genkgo\Camt\DTO\Identification. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
            $this->assertEquals('Some other Id', $msgRecipient->getIdentification()->/** @scrutinizer ignore-call */ getOtherId());
Loading history...
56
            $this->assertEquals('Some other Issuer', $msgRecipient->getIdentification()->getOtherIssuer());
0 ignored issues
show
Bug introduced by
The method getOtherIssuer() does not exist on Genkgo\Camt\DTO\Identification. Since it exists in all sub-types, consider adding an abstract or default implementation to Genkgo\Camt\DTO\Identification. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
            $this->assertEquals('Some other Issuer', $msgRecipient->getIdentification()->/** @scrutinizer ignore-call */ getOtherIssuer());
Loading history...
57
        }
58
59
        $groupHeaderV4 = $messages[1]->getGroupHeader();
60
        $this->assertInstanceOf(Camt054DTO\V04\GroupHeader::class, $groupHeaderV4);
61
        $this->assertInstanceOf(Camt054DTO\V04\OriginalBusinessQuery::class, $groupHeaderV4->getOriginalBusinessQuery());
0 ignored issues
show
introduced by
The method getOriginalBusinessQuery() does not exist on Genkgo\Camt\DTO\GroupHeader. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
        $this->assertInstanceOf(Camt054DTO\V04\OriginalBusinessQuery::class, $groupHeaderV4->/** @scrutinizer ignore-call */ getOriginalBusinessQuery());
Loading history...
62
        $this->assertEquals('SomeMessageId', $groupHeaderV4->getOriginalBusinessQuery()->getMessageId());
63
        $this->assertEquals(
64
            'SomeMessageNameId',
65
            $groupHeaderV4->getOriginalBusinessQuery()->getMessageNameId()
66
        );
67
        $this->assertEquals(
68
            new DateTimeImmutable('2010-10-18T12:30:00+01:00'),
69
            $groupHeaderV4->getOriginalBusinessQuery()->getCreatedOn()
70
        );
71
    }
72
73
    public function testNotifications()
74
    {
75
        $messages = [
76
            $this->getV2Message(),
77
            $this->getV4Message(),
78
        ];
79
80
        foreach ($messages as $message) {
81
            $notifications = $message->getRecords();
82
83
            $this->assertCount(1, $notifications);
84
            foreach ($notifications as $notification) {
85
                $this->assertInstanceOf(Camt054DTO\Notification::class, $notification);
86
                $this->assertEquals('AAAASESS-FP-ACCR001', $notification->getId());
87
                $this->assertEquals('CH2801234000123456789', $notification->getAccount()->getIdentification());
88
                $this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $notification->getCreatedOn());
89
                $this->assertEquals('12312', $notification->getElectronicSequenceNumber());
90
                $this->assertEquals('12312', $notification->getLegalSequenceNumber());
91
                $this->assertEquals('CODU', $notification->getCopyDuplicateIndicator());
92
                $this->assertEquals(new DateTimeImmutable('2007-10-18T08:00:00+01:00'), $notification->getFromDate());
93
                $this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $notification->getToDate());
94
                $this->assertEquals('Additional Information', $notification->getAdditionalInformation());
95
            }
96
        }
97
98
        $notificationV4 = $messages[1]->getRecords()[0];
99
        $this->assertInstanceOf(DTO\Pagination::class, $notificationV4->getPagination());
100
        $this->assertEquals('2', $notificationV4->getPagination()->getPageNumber());
101
        $this->assertEquals(true, $notificationV4->getPagination()->isLastPage());
102
    }
103
104
    public function testEntries()
105
    {
106
        $messages = [
107
            $this->getV2Message(),
108
            $this->getV4Message(),
109
        ];
110
111
        foreach ($messages as $message) {
112
            $notifications = $message->getRecords();
113
114
            $this->assertCount(1, $notifications);
115
            foreach ($notifications as $notification) {
116
                $entries = $notification->getEntries();
117
                $this->assertCount(1, $entries);
118
119
                foreach ($entries as $entry) {
120
                    $this->assertEquals(-20000000, $entry->getAmount()->getAmount());
121
                    $this->assertEquals('SEK', $entry->getAmount()->getCurrency()->getCode());
122
                    $this->assertEquals('2007-10-18', $entry->getBookingDate()->format('Y-m-d'));
123
                    $this->assertEquals('2007-10-18', $entry->getValueDate()->format('Y-m-d'));
124
                    $this->assertEquals('PMNT', $entry->getBankTransactionCode()->getDomain()->getCode());
125
                    $this->assertEquals('ICDT', $entry->getBankTransactionCode()->getDomain()->getFamily()->getCode());
126
                    $this->assertEquals('DMCT', $entry->getBankTransactionCode()->getDomain()->getFamily()->getSubFamilyCode());
127
                }
128
            }
129
        }
130
    }
131
132
    public function testTransactionDetails()
133
    {
134
        $messages = [
135
            $this->getV2Message(),
136
            $this->getV4Message(),
137
        ];
138
139
        foreach ($messages as $message) {
140
            $notifications = $message->getRecords();
141
142
            $this->assertCount(1, $notifications);
143
            foreach ($notifications as $notification) {
144
                $entries = $notification->getEntries();
145
146
                $this->assertCount(1, $entries);
147
                foreach ($entries as $entry) {
148
                    $transactionDetails = $entry->getTransactionDetails();
149
150
                    $this->assertCount(3, $transactionDetails);
151
                    foreach ($transactionDetails as $index=>$transactionDetail) {
152
                        switch ($index) {
153
                            case 0:
154
                                // Legacy : The first message comes from unstructured block
155
                                $this->assertEquals(
156
                                    'Unstructured Remittance Information V1',
157
                                    $transactionDetail
0 ignored issues
show
Deprecated Code introduced by
The function Genkgo\Camt\DTO\Remittan...formation::getMessage() has been deprecated: Use getStructuredBlocks method instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

157
                                    /** @scrutinizer ignore-deprecated */ $transactionDetail

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
158
                                            ->getRemittanceInformation()
159
                                            ->getMessage()
160
                                );
161
162
                                // Only one structured data block
163
                                $this->assertEquals(
164
                                    'Unstructured Remittance Information V1',
165
                                    $transactionDetail
166
                                            ->getRemittanceInformation()
167
                                            ->getUnstructuredBlock()
168
                                            ->getMessage()
169
                                );
170
171
                                // Check structured and unstructured blocks
172
                                $this->assertEquals(
173
                                    'ISR ref number V1',
174
                                    $transactionDetail
175
                                            ->getRemittanceInformation()
176
                                            ->getStructuredBlock()
177
                                            ->getCreditorReferenceInformation()
178
                                            ->getRef()
179
                                );
180
181
                                $this->assertEquals(
182
                                    'ISR Reference',
183
                                    $transactionDetail
184
                                            ->getRemittanceInformation()
185
                                            ->getStructuredBlock()
186
                                            ->getCreditorReferenceInformation()
187
                                            ->getProprietary()
188
                                );
189
190
                                $this->assertEquals(
191
                                    null,
192
                                    $transactionDetail
193
                                            ->getRemittanceInformation()
194
                                            ->getStructuredBlock()
195
                                            ->getCreditorReferenceInformation()
196
                                            ->getCode()
197
                                );
198
199
                                $this->assertEquals(
200
                                    'Additional Remittance Information V1',
201
                                    $transactionDetail
202
                                            ->getRemittanceInformation()
203
                                            ->getStructuredBlock()
204
                                            ->getAdditionalRemittanceInformation()
205
                                );
206
                                break;
207
                            case 1:
208
209
                                // Legacy : ref number from the structured information
210
                                // because the unstructured block is not present
211
                                $this->assertEquals(
212
                                    'ISR ref number V2',
213
                                    $transactionDetail
0 ignored issues
show
Deprecated Code introduced by
The function Genkgo\Camt\DTO\Remittan...formation::getMessage() has been deprecated: Use getStructuredBlocks method instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

213
                                    /** @scrutinizer ignore-deprecated */ $transactionDetail

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
214
                                            ->getRemittanceInformation()
215
                                            ->getMessage()
216
                                );
217
218
                                // No unstructured block
219
                                $this->assertEquals(
220
                                    0,
221
                                    count(
222
                                        $transactionDetail
223
                                                ->getRemittanceInformation()
224
                                                ->getUnstructuredBlocks()
225
                                        )
226
                                );
227
228
                                // Check structured and unstructured blocks
229
                                $this->assertEquals(
230
                                    'ISR ref number V2',
231
                                    $transactionDetail
232
                                            ->getRemittanceInformation()
233
                                            ->getStructuredBlock()
234
                                            ->getCreditorReferenceInformation()
235
                                            ->getRef()
236
                                );
237
238
                                $this->assertEquals(
239
                                    'ISR Reference',
240
                                    $transactionDetail
241
                                            ->getRemittanceInformation()
242
                                            ->getStructuredBlock()
243
                                            ->getCreditorReferenceInformation()
244
                                            ->getProprietary()
245
                                );
246
247
                                $this->assertEquals(
248
                                    null,
249
                                    $transactionDetail
250
                                            ->getRemittanceInformation()
251
                                            ->getStructuredBlock()
252
                                            ->getCreditorReferenceInformation()
253
                                            ->getCode()
254
                                );
255
256
                                $this->assertEquals(
257
                                    'Additional Remittance Information V2',
258
                                    $transactionDetail
259
                                            ->getRemittanceInformation()
260
                                            ->getStructuredBlock()
261
                                            ->getAdditionalRemittanceInformation()
262
                                );
263
264
                                break;
265
                            case 2:
266
                                // Legacy : ref number from the first unstructured block
267
                                $this->assertEquals(
268
                                    'Unstructured Remittance Information V3 block 1',
269
                                    $transactionDetail
0 ignored issues
show
Deprecated Code introduced by
The function Genkgo\Camt\DTO\Remittan...formation::getMessage() has been deprecated: Use getStructuredBlocks method instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

269
                                    /** @scrutinizer ignore-deprecated */ $transactionDetail

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
270
                                            ->getRemittanceInformation()
271
                                            ->getMessage()
272
                                );
273
274
                                // First unstructured block
275
                                $this->assertEquals(
276
                                    'Unstructured Remittance Information V3 block 1',
277
                                    $transactionDetail
278
                                            ->getRemittanceInformation()
279
                                            ->getUnstructuredBlocks()[0]
280
                                            ->getMessage()
281
                                );
282
283
                                // Second unstructured block
284
                                $this->assertEquals(
285
                                    'Unstructured Remittance Information V3 block 2',
286
                                    $transactionDetail
287
                                            ->getRemittanceInformation()
288
                                            ->getUnstructuredBlocks()[1]
289
                                            ->getMessage()
290
                                );
291
292
                                // Ref number from the first structured block
293
                                $this->assertEquals(
294
                                    'Ref number V3 block 1',
295
                                    $transactionDetail
296
                                            ->getRemittanceInformation()
297
                                            ->getStructuredBlocks()[0]
298
                                            ->getCreditorReferenceInformation()
299
                                            ->getRef()
300
                                );
301
302
                                // Ref number from the second structured block
303
                                $this->assertEquals(
304
                                    'Ref number V3 block 2',
305
                                    $transactionDetail
306
                                            ->getRemittanceInformation()
307
                                            ->getStructuredBlocks()[1]
308
                                            ->getCreditorReferenceInformation()
309
                                            ->getRef()
310
                                );
311
312
                                // Code from the first structured block
313
                                $this->assertEquals(
314
                                    'SCOR',
315
                                    $transactionDetail
316
                                            ->getRemittanceInformation()
317
                                            ->getStructuredBlocks()[0]
318
                                            ->getCreditorReferenceInformation()
319
                                            ->getCode()
320
                                );
321
322
                                // Code from the second structured block
323
                                $this->assertEquals(
324
                                    'SCOR',
325
                                    $transactionDetail
326
                                            ->getRemittanceInformation()
327
                                            ->getStructuredBlocks()[1]
328
                                            ->getCreditorReferenceInformation()
329
                                            ->getCode()
330
                                );
331
332
                                // Additional remittance information from the first structured block
333
                                $this->assertEquals(
334
                                    'Additional Remittance Information V3 block 1',
335
                                    $transactionDetail
336
                                            ->getRemittanceInformation()
337
                                            ->getStructuredBlocks()[0]
338
                                            ->getAdditionalRemittanceInformation()
339
                                );
340
341
                                // Additional remittance information from the second structured block
342
                                $this->assertEquals(
343
                                    'Additional Remittance Information V3 block 2',
344
                                    $transactionDetail
345
                                            ->getRemittanceInformation()
346
                                            ->getStructuredBlocks()[1]
347
                                            ->getAdditionalRemittanceInformation()
348
                                );
349
                                break;
350
                            default:
351
                                break;
352
                        }
353
                    }
354
                }
355
            }
356
        }
357
    }
358
}
359