1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Genkgo\TestCamt\Unit\Camt052\Decoder; |
6
|
|
|
|
7
|
|
|
use Genkgo\Camt\Camt052; |
8
|
|
|
use Genkgo\Camt\Camt052\Decoder\V01\Message; |
9
|
|
|
use Genkgo\Camt\Decoder as DecoderObject; |
10
|
|
|
use Genkgo\Camt\DTO; |
11
|
|
|
use PHPUnit\Framework; |
12
|
|
|
use SimpleXMLElement; |
13
|
|
|
|
14
|
|
|
class MessageTest extends Framework\TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var DecoderObject\Record&Framework\MockObject\MockObject |
18
|
|
|
*/ |
19
|
|
|
private $mockedRecordDecoder; |
20
|
|
|
|
21
|
|
|
private Message $decoder; |
22
|
|
|
|
23
|
|
|
protected function setUp(): void |
24
|
|
|
{ |
25
|
|
|
$this->mockedRecordDecoder = $this->createMock(DecoderObject\Record::class); |
26
|
|
|
$this->decoder = new Message($this->mockedRecordDecoder, new DecoderObject\Date()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testItAddsGroupHeader(): void |
30
|
|
|
{ |
31
|
|
|
$message = $this->createMock(DTO\Message::class); |
32
|
|
|
|
33
|
|
|
$message |
34
|
|
|
->expects(self::once()) |
35
|
|
|
->method('setGroupHeader') |
36
|
|
|
->with(self::isInstanceOf(DTO\GroupHeader::class)); |
37
|
|
|
|
38
|
|
|
$this->decoder->addGroupHeader($message, $this->getXmlMessage()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testItAddsReports(): void |
42
|
|
|
{ |
43
|
|
|
$message = $this->createMock(DTO\Message::class); |
44
|
|
|
|
45
|
|
|
$this->mockedRecordDecoder |
46
|
|
|
->expects(self::once()) |
47
|
|
|
->method('addBalances') |
48
|
|
|
->with( |
49
|
|
|
self::isInstanceOf(Camt052\DTO\Report::class), |
50
|
|
|
self::isInstanceOf(SimpleXMLElement::class) |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$this->mockedRecordDecoder |
54
|
|
|
->expects(self::once()) |
55
|
|
|
->method('addEntries') |
56
|
|
|
->with( |
57
|
|
|
self::isInstanceOf(Camt052\DTO\Report::class), |
58
|
|
|
self::isInstanceOf(SimpleXMLElement::class) |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$message |
62
|
|
|
->expects(self::once()) |
63
|
|
|
->method('setRecords') |
64
|
|
|
->with(self::callback(static function (array $records): bool { |
65
|
|
|
self::assertContainsOnlyInstancesOf(Camt052\DTO\Report::class, $records); |
66
|
|
|
self::assertCount(1, $records); |
67
|
|
|
|
68
|
|
|
return true; |
69
|
|
|
})); |
70
|
|
|
|
71
|
|
|
$this->decoder->addRecords($message, $this->getXmlMessage()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function getXmlMessage(): SimpleXMLElement |
75
|
|
|
{ |
76
|
|
|
$xmlContent = <<<XML |
77
|
|
|
<content> |
78
|
|
|
<BkToCstmrAcctRptV01> |
79
|
|
|
<GrpHdr> |
80
|
|
|
<MsgId>CAMT053RIB000000000001</MsgId> |
81
|
|
|
<CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm> |
82
|
|
|
<MsgRcpt> |
83
|
|
|
<Nm>COMPANY BVBA</Nm> |
84
|
|
|
<PstlAdr> |
85
|
|
|
<StrtNm>12 Oxford Street</StrtNm> |
86
|
|
|
<Ctry>UK</Ctry> |
87
|
|
|
</PstlAdr> |
88
|
|
|
<Id> |
89
|
|
|
<OrgId> |
90
|
|
|
<BIC>DABAIE2D</BIC> |
91
|
|
|
<IBEI>BCBDFHJNP8</IBEI> |
92
|
|
|
<BEI>BTDTRSBA</BEI> |
93
|
|
|
<EANGLN>4839402843123</EANGLN> |
94
|
|
|
<PrtryId> |
95
|
|
|
<Id>Some other Id</Id> |
96
|
|
|
<Issr>Some other Issuer</Issr> |
97
|
|
|
</PrtryId> |
98
|
|
|
</OrgId> |
99
|
|
|
</Id> |
100
|
|
|
<CtryOfRes>NL</CtryOfRes> |
101
|
|
|
</MsgRcpt> |
102
|
|
|
</GrpHdr> |
103
|
|
|
<Rpt> |
104
|
|
|
<Id>253EURNL26VAYB8060476890</Id> |
105
|
|
|
<CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm> |
106
|
|
|
<Acct> |
107
|
|
|
<Id> |
108
|
|
|
<PrtryAcct> |
109
|
|
|
<Id>50000000054910000003</Id> |
110
|
|
|
</PrtryAcct> |
111
|
|
|
</Id> |
112
|
|
|
</Acct> |
113
|
|
|
</Rpt> |
114
|
|
|
</BkToCstmrAcctRptV01> |
115
|
|
|
</content> |
116
|
|
|
XML; |
117
|
|
|
|
118
|
|
|
return new SimpleXMLElement($xmlContent); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|