Passed
Push — main ( bf08fb...375d1e )
by Daniel
02:06
created

testGetLocalJsonInvoiceIntoXmlWithDefaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 16
rs 9.8666
c 1
b 0
f 0
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';
0 ignored issues
show
Bug introduced by
Are you sure pathinfo($url, PATHINFO_FILENAME) of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        $strTargetFile = __DIR__ . '/' . /** @scrutinizer ignore-type */ pathinfo($url, PATHINFO_FILENAME) . '.xml';
Loading history...
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';
0 ignored issues
show
Bug introduced by
Are you sure pathinfo($url, PATHINFO_FILENAME) of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        $strTargetFile = __DIR__ . '/' . /** @scrutinizer ignore-type */ pathinfo($url, PATHINFO_FILENAME) . '_raw.xml';
Loading history...
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