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
|
|
|
|