|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Genkgo\TestCamt\Unit\Camt053\Decoder; |
|
6
|
|
|
|
|
7
|
|
|
use Genkgo\Camt\Camt053; |
|
8
|
|
|
use Genkgo\Camt\Camt053\Decoder\Message; |
|
9
|
|
|
use Genkgo\Camt\Decoder as DecoderObject; |
|
10
|
|
|
use Genkgo\Camt\DTO; |
|
11
|
|
|
use Genkgo\TestCamt\AbstractTestCase; |
|
12
|
|
|
use Prophecy\Argument; |
|
13
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
|
14
|
|
|
use SimpleXMLElement; |
|
15
|
|
|
|
|
16
|
|
|
class MessageTest extends AbstractTestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var ObjectProphecy |
|
20
|
|
|
*/ |
|
21
|
|
|
private $mockedRecordDecoder; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Message |
|
25
|
|
|
*/ |
|
26
|
|
|
private $decoder; |
|
27
|
|
|
|
|
28
|
|
|
protected function setUp(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$entry = $this->prophesize(DecoderObject\Entry::class); |
|
31
|
|
|
$this->mockedRecordDecoder = $this |
|
32
|
|
|
->prophesize(DecoderObject\Record::class) |
|
33
|
|
|
->willBeConstructedWith([$entry->reveal(), new DecoderObject\Date()]); |
|
34
|
|
|
$this->decoder = new Message($this->mockedRecordDecoder->reveal(), new DecoderObject\Date()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testItAddsGroupHeader(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$message = $this->prophesize(DTO\Message::class); |
|
40
|
|
|
$message->setGroupHeader(Argument::type(DTO\GroupHeader::class))->shouldBeCalled(); |
|
41
|
|
|
|
|
42
|
|
|
$this->decoder->addGroupHeader($message->reveal(), $this->getXmlMessage()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testItAddsStatements(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$message = $this->prophesize(DTO\Message::class); |
|
48
|
|
|
|
|
49
|
|
|
$this->mockedRecordDecoder->addBalances( |
|
50
|
|
|
Argument::type(Camt053\DTO\Statement::class), |
|
51
|
|
|
Argument::type('\SimpleXMLElement') |
|
52
|
|
|
)->shouldBeCalled(); |
|
53
|
|
|
$this->mockedRecordDecoder->addEntries( |
|
54
|
|
|
Argument::type(Camt053\DTO\Statement::class), |
|
55
|
|
|
Argument::type('\SimpleXMLElement') |
|
56
|
|
|
)->shouldBeCalled(); |
|
57
|
|
|
|
|
58
|
|
|
$message->setRecords(Argument::that(function ($argument): bool { |
|
59
|
|
|
return is_array($argument) && $argument[0] instanceof Camt053\DTO\Statement; |
|
60
|
|
|
}))->shouldBeCalled(); |
|
61
|
|
|
|
|
62
|
|
|
$this->decoder->addRecords($message->reveal(), $this->getXmlMessage()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function getXmlMessage(): SimpleXMLElement |
|
66
|
|
|
{ |
|
67
|
|
|
$xmlContent = <<<XML |
|
68
|
|
|
<content> |
|
69
|
|
|
<BkToCstmrStmt> |
|
70
|
|
|
<GrpHdr> |
|
71
|
|
|
<MsgId>CAMT053RIB000000000001</MsgId> |
|
72
|
|
|
<CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm> |
|
73
|
|
|
</GrpHdr> |
|
74
|
|
|
<Stmt> |
|
75
|
|
|
<Id>253EURNL26VAYB8060476890</Id> |
|
76
|
|
|
<CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm> |
|
77
|
|
|
<Acct> |
|
78
|
|
|
<Id> |
|
79
|
|
|
<IBAN>NL26VAYB8060476890</IBAN> |
|
80
|
|
|
</Id> |
|
81
|
|
|
</Acct> |
|
82
|
|
|
</Stmt> |
|
83
|
|
|
</BkToCstmrStmt> |
|
84
|
|
|
</content> |
|
85
|
|
|
|
|
86
|
|
|
XML; |
|
87
|
|
|
|
|
88
|
|
|
return new SimpleXMLElement($xmlContent); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|