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\Camt052;
4
5
use \DateTimeImmutable;
6
use Genkgo\TestCamt\AbstractTestCase;
7
use Genkgo\Camt\Camt052\MessageFormat;
8
use Genkgo\Camt\Camt052\DTO as Camt052DTO;
9
use Genkgo\Camt\DTO;
10
11
class EndToEndTest extends AbstractTestCase
12
{
13
    protected function getV1Message()
14
    {
15
        $dom = new \DOMDocument('1.0', 'UTF-8');
16
        $dom->load(__DIR__.'/Stubs/camt052.v1.xml');
17
18
        return (new MessageFormat\V01)->getDecoder()->decode($dom);
19
    }
20
21
    protected function getV2Message()
22
    {
23
        $dom = new \DOMDocument('1.0', 'UTF-8');
24
        $dom->load(__DIR__.'/Stubs/camt052.v2.xml');
25
26
        return (new MessageFormat\V02)->getDecoder()->decode($dom);
27
    }
28
29
    protected function getV2OtherAccountMessage()
30
    {
31
        $dom = new \DOMDocument('1.0', 'UTF-8');
32
        $dom->load(__DIR__.'/Stubs/camt052.v2.other-account.xml');
33
34
        return (new MessageFormat\V02)->getDecoder()->decode($dom);
35
    }
36
37
    protected function getV4Message()
38
    {
39
        $dom = new \DOMDocument('1.0', 'UTF-8');
40
        $dom->load(__DIR__.'/Stubs/camt052.v4.xml');
41
42
        return (new MessageFormat\V04)->getDecoder()->decode($dom);
43
    }
44
45
    public function testGroupHeader()
46
    {
47
        $messages = [
48
            $this->getV1Message(),
49
            $this->getV2Message(),
50
            $this->getV4Message(),
51
        ];
52
53
        foreach ($messages as $message) {
54
            $groupHeader = $message->getGroupHeader();
55
56
            $this->assertInstanceOf(DTO\GroupHeader::class, $groupHeader);
57
            $this->assertEquals('AAAASESS-FP-ACCR001', $groupHeader->getMessageId());
58
            $this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $groupHeader->getCreatedOn());
59
            $this->assertEquals('Group header additional information', $groupHeader->getAdditionalInformation());
60
            $msgRecipient = $groupHeader->getMessageRecipient();
61
            $this->assertInstanceOf(DTO\Recipient::class, $msgRecipient);
62
            $this->assertEquals('COMPANY BVBA', $msgRecipient->getName());
63
            $this->assertEquals('NL', $msgRecipient->getCountryOfResidence());
64
            $this->assertInstanceOf(DTO\Address::class, $msgRecipient->getAddress());
65
            $this->assertEquals('12 Oxford Street', $msgRecipient->getAddress()->getStreetName());
66
            $this->assertEquals('UK', $msgRecipient->getAddress()->getCountry());
67
            $this->assertInstanceOf(DTO\Identification::class, $msgRecipient->getIdentification());
68
            $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

68
            $this->assertEquals('DABAIE2D', $msgRecipient->getIdentification()->/** @scrutinizer ignore-call */ getBic());
Loading history...
69
            $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

69
            $this->assertEquals('Some other Id', $msgRecipient->getIdentification()->/** @scrutinizer ignore-call */ getOtherId());
Loading history...
70
            $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

70
            $this->assertEquals('Some other Issuer', $msgRecipient->getIdentification()->/** @scrutinizer ignore-call */ getOtherIssuer());
Loading history...
71
        }
72
    }
73
74
    public function testReports()
