Completed
Pull Request — master (#88)
by
unknown
08:32
created

EndToEndTest::getV1Message()   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
declare(strict_types=1);
4
5
namespace Genkgo\TestCamt\Unit\Camt052;
6
7
use \DateTimeImmutable;
8
use DOMDocument;
9
use Genkgo\Camt\DTO\Entry;
10
use Genkgo\Camt\DTO\Message;
11
use Genkgo\Camt\DTO\OrganisationIdentification;
12
use Genkgo\TestCamt\AbstractTestCase;
13
use Genkgo\Camt\Camt052\MessageFormat;
14
use Genkgo\Camt\Camt052\DTO as Camt052DTO;
15
use Genkgo\Camt\DTO;
16
17
class EndToEndTest extends AbstractTestCase
18
{
19
    protected function getV1Message(): Message
20
    {
21
        $dom = new DOMDocument('1.0', 'UTF-8');
22
        $dom->load(__DIR__.'/Stubs/camt052.v1.xml');
23
24
        return (new MessageFormat\V01)->getDecoder()->decode($dom);
25
    }
26
27
    protected function getV2Message(): Message
28
    {
29
        $dom = new DOMDocument('1.0', 'UTF-8');
30
        $dom->load(__DIR__.'/Stubs/camt052.v2.xml');
31
32
        return (new MessageFormat\V02)->getDecoder()->decode($dom);
33
    }
34
35
    protected function getV2OtherAccountMessage(): Message
36
    {
37
        $dom = new DOMDocument('1.0', 'UTF-8');
38
        $dom->load(__DIR__.'/Stubs/camt052.v2.other-account.xml');
39
40
        return (new MessageFormat\V02)->getDecoder()->decode($dom);
41
    }
42
43
    protected function getV4Message(): Message
44
    {
45
        $dom = new DOMDocument('1.0', 'UTF-8');
46
        $dom->load(__DIR__.'/Stubs/camt052.v4.xml');
47
48
        return (new MessageFormat\V04)->getDecoder()->decode($dom);
49
    }
50
51
    protected function getV6Message(): Message
52
    {
53
        $dom = new DOMDocument('1.0', 'UTF-8');
54
        $dom->load(__DIR__.'/Stubs/camt052.v6.xml');
55
56
        return (new MessageFormat\V06())->getDecoder()->decode($dom);
57
    }
58
59
    public function testGroupHeader(): void
60
    {
61
        $messages = [
62
            $this->getV1Message(),
63
            $this->getV2Message(),
64
            $this->getV4Message(),
65
            $this->getV6Message(),
66
        ];
67
68
        /** @var Message $message */
69
        foreach ($messages as $message) {
70
            $groupHeader = $message->getGroupHeader();
71
72
            $this->assertInstanceOf(DTO\GroupHeader::class, $groupHeader);
73
            $this->assertEquals('AAAASESS-FP-ACCR001', $groupHeader->getMessageId());
74
            $this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $groupHeader->getCreatedOn());
75
            $this->assertEquals('Group header additional information', $groupHeader->getAdditionalInformation());
76
            $msgRecipient = $groupHeader->getMessageRecipient();
77
            $this->assertInstanceOf(DTO\Recipient::class, $msgRecipient);
78
            $this->assertEquals('COMPANY BVBA', $msgRecipient->getName());
79
            $this->assertEquals('NL', $msgRecipient->getCountryOfResidence());
80
            $this->assertInstanceOf(DTO\Address::class, $msgRecipient->getAddress());
81
            $this->assertEquals('12 Oxford Street', $msgRecipient->getAddress()->getStreetName());
82
            $this->assertEquals('UK', $msgRecipient->getAddress()->getCountry());
83
84
            /** @var OrganisationIdentification $identification */
85
            $identification = $msgRecipient->getIdentification();
86
            $this->assertInstanceOf(DTO\Identification::class, $identification);
87
            $this->assertEquals('DABAIE2D', $identification->getBic());
88
            $this->assertEquals('Some other Id', $identification->getOtherId());
89
            $this->assertEquals('Some other Issuer', $identification->getOtherIssuer());
90
        }
91
    }
92
93
    public function testReports(): void
94
    {
95
        $messages = [
96
            $this->getV1Message(),
97
            $this->getV2Message(),
98
            $this->getV4Message(),
99
        ];
100
101
        foreach ($messages as $message) {
102
            $reports = $message->getRecords();
103
104
            $this->assertCount(1, $reports);
105
            foreach ($reports as $report) {
106
                $this->assertInstanceOf(Camt052DTO\Report::class, $report);
107
                $this->assertEquals('AAAASESS-FP-ACCR001', $report->getId());
108
                $this->assertEquals('CH2801234000123456789', $report->getAccount()->getIdentification());
109
                $this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $report->getCreatedOn());
110
                $this->assertEquals('12312', $report->getElectronicSequenceNumber());
111
                $this->assertEquals('12312', $report->getLegalSequenceNumber());
112
                $this->assertEquals('CODU', $report->getCopyDuplicateIndicator());
113
                $this->assertEquals(new DateTimeImmutable('2007-10-18T08:00:00+01:00'), $report->getFromDate());
114
                $this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $report->getToDate());
115
                $this->assertEquals('Additional Information', $report->getAdditionalInformation());
116
            }
117
        }
