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

MessageTest::it_adds_notifications()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 1
nop 0
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Genkgo\TestCamt\Unit\Camt054\Decoder;
4
5
use Genkgo\TestCamt\AbstractTestCase;
6
use Genkgo\Camt\Camt054;
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 Camt054\Decoder\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_notifications()
45
    {
46
        $message = $this->prophesize(DTO\Message::class);
47
48
        $this->mockedRecordDecoder->addEntries(
49
            Argument::type(Camt054\DTO\Notification::class),
50
            Argument::type('\SimpleXMLElement')
51
        )->shouldBeCalled();
52
53
        $message->setRecords(Argument::that(function ($argument) {
54
            return is_array($argument) && $argument[0] instanceof Camt054\DTO\Notification;
55
        }))->shouldBeCalled();
56
57
        $this->decoder->addRecords($message->reveal(), $this->getXmlMessage());
58
    }
59
60
    private function getXmlMessage()
61
    {
62
        $xmlContent = <<<XML
63
<content>
64
    <BkToCstmrDbtCdtNtfctn>
65
        <GrpHdr>
66
            <MsgId>CAMT053RIB000000000001</MsgId>
67
            <CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm>
68
        </GrpHdr>
69
        <Ntfctn>
70
            <Id>253EURNL26VAYB8060476890</Id>
71
            <CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm>
72
            <Acct>
73
                <Id>
74
                    <PrtryAcct>
75
                        <Id>50000000054910000003</Id>
76
                    </PrtryAcct>
77
                </Id>
78
            </Acct>
79
        </Ntfctn>
80
    </BkToCstmrDbtCdtNtfctn>
81
</content>
82
XML;
83
84
        return new \SimpleXMLElement($xmlContent);
85
    }
86
}
87