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

RecordTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 64
dl 0
loc 111
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A getXmlRecord() 0 38 1
A it_adds_balances_if_there_are_present_in_xml() 0 6 1
A it_adds_entries_if_there_are_present_in_xml() 0 14 1
A it_does_not_add_balances_if_there_are_none_in_xml() 0 7 1
A it_adds_no_entries_if_there_are_none_in_xml() 0 8 1
1
<?php
2
3
namespace Genkgo\TestCamt\Unit\Decoder;
4
5
use Genkgo\TestCamt\AbstractTestCase;
6
use Genkgo\Camt\Decoder;
7
use Genkgo\Camt\DTO;
8
use Genkgo\Camt\Camt053;
9
use Prophecy\Argument;
10
use Prophecy\Prophecy\ObjectProphecy;
11
12
class RecordTest extends AbstractTestCase
13
{
14
    /** @var ObjectProphecy */
15
    private $mockedEntryDecoder;
16
17
    /** @var Decoder\Record */
18
    private $decoder;
19
20
    public function setUp()
21
    {
22
        $entryTransactionDetail = $this->prophesize(Decoder\EntryTransactionDetail::class);
23
        $this->mockedEntryDecoder = $this
24
            ->prophesize(Decoder\Entry::class)
25
            ->willBeConstructedWith([$entryTransactionDetail->reveal()])
26
        ;
27
        $this->decoder = new Decoder\Record($this->mockedEntryDecoder->reveal(), new Decoder\Date());
28
    }
29
30
    /**
31
     * @test
32
     */
33
    public function it_does_not_add_balances_if_there_are_none_in_xml()
34
    {
35
        $record = $this->prophesize(Camt053\DTO\Statement::class);
36
        $record->addBalance(Argument::any())->shouldNotBeCalled();
37
38
        $xmlRecord = new \SimpleXMLElement('<content></content>');
39
        $this->decoder->addBalances($record->reveal(), $xmlRecord);
40
    }
41
42
    /**
43
     * @test
44
     */
45
    public function it_adds_balances_if_there_are_present_in_xml()
46
    {
47
        $record = $this->prophesize(Camt053\DTO\Statement::class);
48
        $record->addBalance(Argument::type(DTO\Balance::class))->shouldBeCalled();
49
50
        $this->decoder->addBalances($record->reveal(), $this->getXmlRecord());
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function it_adds_no_entries_if_there_are_none_in_xml()
57
    {
58
        $record = $this->prophesize(DTO\Record::class);
59
        $this->mockedEntryDecoder->addTransactionDetails(Argument::any(), Argument::any())->shouldNotBeCalled();
60
        $record->addEntry(Argument::any())->shouldNotBeCalled();
61
        $xmlRecord = new \SimpleXMLElement('<content></content>');
62
63
        $this->decoder->addEntries($record->reveal(), $xmlRecord);
64
    }
65
66
    /**
67
     * @test
68
     */
69
    public function it_adds_entries_if_there_are_present_in_xml()
70
    {
71
        $record = $this->prophesize(DTO\Record::class);
72
        $this
73
            ->mockedEntryDecoder
74
            ->addTransactionDetails(
75
                Argument::type(DTO\Entry::class),
76
                Argument::type('\SimpleXMLElement')
77
            )
78
            ->shouldBeCalled()
79
        ;
80
        $record->addEntry(Argument::type(DTO\Entry::class))->shouldBeCalled();
81
82
        $this->decoder->addEntries($record->reveal(), $this->getXmlRecord());
83
    }
84
85
    private function getXmlRecord()
86
    {
87
        $xmlContent = <<<XML
88
<content>
89
    <Bal>
90
        <Amt Ccy="EUR">24.22</Amt>
91
        <Dt>
92
            <Dt>2014-12-30</Dt>
93
        </Dt>
94
        <CdtDbtInd>DBIT</CdtDbtInd>
95
        <Tp>
96
            <CdOrPrtry>
97
                <Cd>OPBD</Cd>
98
            </CdOrPrtry>
99
        </Tp>
100
    </Bal>
101
    <Ntry>
102
        <Amt Ccy="EUR">1.42</Amt>
103
        <BookgDt>
104
            <Dt></Dt>
105
        </BookgDt>
106
        <ValDt>
107
            <Dt></Dt>
108
        </ValDt>
109
        <CdtDbtInd>DBIT</CdtDbtInd>
110
        <RvslInd>true</RvslInd>
111
        <NtryRef>lorem</NtryRef>
112
        <AcctSvcrRef>ipsum</AcctSvcrRef>
113
        <NtryDtls>
114
            <Btch>
115
                <PmtInfId>id</PmtInfId>
116
            </Btch>
117
        </NtryDtls>
118
    </Ntry>
119
</content>
120
XML;
121
122
        return new \SimpleXMLElement($xmlContent);
123
    }
124
}
125