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\ElectronicInvoiceRead::class)] |
11
|
|
|
#[CoversClass(\danielgp\efactura\ElectronicInvoiceWrite::class)] |
12
|
|
|
final class ReadWriteTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
const LOCAL_UBL_EXAMPLES_PATH = __DIR__ . '/UBL_examples/'; |
15
|
|
|
|
16
|
|
|
public function testGetLocalInvoiceIntoArrayAsCreditNote1() |
17
|
|
|
{ |
18
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-creditnote1.xml'; |
19
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
20
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
21
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
22
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
23
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
24
|
|
|
'Comments' => false, |
25
|
|
|
'SchemaLocation' => false, |
26
|
|
|
]); |
27
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample1() |
31
|
|
|
{ |
32
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example1.xml'; |
33
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
34
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
35
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
36
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
37
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
38
|
|
|
'Comments' => false, |
39
|
|
|
'SchemaLocation' => true, |
40
|
|
|
]); |
41
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample2() |
45
|
|
|
{ |
46
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example2.xml'; |
47
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
48
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
49
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
50
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
51
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
52
|
|
|
'Comments' => false, |
53
|
|
|
'SchemaLocation' => true, |
54
|
|
|
]); |
55
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample3() |
59
|
|
|
{ |
60
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example3.xml'; |
61
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
62
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
63
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
64
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
65
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
66
|
|
|
'Comments' => false, |
67
|
|
|
'SchemaLocation' => true, |
68
|
|
|
]); |
69
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample4() |
73
|
|
|
{ |
74
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example4.xml'; |
75
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
76
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
77
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
78
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
79
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
80
|
|
|
'Comments' => false, |
81
|
|
|
'SchemaLocation' => true, |
82
|
|
|
]); |
83
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample5() |
87
|
|
|
{ |
88
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example5.xml'; |
89
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
90
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
91
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
92
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
93
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
94
|
|
|
'Comments' => false, |
95
|
|
|
'SchemaLocation' => true, |
96
|
|
|
]); |
97
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample6() |
101
|
|
|
{ |
102
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example6.xml'; |
103
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
104
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
105
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
106
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
107
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
108
|
|
|
'Comments' => false, |
109
|
|
|
'SchemaLocation' => true, |
110
|
|
|
]); |
111
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample7() |
115
|
|
|
{ |
116
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example7.xml'; |
117
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
118
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
119
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
120
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
121
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
122
|
|
|
'Comments' => false, |
123
|
|
|
'SchemaLocation' => true, |
124
|
|
|
]); |
125
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample8() |
129
|
|
|
{ |
130
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example8.xml'; |
131
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
132
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
133
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
134
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
135
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
136
|
|
|
'Comments' => false, |
137
|
|
|
'SchemaLocation' => true, |
138
|
|
|
]); |
139
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample9() |
143
|
|
|
{ |
144
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example9.xml'; |
145
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
146
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
147
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
148
|
|
|
$strTargetFile = __DIR__ . '/' . basename($url); |
149
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
150
|
|
|
'Comments' => false, |
151
|
|
|
'SchemaLocation' => true, |
152
|
|
|
]); |
153
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function testGetLocalInvoiceIntoArrayAsExample9WithComments() |
157
|
|
|
{ |
158
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'eInvoicing-EN16931/ubl-tc434-example9.xml'; |
159
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
160
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
161
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
162
|
|
|
$strTargetFile = __DIR__ . '/' . str_replace('.xml', '_withComments.xml', basename($url)); |
163
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
164
|
|
|
'Comments' => true, |
165
|
|
|
'SchemaLocation' => true, |
166
|
|
|
]); |
167
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strTargetFile); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function testGetLocalCreditNoteIntoArray() |
171
|
|
|
{ |
172
|
|
|
$strFile = self::LOCAL_UBL_EXAMPLES_PATH . 'Romanian/creditNote_ex.xml'; |
173
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
174
|
|
|
$arrayData = $classRead->readElectronicInvoice($strFile); |
175
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
176
|
|
|
$strTargetFile = __DIR__ . '/' . basename($strFile); |
177
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
178
|
|
|
'Comments' => false, |
179
|
|
|
'Ident' => 2, |
180
|
|
|
'SchemaLocation' => false, |
181
|
|
|
]); |
182
|
|
|
$this->assertXmlFileEqualsXmlFile($strFile, $strTargetFile); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function testGetLocalInvoiceIntoArray() |
186
|
|
|
{ |
187
|
|
|
$strFile = self::LOCAL_UBL_EXAMPLES_PATH . 'Romanian/eInvoice_ex.xml'; |
188
|
|
|
$classRead = new \danielgp\efactura\ElectronicInvoiceRead(); |
189
|
|
|
$arrayData = $classRead->readElectronicInvoice($strFile); |
190
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
191
|
|
|
$strTargetFile = __DIR__ . '/' . basename($strFile); |
192
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
193
|
|
|
'Comments' => false, |
194
|
|
|
'Ident' => 2, |
195
|
|
|
'SchemaLocation' => false, |
196
|
|
|
]); |
197
|
|
|
$this->assertXmlFileEqualsXmlFile($strFile, $strTargetFile); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function tearDown(): void |
201
|
|
|
{ |
202
|
|
|
$arrayFiles = new RecursiveDirectoryIterator(__DIR__, FilesystemIterator::SKIP_DOTS); |
203
|
|
|
foreach ($arrayFiles as $strFile) { |
204
|
|
|
if ($strFile->isFile() && ($strFile->getExtension() === 'xml')) { |
205
|
|
|
unlink($strFile->getRealPath()); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|