118
    }
119
120
    public function testEntries(): void
121
    {
122
        $messages = [
123
            $this->getV1Message(),
124
            $this->getV2Message(),
125
            $this->getV4Message(),
126
        ];
127
128
        foreach ($messages as $message) {
129
            $reports = $message->getRecords();
130
131
            $this->assertCount(1, $reports);
132
            foreach ($reports as $report) {
133
                $entries = $report->getEntries();
134
                $this->assertCount(1, $entries);
135
136
                foreach ($entries as $entry) {
137
                    $this->assertEquals(-20000000, $entry->getAmount()->getAmount());
138
                    $this->assertEquals('SEK', $entry->getAmount()->getCurrency()->getCode());
139
                    $this->assertEquals('2007-10-18', $entry->getBookingDate()->format('Y-m-d'));
140
                    $this->assertEquals('2007-10-18', $entry->getValueDate()->format('Y-m-d'));
141
                    $this->assertEquals('Credit', $entry->getAdditionalInfo());
142
                }
143
            }
144
        }
145
146
        $reportV4 = $messages[2]->getRecords()[0];
147
        $this->assertInstanceOf(DTO\Pagination::class, $reportV4->getPagination());
148
        $this->assertEquals('2', $reportV4->getPagination()->getPageNumber());
149
        $this->assertEquals(true, $reportV4->getPagination()->isLastPage());
150
    }
151
152
    public function testRelatedAgents(): void
153
    {
154
        $messages = [
155
            $this->getV2Message(),
156
        ];
157
158
        foreach ($messages as $message) {
159
            $reports = $message->getRecords();
160
161
            $this->assertCount(1, $reports);
162
            foreach ($reports as $report) {
163
                $entries = $report->getEntries();
164
                $this->assertCount(1, $entries);
165
166
                /** @var Entry $entry */
167
                foreach ($entries as $entry) {
168
                    $this->assertCount(1, $entry->getTransactionDetails());
169
                    foreach ($entry->getTransactionDetails() as $detail) {
170
                        $this->assertCount(2, $detail->getRelatedAgents());
171
172
                        foreach ($detail->getRelatedAgents() as $relatedAgent) {
173
                            $this->assertEquals('BANKCHZHXXX', $relatedAgent->getRelatedAgentType()->getBIC());
174
                            $this->assertEquals('Some bank', $relatedAgent->getRelatedAgentType()->getName());
175
                        }
176
                    }
177
                }
178
            }
179
        }
180
    }
181
182
    public function testOtherAccount(): void
