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

EntryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 68
dl 0
loc 96
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A it_adds_transaction_details_if_there_are_present_in_xml() 0 52 1
A it_does_not_add_transaction_details_if_there_is_none_in_xml() 0 7 1
A getXmlEntry() 0 13 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 Prophecy\Argument;
9
use Prophecy\Prophecy\ObjectProphecy;
10
11
class EntryTest extends AbstractTestCase
12
{
13
    /** @var ObjectProphecy */
14
    private $mockedEntryTransactionDetailDecoder;
15
16
    /** @var Decoder\Entry */
17
    private $decoder;
18
19
    public function setUp()
20
    {
21
        $this->mockedEntryTransactionDetailDecoder = $this->prophesize(Decoder\EntryTransactionDetail::class);
22
        $this->decoder = new Decoder\Entry($this->mockedEntryTransactionDetailDecoder->reveal());
23
    }
24
25
    /**
26
     * @test
27
     */
28
    public function it_does_not_add_transaction_details_if_there_is_none_in_xml()
29
    {
30
        $entry = $this->prophesize(DTO\Entry::class);
31
        $entry->addTransactionDetail(Argument::any())->shouldNotBeCalled();
32
33
        $xmlEntry = new \SimpleXMLElement('<content></content>');
34
        $this->decoder->addTransactionDetails($entry->reveal(), $xmlEntry);
35
    }
36
37
    /**
38
     * @test
39
     */
40
    public function it_adds_transaction_details_if_there_are_present_in_xml()
41
    {
42
        $entry = $this->prophesize(DTO\Entry::class);
43
        $this->mockedEntryTransactionDetailDecoder->addReferences(
44
            Argument::type(DTO\EntryTransactionDetail::class),
45
            Argument::type('\SimpleXMLElement')
46
        )->shouldBeCalled();
47
        $this->mockedEntryTransactionDetailDecoder->addRelatedParties(
48
            Argument::type(DTO\EntryTransactionDetail::class),
49
            Argument::type('\SimpleXMLElement')
50
        )->shouldBeCalled();
51
        $this->mockedEntryTransactionDetailDecoder->addRelatedAgents(
52
            Argument::type(DTO\EntryTransactionDetail::class),
53
            Argument::type('\SimpleXMLElement')
54
        )->shouldBeCalled();
55
        $this->mockedEntryTransactionDetailDecoder->addRemittanceInformation(
56
            Argument::type(DTO\EntryTransactionDetail::class),
57
            Argument::type('\SimpleXMLElement')
58
        )->shouldBeCalled();
59
        $this->mockedEntryTransactionDetailDecoder->addRelatedDates(
60
            Argument::type(DTO\EntryTransactionDetail::class),
61
            Argument::type('\SimpleXMLElement')
62
        )->shouldBeCalled();
63
        $this->mockedEntryTransactionDetailDecoder->addReturnInformation(
64
            Argument::type(DTO\EntryTransactionDetail::class),
65
            Argument::type('\SimpleXMLElement')
66
        )->shouldBeCalled();
67
        $this->mockedEntryTransactionDetailDecoder->addAdditionalTransactionInformation(
68
            Argument::type(DTO\EntryTransactionDetail::class),
69
            Argument::type('\SimpleXMLElement')
70
        )->shouldBeCalled();
71
        $this->mockedEntryTransactionDetailDecoder->addBankTransactionCode(
72
            Argument::type(DTO\EntryTransactionDetail::class),
73
            Argument::type('\SimpleXMLElement')
74
        )->shouldBeCalled();
75
        $this->mockedEntryTransactionDetailDecoder->addCharges(
76
            Argument::type(DTO\EntryTransactionDetail::class),
77
            Argument::type('\SimpleXMLElement')
78
        )->shouldBeCalled();
79
        $this->mockedEntryTransactionDetailDecoder->addAmountDetails(
80
            Argument::type(DTO\EntryTransactionDetail::class),
81
            Argument::type('\SimpleXMLElement'),
82
            Argument::type('\SimpleXMLElement')
83
        )->shouldBeCalled();
84
        $this->mockedEntryTransactionDetailDecoder->addAmount(
85
            Argument::type(DTO\EntryTransactionDetail::class),
86
            Argument::type('\SimpleXMLElement'),
87
            Argument::type('\SimpleXMLElement')
88
        )->shouldBeCalled();
89
        $entry->addTransactionDetail(Argument::type(DTO\EntryTransactionDetail::class))->shouldBeCalled();
90
91
        $this->decoder->addTransactionDetails($entry->reveal(), $this->getXmlEntry());
92
    }
93
94
    private function getXmlEntry()
95
    {
96
        $xmlContent = <<<XML
97
<content>
98
    <NtryDtls>
99
        <TxDtls>
100
            <EndToEndId>000000001</EndToEndId>
101
        </TxDtls>
102
    </NtryDtls>
103
</content>
104
XML;
105
106
        return new \SimpleXMLElement($xmlContent);
107
    }
108
}
109