75
    {
76
        $messages = [
77
            $this->getV1Message(),
78
            $this->getV2Message(),
79
            $this->getV4Message(),
80
        ];
81
82
        foreach ($messages as $message) {
83
            $reports = $message->getRecords();
84
85
            $this->assertCount(1, $reports);
86
            foreach ($reports as $report) {
87
                $this->assertInstanceOf(Camt052DTO\Report::class, $report);
88
                $this->assertEquals('AAAASESS-FP-ACCR001', $report->getId());
89
                $this->assertEquals('CH2801234000123456789', $report->getAccount()->getIdentification());
90
                $this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $report->getCreatedOn());
91
                $this->assertEquals('12312', $report->getElectronicSequenceNumber());
92
                $this->assertEquals('12312', $report->getLegalSequenceNumber());
93
                $this->assertEquals('CODU', $report->getCopyDuplicateIndicator());
94
                $this->assertEquals(new DateTimeImmutable('2007-10-18T08:00:00+01:00'), $report->getFromDate());
95
                $this->assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $report->getToDate());
96
                $this->assertEquals('Additional Information', $report->getAdditionalInformation());
97
            }
98
        }
99
    }
100
101
    public function testEntries()
102
    {
103
        $messages = [
104
            $this->getV1Message(),
105
            $this->getV2Message(),
106
            $this->getV4Message(),
107
        ];
108
109
        foreach ($messages as $message) {
110
            $reports = $message->getRecords();
111
112
            $this->assertCount(1, $reports);
113
            foreach ($reports as $report) {
114
                $entries = $report->getEntries();
115
                $this->assertCount(1, $entries);
116
117
                foreach ($entries as $entry) {
118
                    $this->assertEquals(-20000000, $entry->getAmount()->getAmount());
119
                    $this->assertEquals('SEK', $entry->getAmount()->getCurrency()->getCode());
120
                    $this->assertEquals('2007-10-18', $entry->getBookingDate()->format('Y-m-d'));
121
                    $this->assertEquals('2007-10-18', $entry->getValueDate()->format('Y-m-d'));
122
                    $this->assertEquals('Credit', $entry->getAdditionalInfo());
123
                }
124
            }
125
        }
126
127
        $reportV4 = $messages[2]->getRecords()[0];
128
        $this->assertInstanceOf(DTO\Pagination::class, $reportV4->getPagination());
129
        $this->assertEquals('2', $reportV4->getPagination()->getPageNumber());
130
        $this->assertEquals(true, $reportV4->getPagination()->isLastPage());
131
    }
132
133
    public function testRelatedAgents()
134
    {
135
        $messages = [
136
            $this->getV2Message(),
137
        ];
138
139
        foreach ($messages as $message) {
140
            $reports = $message->getRecords();
141
142
            $this->assertCount(1, $reports);
143
            foreach ($reports as $report) {
144
                $entries = $report->getEntries();
145
                $this->assertCount(1, $entries);
146
147
                /** @var \Genkgo\Camt\DTO\Entry $entry */
148
                foreach ($entries as $entry) {
149
                    $this->assertCount(1, $entry->getTransactionDetails());
150
                    foreach ($entry->getTransactionDetails() as $detail) {
151
                        $this->assertCount(2, $detail->getRelatedAgents());
152
153
                        foreach ($detail->getRelatedAgents() as $relatedAgent) {
154
                            $this->assertEquals('BANKCHZHXXX', $relatedAgent->getRelatedAgentType()->getBIC());
155
                            $this->assertEquals('Some bank', $relatedAgent->getRelatedAgentType()->getName());
156
                        }
157
                    }
158
                }
159
            }
160
        }
161
    }
162
163
    public function testOtherAccount()
164
    {
165
        $messages = [
166
            $this->getV2OtherAccountMessage()
167
        ];
168
169
        foreach ($messages as $message) {
170
            $reports = $message->getRecords();
171
172
            $this->assertCount(1, $reports);
173
            foreach ($reports as $report) {
174
                $entries = $report->getEntries();
175
                $this->assertCount(1, $entries);
176
177
                /** @var DTO\Entry $entry */
178
                foreach ($entries as $entry) {
179
                    $parties = $entry->getTransactionDetail()->getRelatedParties();
180
181
                    foreach ($parties as $party) {
182
                        $this->assertInstanceOf(DTO\OtherAccount::class, $party->getAccount());
183
                    }
184
                }
185
            }
186
        }
187
    }
