1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
require_once __DIR__ . '/../vendor/autoload.php'; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
#[CoversClass(\danielgp\efactura\ElectornicInvoiceRead::class)] |
11
|
|
|
#[CoversClass(\danielgp\efactura\ElectornicInvoiceWrite::class)] |
12
|
|
|
final class ReadWriteTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
const REMOTE_UBL_EXAMPLES_PATH = 'https://raw.githubusercontent.com/ConnectingEurope/eInvoicing-EN16931/' |
16
|
|
|
. 'master/ubl/examples/'; |
17
|
|
|
const LOCAL_RESULT_FILE = __DIR__ . '/resultWrite.xml'; |
18
|
|
|
|
19
|
|
|
public function testReadRemoteXml() |
20
|
|
|
{ |
21
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example1.xml'; |
22
|
|
|
$xmlContent = file_get_contents($url); |
23
|
|
|
$this->assertNotEmpty($xmlContent); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testGetRemoteInvoiceIntoArrayAsCreditNote1() |
27
|
|
|
{ |
28
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-creditnote1.xml'; |
29
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
30
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
31
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
32
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
33
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
34
|
|
|
'Comments' => false, |
35
|
|
|
'SchemaLocation' => false, |
36
|
|
|
]); |
37
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample1() |
41
|
|
|
{ |
42
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example1.xml'; |
43
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
44
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
45
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
46
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
47
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
48
|
|
|
'Comments' => false, |
49
|
|
|
'SchemaLocation' => true, |
50
|
|
|
]); |
51
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample2() |
55
|
|
|
{ |
56
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example2.xml'; |
57
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
58
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
59
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
60
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
61
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
62
|
|
|
'Comments' => false, |
63
|
|
|
'SchemaLocation' => true, |
64
|
|
|
]); |
65
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample3() |
69
|
|
|
{ |
70
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example3.xml'; |
71
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
72
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
73
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
74
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
75
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
76
|
|
|
'Comments' => false, |
77
|
|
|
'SchemaLocation' => true, |
78
|
|
|
]); |
79
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample4() |
83
|
|
|
{ |
84
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example4.xml'; |
85
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
86
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
87
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
88
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
89
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
90
|
|
|
'Comments' => false, |
91
|
|
|
'SchemaLocation' => true, |
92
|
|
|
]); |
93
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample5() |
97
|
|
|
{ |
98
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example5.xml'; |
99
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
100
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
101
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
102
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
103
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
104
|
|
|
'Comments' => false, |
105
|
|
|
'SchemaLocation' => true, |
106
|
|
|
]); |
107
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample6() |
111
|
|
|
{ |
112
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example6.xml'; |
113
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
114
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
115
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
116
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
117
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
118
|
|
|
'Comments' => false, |
119
|
|
|
'SchemaLocation' => true, |
120
|
|
|
]); |
121
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample7() |
125
|
|
|
{ |
126
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example7.xml'; |
127
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
128
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
129
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
130
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
131
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
132
|
|
|
'Comments' => false, |
133
|
|
|
'SchemaLocation' => true, |
134
|
|
|
]); |
135
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample8() |
139
|
|
|
{ |
140
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example8.xml'; |
141
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
142
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
143
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
144
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
145
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
146
|
|
|
'Comments' => false, |
147
|
|
|
'SchemaLocation' => true, |
148
|
|
|
]); |
149
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample9() |
153
|
|
|
{ |
154
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example9.xml'; |
155
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
156
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
157
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
158
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
159
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
160
|
|
|
'Comments' => false, |
161
|
|
|
'SchemaLocation' => true, |
162
|
|
|
]); |
163
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample9WithComments() |
167
|
|
|
{ |
168
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example9.xml'; |
169
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
170
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
171
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
172
|
|
|
$strTargetFile = __DIR__ . '/' . str_replace('.xml', '_withComments.xml', basename($url)); |
173
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
174
|
|
|
'Comments' => true, |
175
|
|
|
'SchemaLocation' => true, |
176
|
|
|
]); |
177
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function testGetLocalCreditNoteIntoArray() |
181
|
|
|
{ |
182
|
|
|
$strFile = __DIR__ . '/Romanian/creditNote_ex.xml'; |
183
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
184
|
|
|
$arrayData = $classRead->readElectronicInvoice($strFile); |
185
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
186
|
|
|
$strTargetFile = __DIR__ . '/' . basename($strFile); |
187
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
188
|
|
|
'Comments' => false, |
189
|
|
|
'Ident' => 2, |
190
|
|
|
'SchemaLocation' => false, |
191
|
|
|
]); |
192
|
|
|
$this->assertXmlFileEqualsXmlFile($strFile, $strTargetFile); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function testGetLocalInvoiceIntoArray() |
196
|
|
|
{ |
197
|
|
|
$strFile = __DIR__ . '/Romanian/eInvoice_ex.xml'; |
198
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
199
|
|
|
$arrayData = $classRead->readElectronicInvoice($strFile); |
200
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
201
|
|
|
$strTargetFile = __DIR__ . '/' . basename($strFile); |
202
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
203
|
|
|
'Comments' => false, |
204
|
|
|
'Ident' => 2, |
205
|
|
|
'SchemaLocation' => false, |
206
|
|
|
]); |
207
|
|
|
$this->assertXmlFileEqualsXmlFile($strFile, $strTargetFile); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function tearDown(): void |
211
|
|
|
{ |
212
|
|
|
$arrayFiles = new RecursiveDirectoryIterator(__DIR__, FilesystemIterator::SKIP_DOTS); |
213
|
|
|
foreach ($arrayFiles as $strFile) { |
214
|
|
|
if ($strFile->isFile() && ($strFile->getExtension() === 'xml')) { |
215
|
|
|
unlink($strFile->getRealPath()); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|