|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Genkgo\TestCamt\Unit\Camt054\Decoder; |
|
6
|
|
|
|
|
7
|
|
|
use Genkgo\Camt\Camt054; |
|
8
|
|
|
use Genkgo\Camt\Camt054\Decoder\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 testItAddsNotifications(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$message = $this->createMock(DTO\Message::class); |
|
44
|
|
|
|
|
45
|
|
|
$this->mockedRecordDecoder |
|
46
|
|
|
->expects(self::once()) |
|
47
|
|
|
->method('addEntries') |
|
48
|
|
|
->with( |
|
49
|
|
|
self::isInstanceOf(Camt054\DTO\Notification::class), |
|
50
|
|
|
self::isInstanceOf(SimpleXMLElement::class), |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
$message |
|
54
|
|
|
->expects(self::once()) |
|
55
|
|
|
->method('setRecords') |
|
56
|
|
|
->with(self::callback(static function (array $records): bool { |
|
57
|
|
|
self::assertContainsOnlyInstancesOf(Camt054\DTO\Notification::class, $records); |
|
58
|
|
|
self::assertCount(1, $records); |
|
59
|
|
|
|
|
60
|
|
|
return true; |
|
61
|
|
|
})); |
|
62
|
|
|
|
|
63
|
|
|
$this->decoder->addRecords($message, $this->getXmlMessage()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
private function getXmlMessage(): SimpleXMLElement |
|
67
|
|
|
{ |
|
68
|
|
|
$xmlContent = <<<XML |
|
69
|
|
|
<content> |
|
70
|
|
|
<BkToCstmrDbtCdtNtfctn> |
|
71
|
|
|
<GrpHdr> |
|
72
|
|
|
<MsgId>CAMT053RIB000000000001</MsgId> |
|
73
|
|
|
<CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm> |
|
74
|
|
|
</GrpHdr> |
|
75
|
|
|
<Ntfctn> |
|
76
|
|
|
<Id>253EURNL26VAYB8060476890</Id> |
|
77
|
|
|
<CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm> |
|
78
|
|
|
<Acct> |
|
79
|
|
|
<Id> |
|
80
|
|
|
<PrtryAcct> |
|
81
|
|
|
<Id>50000000054910000003</Id> |
|
82
|
|
|
</PrtryAcct> |
|
83
|
|
|
</Id> |
|
84
|
|
|
</Acct> |
|
85
|
|
|
</Ntfctn> |
|
86
|
|
|
</BkToCstmrDbtCdtNtfctn> |
|
87
|
|
|
</content> |
|
88
|
|
|
XML; |
|
89
|
|
|
|
|
90
|
|
|
return new SimpleXMLElement($xmlContent); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|