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

MessageTest::testItAddsGroupHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Genkgo\TestCamt\Unit\Camt054\Decoder;
6
7
use Genkgo\Camt\Camt054;
8
use Genkgo\Camt\Camt054\Decoder\Message;
9
use Genkgo\Camt\Decoder as DecoderObject;
10
use Genkgo\Camt\DTO;
11
use Genkgo\TestCamt\AbstractTestCase;
12
use Prophecy\Argument;
13
use Prophecy\Prophecy\ObjectProphecy;
14
use SimpleXMLElement;
15
16
class MessageTest extends AbstractTestCase
17
{
18
    /**
19
     * @var ObjectProphecy
20
     */
21
    private $mockedRecordDecoder;
22
23
    /**
24
     * @var Message
25
     */
26
    private $decoder;
27
28
    protected function setUp(): void
29
    {
30
        $entry = $this->prophesize(DecoderObject\Entry::class);
31
        $this->mockedRecordDecoder = $this
32
            ->prophesize(DecoderObject\Record::class)
33
            ->willBeConstructedWith([$entry->reveal(), new DecoderObject\Date()]);
34
        $this->decoder = new Message($this->mockedRecordDecoder->reveal(), new DecoderObject\Date());
35
    }
36
37
    public function testItAddsGroupHeader(): void
38
    {
39
        $message = $this->prophesize(DTO\Message::class);
40
        $message->setGroupHeader(Argument::type(DTO\GroupHeader::class))->shouldBeCalled();
41
42
        $this->decoder->addGroupHeader($message->reveal(), $this->getXmlMessage());
43
    }
44
45
    public function testItAddsNotifications(): void
46
    {
47
        $message = $this->prophesize(DTO\Message::class);
48
49
        $this->mockedRecordDecoder->addEntries(
50
            Argument::type(Camt054\DTO\Notification::class),
51
            Argument::type('\SimpleXMLElement')
52
        )->shouldBeCalled();
53
54
        $message->setRecords(Argument::that(function ($argument): bool {
55
            return is_array($argument) && $argument[0] instanceof Camt054\DTO\Notification;
56
        }))->shouldBeCalled();
57
58
        $this->decoder->addRecords($message->reveal(), $this->getXmlMessage());
59
    }
60
61
    private function getXmlMessage(): SimpleXMLElement
62
    {
63
        $xmlContent = <<<XML
64
<content>
65
    <BkToCstmrDbtCdtNtfctn>
66
        <GrpHdr>
67
            <MsgId>CAMT053RIB000000000001</MsgId>
68
            <CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm>
69
        </GrpHdr>
70
        <Ntfctn>
71
            <Id>253EURNL26VAYB8060476890</Id>
72
            <CreDtTm>2015-03-10T18:43:50+00:00</CreDtTm>
73
            <Acct>
74
                <Id>
75
                    <PrtryAcct>
76
                        <Id>50000000054910000003</Id>
77
                    </PrtryAcct>
78
                </Id>
79
            </Acct>
80
        </Ntfctn>
81
    </BkToCstmrDbtCdtNtfctn>
82
</content>
83
XML;
84
85
        return new SimpleXMLElement($xmlContent);
86
    }
87
}
88