188
189
    public function testRelatedParties()
190
    {
191
        $messages = [
192
            $this->getV2Message(),
193
        ];
194
195
        foreach ($messages as $message) {
196
            $reports = $message->getRecords();
197
198
            $this->assertCount(1, $reports);
199
            foreach ($reports as $report) {
200
                $entries = $report->getEntries();
201
                $this->assertCount(1, $entries);
202
203
                foreach ($entries as $entry) {
204
                    $details = $entry->getTransactionDetails();
205
                    $this->assertCount(1, $details);
206
207
                    foreach ($details as $detail) {
208
                        $parties = $detail->getRelatedParties();
209
                        $this->assertCount(2, $parties);
210
211
                        foreach ($parties as $party) {
212
                            if ($party->getRelatedPartyType() instanceof DTO\Creditor) {
213
                                $this->assertEquals('Company Name', $party->getRelatedPartyType()->getName());
214
                                $this->assertEquals('NL', $party->getRelatedPartyType()->getAddress()->getCountry());
215
                                $this->assertEquals([], $party->getRelatedPartyType()->getAddress()->getAddressLines());
216
                                $this->assertEquals('NL56AGDH9619008421', (string)$party->getAccount()->getIdentification());
217
                            } elseif ($party->getRelatedPartyType() instanceof DTO\Debtor) {
218
                                $this->assertEquals('NAME NAME', $party->getRelatedPartyType()->getName());
219
                                $this->assertEquals('NL', $party->getRelatedPartyType()->getAddress()->getCountry());
220
                                $this->assertEquals(['ADDR ADDR 10', '2000 ANTWERPEN'], $party->getRelatedPartyType()->getAddress()->getAddressLines());
221
                                $this->assertEquals('NL56AGDH9619008421', (string)$party->getAccount()->getIdentification());
222
                            }
223
                        }
224
                    }
225
                }
226
            }
227
        }
228
    }
229
230
    public function testProprietaryBankTransactionCode()
231
    {
232
        $messages = [
233
            $this->getV2Message()
234
        ];
235
236
        foreach ($messages as $message) {
237
            $reports = $message->getRecords();
238
239
            $this->assertCount(1, $reports);
240
            foreach ($reports as $report) {
241
                $entries = $report->getEntries();
242
                $this->assertCount(1, $entries);
243
244
                /** @var DTO\Entry $entry */
245
                foreach ($entries as $entry) {
246
                    $this->assertInstanceOf(DTO\BankTransactionCode::class, $entry->getBankTransactionCode());
247
                    $this->assertInstanceOf(DTO\ProprietaryBankTransactionCode::class, $entry->getBankTransactionCode()->getProprietary());
248
249
                    $this->assertEquals('XXXX+000+0000+000', $entry->getBankTransactionCode()->getProprietary()->getCode());
250
                    $this->assertEquals('ZKA', $entry->getBankTransactionCode()->getProprietary()->getIssuer());
251
252
                    $this->assertCount(1, $entry->getTransactionDetails());
253
254
                    foreach ($entry->getTransactionDetails() as $details) {
255
                        $this->assertInstanceOf(DTO\BankTransactionCode::class, $details->getBankTransactionCode());
256
                        $this->assertInstanceOf(DTO\ProprietaryBankTransactionCode::class, $details->getBankTransactionCode()->getProprietary());
257
258
                        $this->assertEquals('XXXX+000+0000+000', $details->getBankTransactionCode()->getProprietary()->getCode());
259
                        $this->assertEquals('ZKA', $details->getBankTransactionCode()->getProprietary()->getIssuer());
260
                    }
261
                }
262
            }
263
        }
264
    }
265
}
266