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

testItAddsTransactionDetailsIfThereArePresentInXml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 49
nc 1
nop 0
dl 0
loc 52
rs 9.1127
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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