|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
#[CoversClass(\danielgp\efactura\ElectronicInvoiceWrite::class)] |
|
9
|
|
|
final class WriteTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
const LOCAL_UBL_EXAMPLES_PATH = __DIR__ . '/UBL_examples/'; |
|
12
|
|
|
|
|
13
|
|
|
public function testGetLocalJsonInvoiceIntoXml() |
|
14
|
|
|
{ |
|
15
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'Romanian/Invoice.json'; |
|
16
|
|
|
$fileHandle = fopen($url, 'r'); |
|
17
|
|
|
$jsonData = fread($fileHandle, ((int) filesize($url))); |
|
18
|
|
|
fclose($fileHandle); |
|
19
|
|
|
$arrayData = json_decode($jsonData, true); |
|
20
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
|
21
|
|
|
$strTargetFile = __DIR__ . '/' . pathinfo($url)['filename'] . '.xml'; |
|
22
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
|
23
|
|
|
'Comments' => false, |
|
24
|
|
|
'SchemaLocation' => false, |
|
25
|
|
|
]); |
|
26
|
|
|
$this->assertXmlFileEqualsXmlFile(self::LOCAL_UBL_EXAMPLES_PATH |
|
27
|
|
|
. 'Romanian/eInvoice_ex.xml', $strTargetFile); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testGetLocalJsonInvoiceIntoXmlWithDefaults() |
|
31
|
|
|
{ |
|
32
|
|
|
// given file does not contain namespaces, as these elements are Optional and taken from default if not provided |
|
33
|
|
|
$url = self::LOCAL_UBL_EXAMPLES_PATH . 'Romanian/Invoice_Data.json'; |
|
34
|
|
|
$fileHandle = fopen($url, 'r'); |
|
35
|
|
|
$jsonData = fread($fileHandle, ((int) filesize($url))); |
|
36
|
|
|
fclose($fileHandle); |
|
37
|
|
|
$arrayData = json_decode($jsonData, true); |
|
38
|
|
|
$classWrite = new \danielgp\efactura\ElectronicInvoiceWrite(); |
|
39
|
|
|
$strTargetFile = __DIR__ . '/' . pathinfo($url)['filename'] . '_raw.xml'; |
|
40
|
|
|
$classWrite->writeElectronicInvoice($strTargetFile, $arrayData, [ |
|
41
|
|
|
'Comments' => false, |
|
42
|
|
|
'SchemaLocation' => false, |
|
43
|
|
|
]); |
|
44
|
|
|
$this->assertXmlFileNotEqualsXmlFile(self::LOCAL_UBL_EXAMPLES_PATH |
|
45
|
|
|
. 'Romanian/eInvoice_ex.xml', $strTargetFile); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function tearDown(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$arrayFiles = new RecursiveDirectoryIterator(__DIR__, FilesystemIterator::SKIP_DOTS); |
|
51
|
|
|
foreach ($arrayFiles as $strFile) { |
|
52
|
|
|
if ($strFile->isFile() && ($strFile->getExtension() === 'xml')) { |
|
53
|
|
|
unlink($strFile->getRealPath()); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|