183
    {
184
        $messages = [
185
            $this->getV2OtherAccountMessage(),
186
        ];
187
188
        foreach ($messages as $message) {
189
            $reports = $message->getRecords();
190
191
            $this->assertCount(1, $reports);
192
            foreach ($reports as $report) {
193
                $entries = $report->getEntries();
194
                $this->assertCount(1, $entries);
195
196
                /** @var Entry $entry */
197
                foreach ($entries as $entry) {
198
                    $parties = $entry->getTransactionDetail()->getRelatedParties();
199
200
                    foreach ($parties as $party) {
201
                        $this->assertInstanceOf(DTO\OtherAccount::class, $party->getAccount());
202
                    }
203
                }
204
            }
205
        }
206
    }
207
208
    public function testRelatedParties(): void
209
    {
210
        $messages = [
211
            $this->getV2Message(),
212
        ];
213
214
        foreach ($messages as $message) {
215
            $reports = $message->getRecords();
216
217
            $this->assertCount(1, $reports);
218
            foreach ($reports as $report) {
219
                $entries = $report->getEntries();
220
                $this->assertCount(1, $entries);
221
222
                foreach ($entries as $entry) {
223
                    $details = $entry->getTransactionDetails();
224
                    $this->assertCount(1, $details);
225
226
                    foreach ($details as $detail) {
227
                        $parties = $detail->getRelatedParties();
228
                        $this->assertCount(2, $parties);
229
230
                        foreach ($parties as $party) {
231
                            if ($party->getRelatedPartyType() instanceof DTO\Creditor) {
232
                                $this->assertEquals('Company Name', $party->getRelatedPartyType()->getName());
233
                                $this->assertEquals('NL', $party->getRelatedPartyType()->getAddress()->getCountry());
234
                                $this->assertEquals([], $party->getRelatedPartyType()->getAddress()->getAddressLines());
235
                                $this->assertEquals('NL56AGDH9619008421', (string)$party->getAccount()->getIdentification());
236
                            } elseif ($party->getRelatedPartyType() instanceof DTO\Debtor) {
237
                                $this->assertEquals('NAME NAME', $party->getRelatedPartyType()->getName());
238
                                $this->assertEquals('NL', $party->getRelatedPartyType()->getAddress()->getCountry());
239
                                $this->assertEquals(['ADDR ADDR 10', '2000 ANTWERPEN'], $party->getRelatedPartyType()->getAddress()->getAddressLines());
240
                                $this->assertEquals('NL56AGDH9619008421', (string)$party->getAccount()->getIdentification());
241
                            }
242
                        }
243
                    }
244
                }
245
            }
246
        }
247
    }
248
249
    public function testProprietaryBankTransactionCode(): void
250
    {
251
        $messages = [
252
            $this->getV2Message(),
253
        ];
254
255
        foreach ($messages as $message) {
256
            $reports = $message->getRecords();
257
258
            $this->assertCount(1, $reports);
259
            foreach ($reports as $report) {
260
                $entries = $report->getEntries();
261
                $this->assertCount(1, $entries);
262
263
                /** @var Entry $entry */
264
                foreach ($entries as $entry) {
265
                    $this->assertInstanceOf(DTO\BankTransactionCode::class, $entry->getBankTransactionCode());
266
                    $this->assertInstanceOf(DTO\ProprietaryBankTransactionCode::class, $entry->getBankTransactionCode()->getProprietary());
267
268
                    $this->assertEquals('XXXX+000+0000+000', $entry->getBankTransactionCode()->getProprietary()->getCode());
269
                    $this->assertEquals('ZKA', $entry->getBankTransactionCode()->getProprietary()->getIssuer());
270
271
                    $this->assertCount(1, $entry->getTransactionDetails());
272
273
                    foreach ($entry->getTransactionDetails() as $details) {
274
                        $this->assertInstanceOf(DTO\BankTransactionCode::class, $details->getBankTransactionCode());
275
                        $this->assertInstanceOf(DTO\ProprietaryBankTransactionCode::class, $details->getBankTransactionCode()->getProprietary());
276
277
                        $this->assertEquals('XXXX+000+0000+000', $details->getBankTransactionCode()->getProprietary()->getCode());
278
                        $this->assertEquals('ZKA', $details->getBankTransactionCode()->getProprietary()->getIssuer());
279
                    }
280
                }
281
            }
282
        }
283
    }
284
}
285