Failed Conditions
Push — master ( c3df43...3c8a24 )
by Adrien
02:34
created

MessageTest::testItAddsGroupHeader()   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\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 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 testItAddsReports(): void
46
    {
47
        $message = $this->prophesize(DTO\Message::class);
48
49
        $this->mockedRecordDecoder->addBalances(
50
            Argument::type(Camt052\DTO\Report::class),
51
            Argument::type('\SimpleXMLElement')
52
        )->shouldBeCalled();
53
        $this->mockedRecordDecoder->addEntries(
54
            Argument::type(Camt052\DTO\Report::class),
55
            Argument::type('\SimpleXMLElement')
56
        )->shouldBeCalled();
57
58
        $message->setRecords(Argument::that(function ($argument): bool {
59
            return is_array($argument) && $argument[0] instanceof Camt052\DTO\Report;
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
    <BkToCstmrAcctRptV01>
70
        <GrpHdr>
71
            <MsgId>CAMT053RIB000000000001</MsgId>
72
            <CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm>
73
            <MsgRcpt>
74
                <Nm>COMPANY BVBA</Nm>
75
                <PstlAdr>
76
                    <StrtNm>12 Oxford Street</StrtNm>
77
                    <Ctry>UK</Ctry>
78
                </PstlAdr>
79
                <Id>
80
                    <OrgId>
81
                        <BIC>DABAIE2D</BIC>
82
                        <IBEI>BCBDFHJNP8</IBEI>
83
                        <BEI>BTDTRSBA</BEI>
84
                        <EANGLN>4839402843123</EANGLN>
85
                        <PrtryId>
86
                            <Id>Some other Id</Id>
87
                            <Issr>Some other Issuer</Issr>
88
                        </PrtryId>
89
                    </OrgId>
90
                </Id>
91
                <CtryOfRes>NL</CtryOfRes>
92
            </MsgRcpt>
93
        </GrpHdr>
94
        <Rpt>
95
            <Id>253EURNL26VAYB8060476890</Id>
96
            <CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm>
97
            <Acct>
98
                <Id>
99
                    <PrtryAcct>
100
                        <Id>50000000054910000003</Id>
101
                    </PrtryAcct>
102
                </Id>
103
            </Acct>
104
        </Rpt>
105
    </BkToCstmrAcctRptV01>
106
</content>
107
XML;
108
109
        return new SimpleXMLElement($xmlContent);
110
    }
111
}
112