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

EntryTransactionDetailTest::getXmlDetail()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 67
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 64
nc 1
nop 0
dl 0
loc 67
rs 8.7853
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
namespace Genkgo\TestCamt\Unit\Decoder;
4
5
use Genkgo\Camt\Decoder\Date;
6
use Genkgo\TestCamt\AbstractTestCase;
7
use Genkgo\Camt\Camt053;
8
use Genkgo\Camt\DTO;
9
use Prophecy\Argument;
10
11
class EntryTransactionDetailTest extends AbstractTestCase
12
{
13
    /**
14
     * @test
15
     */
16
    public function it_does_not_add_reference_if_there_is_none_in_xml()
17
    {
18
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
19
        $detail->addReference(Argument::any())->shouldNotBeCalled();
20
21
        $xmlDetail = new \SimpleXMLElement('<content></content>');
22
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addReferences($detail->reveal(), $xmlDetail);
23
    }
24
25
    /**
26
     * @test
27
     */
28
    public function it_adds_reference_if_it_is_present_in_xml()
29
    {
30
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
31
        $detail->addReference(Argument::type(DTO\Reference::class))->shouldBeCalled();
32
33
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addReferences($detail->reveal(), $this->getXmlDetail());
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function it_does_not_add_additional_transaction_information_if_there_is_none_in_xml()
40
    {
41
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
42
        $detail->setAdditionalTransactionInformation(Argument::any())->shouldNotBeCalled();
43
44
        $xmlDetail = new \SimpleXMLElement('<content></content>');
45
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addAdditionalTransactionInformation($detail->reveal(), $xmlDetail);
46
    }
47
48
    /**
49
     * @test
50
     */
51
    public function it_adds_additional_transaction_information_if_it_is_present_in_xml()
52
    {
53
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
54
        $detail->setAdditionalTransactionInformation(
55
            Argument::type(DTO\AdditionalTransactionInformation::class)
56
        )->shouldBeCalled();
57
58
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addAdditionalTransactionInformation($detail->reveal(), $this->getXmlDetail());
59
    }
60
61
    /**
62
     * @test
63
     */
64
    public function it_does_not_add_remittance_information_if_there_is_none_in_xml()
65
    {
66
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
67
        $detail->setRemittanceInformation(Argument::any())->shouldNotBeCalled();
68
69
        $xmlDetail = new \SimpleXMLElement('<content></content>');
70
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRemittanceInformation($detail->reveal(), $xmlDetail);
71
    }
72
73
    /**
74
     * @test
75
     */
76
    public function it_adds_remittance_information_and_creditor_reference_if_it_is_present_in_xml()
77
    {
78
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
79
        $detail->setRemittanceInformation(Argument::type(DTO\RemittanceInformation::class))->shouldBeCalled();
80
81
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRemittanceInformation($detail->reveal(), $this->getXmlDetail());
82
    }
83
84
    /**
85
     * @test
86
     */
87
    public function it_adds_remittance_information_if_it_is_present_in_xml()
88
    {
89
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
90
        $detail->setRemittanceInformation(Argument::type(DTO\RemittanceInformation::class))->shouldBeCalled();
91
92
        $xmlDetail = new \SimpleXMLElement('<content><RmtInf><Ustrd>Lorem</Ustrd></RmtInf></content>');
93
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRemittanceInformation($detail->reveal(), $xmlDetail);
94
    }
95
96
    /**
97
     * @test
98
     */
99
    public function it_does_not_add_return_information_if_there_is_none_in_xml()
100
    {
101
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
102
        $detail->setReturnInformation(Argument::any())->shouldNotBeCalled();
103
104
        $xmlDetail = new \SimpleXMLElement('<content></content>');
105
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addReturnInformation($detail->reveal(), $xmlDetail);
106
    }
107
108
    /**
109
     * @test
110
     */
111
    public function it_adds_return_information_if_it_is_present_in_xml()
112
    {
113
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
114
        $detail->setReturnInformation(
115
            Argument::type(DTO\ReturnInformation::class)
116
        )->shouldBeCalled();
117
118
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addReturnInformation($detail->reveal(), $this->getXmlDetail());
119
    }
120
121
    /**
122
     * @test
123
     */
124
    public function it_does_not_add_related_parties_if_there_is_none_in_xml()
125
    {
126
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
127
        $detail->addRelatedParty(Argument::any())->shouldNotBeCalled();
128
129
        $xmlDetail = new \SimpleXMLElement('<content></content>');
130
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRelatedParties($detail->reveal(), $xmlDetail);
131
    }
132
133
    /**
134
     * @test
135
     */
136
    public function it_adds_related_parties_if_is_present_in_xml()
137
    {
138
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
139
        $detail->addRelatedParty(Argument::type(DTO\RelatedParty::class))->shouldBeCalled();
140
141
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRelatedParties($detail->reveal(), $this->getXmlDetail());
142
    }
143
144
    /**
145
     * @test
146
     */
147
    public function it_does_not_add_related_dates_if_there_is_none_in_xml()
148
    {
149
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
150
        $detail->setRelatedDates(Argument::any())->shouldNotBeCalled();
151
152
        $xmlDetail = new \SimpleXMLElement('<content></content>');
153
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRelatedDates($detail->reveal(), $xmlDetail);
154
    }
155
156
    /**
157
     * @test
158
     */
159
    public function it_adds_related_dates_if_is_present_in_xml()
160
    {
161
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
162
        $detail->setRelatedDates(Argument::type(DTO\RelatedDates::class))->shouldBeCalled();
163
164
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addRelatedDates($detail->reveal(), $this->getXmlDetail());
165
    }
166
167
    /**
168
     * @test
169
     */
170
    public function it_does_not_add_charges_if_there_is_none_in_xml()
171
    {
172
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
173
        $detail->setCharges(Argument::any())->shouldNotBeCalled();
174
175
        $xmlDetail = new \SimpleXMLElement('<content></content>');
176
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addCharges($detail->reveal(), $xmlDetail);
177
    }
178
179
    /**
180
     * @test
181
     */
182
    public function it_adds_charges_if_is_present_in_xml()
183
    {
184
        $detail = $this->prophesize(DTO\EntryTransactionDetail::class);
185
        $detail->setCharges(Argument::type(DTO\Charges::class))->shouldBeCalled();
186
187
        (new Camt053\Decoder\EntryTransactionDetail(new Date()))->addCharges($detail->reveal(), $this->getXmlDetail());
188
    }
189
190
    
191
    private function getXmlDetail()
192
    {
193
        $xmlContent = <<<XML
194
<content>
195
    <Refs>
196
        <EndToEndId>some end to end id</EndToEndId>
197
        <MndtId>some mandate id</MndtId>
198
    </Refs>
199
    <AddtlTxInf>additional transaction information</AddtlTxInf>
200
    <RtrInf>
201
        <Rsn>
202
            <Cd>lorem</Cd>
203
        </Rsn>
204
        <AddtlInf>ipsum</AddtlInf>
205
    </RtrInf>
206
    <RmtInf>
207
        <Strd>
208
            <CdtrRefInf>
209
                <Ref>Some reference</Ref>
210
            </CdtrRefInf>
211
            <Cd>lorem</Cd>
212
        </Strd>
213
    </RmtInf>
214
    <RltdDts>
215
      <AccptncDtTm>2017-02-27T15:23:45.446</AccptncDtTm>
216
    </RltdDts>
217
    <Chrgs>
218
      <TtlChrgsAndTaxAmt Ccy="CHF">1.79</TtlChrgsAndTaxAmt>
219
      <Rcrd>
220
        <Amt Ccy="CHF">1.75</Amt>
221
        <CdtDbtInd>DBIT</CdtDbtInd>
222
        <ChrgInclInd>false</ChrgInclInd>
223
        <Tp>
224
          <Prtry>
225
            <Id>2</Id>
226
          </Prtry>
227
        </Tp>
228
      </Rcrd>
229
      <Rcrd>
230
        <Amt Ccy="CHF">0.04</Amt>
231
        <CdtDbtInd>DBIT</CdtDbtInd>
232
        <ChrgInclInd>false</ChrgInclInd>
233
        <Tp>
234
          <Prtry>
235
            <Id>4</Id>
236
          </Prtry>
237
        </Tp>
238
      </Rcrd>
239
    </Chrgs>    
240
    <RltdPties>
241
        <Cdtr>
242
            <Nm>Lorem</Nm>
243
            <PstlAdr>
244
                <Ctry>NL</Ctry>
245
                <AdrLine>NL</AdrLine>
246
            </PstlAdr>
247
        </Cdtr>
248
        <CdtrAcct>
249
            <Id>
250
                <IBAN>NL39ULSS6234823955</IBAN>
251
            </Id>
252
        </CdtrAcct>
253
    </RltdPties>
254
</content>
255
XML;
256
257
        return new \SimpleXMLElement($xmlContent);
258
    }
259
}
260