Failed Conditions
Push — master ( 65cf51...40aca8 )
by Adrien
03:16
created

MessageTest::it_adds_group_header()   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\Decoder;
4
5
use Genkgo\TestCamt\AbstractTestCase;
6
use Genkgo\Camt\Camt052;
7
use Genkgo\Camt\DTO;
8
use Genkgo\Camt\Decoder as DecoderObject;
9
use Prophecy\Argument;
10
use Prophecy\Prophecy\ObjectProphecy;
11
12
class MessageTest extends AbstractTestCase
13
{
14
    /** @var ObjectProphecy */
15
    private $mockedRecordDecoder;
16
17
    /** @var DecoderObject\Message */
18
    private $decoder;
19
20
    public function setUp()
21
    {
22
        $entry = $this->prophesize(DecoderObject\Entry::class);
23
        $this->mockedRecordDecoder = $this
24
            ->prophesize(DecoderObject\Record::class)
25
            ->willBeConstructedWith([$entry->reveal(), new DecoderObject\Date()])
26
        ;
27
        $this->decoder = new Camt052\Decoder\V01\Message($this->mockedRecordDecoder->reveal(), new DecoderObject\Date());
28
    }
29
30
    /**
31
     * @test
32
     */
33
    public function it_adds_group_header()
34
    {
35
        $message = $this->prophesize(DTO\Message::class);
36
        $message->setGroupHeader(Argument::type(DTO\GroupHeader::class))->shouldBeCalled();
37
38
        $this->decoder->addGroupHeader($message->reveal(), $this->getXmlMessage());
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function it_adds_reports()
45
    {
46
        $message = $this->prophesize(DTO\Message::class);
47
48
        $this->mockedRecordDecoder->addBalances(
49
            Argument::type(Camt052\DTO\Report::class),
50
            Argument::type('\SimpleXMLElement')
51
        )->shouldBeCalled();
52
        $this->mockedRecordDecoder->addEntries(
53
            Argument::type(Camt052\DTO\Report::class),
54
            Argument::type('\SimpleXMLElement')
55
        )->shouldBeCalled();
56
57
        $message->setRecords(Argument::that(function ($argument) {
58
            return is_array($argument) && $argument[0] instanceof Camt052\DTO\Report;
59
        }))->shouldBeCalled();
60
61
        $this->decoder->addRecords($message->reveal(), $this->getXmlMessage());
62
    }
63
64
    private function getXmlMessage()
65
    {
66
        $xmlContent = <<<XML
67
<content>
68
    <BkToCstmrAcctRptV01>
69
        <GrpHdr>
70
            <MsgId>CAMT053RIB000000000001</MsgId>
71
            <CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm>
72
            <MsgRcpt>
73
                <Nm>COMPANY BVBA</Nm>
74
                <PstlAdr>
75
                    <StrtNm>12 Oxford Street</StrtNm>
76
                    <Ctry>UK</Ctry>
77
                </PstlAdr>
78
                <Id>
79
                    <OrgId>
80
                        <BIC>DABAIE2D</BIC>
81
                        <IBEI>BCBDFHJNP8</IBEI>
82
                        <BEI>BTDTRSBA</BEI>
83
                        <EANGLN>4839402843123</EANGLN>
84
                        <PrtryId>
85
                            <Id>Some other Id</Id>
86
                            <Issr>Some other Issuer</Issr>
87
                        </PrtryId>
88
                    </OrgId>
89
                </Id>
90
                <CtryOfRes>NL</CtryOfRes>
91
            </MsgRcpt>
92
        </GrpHdr>
93
        <Rpt>
94
            <Id>253EURNL26VAYB8060476890</Id>
95
            <CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm>
96
            <Acct>
97
                <Id>
98
                    <PrtryAcct>
99
                        <Id>50000000054910000003</Id>
100
                    </PrtryAcct>
101
                </Id>
102
            </Acct>
103
        </Rpt>
104
    </BkToCstmrAcctRptV01>
105
</content>
106
XML;
107
108
        return new \SimpleXMLElement($xmlContent);
109
    }
110
}
111