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