Passed
Push — main ( 1b869f...fb126e )
by Daniel
02:10
created

testGetRemoteInvoiceIntoArrayAsExample4()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
eloc 6
c 2
b 0
f 2
nc 1
nop 0
dl 0
loc 8
rs 10
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
        $classWrite->writeElectronicInvoice(self::LOCAL_RESULT_FILE, $arrayData, false, false);
33
        $this->assertXmlFileEqualsXmlFile($url, self::LOCAL_RESULT_FILE);
34
    }
35
36
    public function testGetRemoteInvoiceIntoArrayAsExample1()
37
    {
38
        $url        = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example1.xml';
39
        $classRead  = new \danielgp\efactura\ElectornicInvoiceRead();
40
        $arrayData  = $classRead->readElectronicInvoice($url);
41
        $classWrite = new \danielgp\efactura\ElectornicInvoiceWrite();
42
        $classWrite->writeElectronicInvoice(self::LOCAL_RESULT_FILE, $arrayData, false, true);
43
        $this->assertXmlFileEqualsXmlFile($url, self::LOCAL_RESULT_FILE);
44
    }
45
46
    public function testGetRemoteInvoiceIntoArrayAsExample2()
47
    {
48
        $this->markTestSkipped('Full logic not yest implemented... WIP');
49
        $url        = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example2.xml';
50
        $classRead  = new \danielgp\efactura\ElectornicInvoiceRead();
51
        $arrayData  = $classRead->readElectronicInvoice($url);
52
        $classWrite = new \danielgp\efactura\ElectornicInvoiceWrite();
53
        $classWrite->writeElectronicInvoice(self::LOCAL_RESULT_FILE, $arrayData, false, true);
54
        $this->assertXmlFileEqualsXmlFile($url, self::LOCAL_RESULT_FILE);
55
    }
56
57
    public function testGetRemoteInvoiceIntoArrayAsExample3()
58
    {
59
        $url        = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example3.xml';
60
        $classRead  = new \danielgp\efactura\ElectornicInvoiceRead();
61
        $arrayData  = $classRead->readElectronicInvoice($url);
62
        $classWrite = new \danielgp\efactura\ElectornicInvoiceWrite();
63
        $classWrite->writeElectronicInvoice(self::LOCAL_RESULT_FILE, $arrayData, false, true);
64
        $this->assertXmlFileEqualsXmlFile($url, self::LOCAL_RESULT_FILE);
65
    }
66
67
    public function testGetRemoteInvoiceIntoArrayAsExample4()
68
    {
69
        $url        = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example4.xml';
70
        $classRead  = new \danielgp\efactura\ElectornicInvoiceRead();
71
        $arrayData  = $classRead->readElectronicInvoice($url);
72
        $classWrite = new \danielgp\efactura\ElectornicInvoiceWrite();
73
        $classWrite->writeElectronicInvoice(self::LOCAL_RESULT_FILE, $arrayData, false, true);
74
        $this->assertXmlFileEqualsXmlFile($url, self::LOCAL_RESULT_FILE);
75
    }
76
77
    public function testGetRemoteInvoiceIntoArrayAsExample6()
78
    {
79
        $url        = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example6.xml';
80
        $classRead  = new \danielgp\efactura\ElectornicInvoiceRead();
81
        $arrayData  = $classRead->readElectronicInvoice($url);
82
        $classWrite = new \danielgp\efactura\ElectornicInvoiceWrite();
83
        $classWrite->writeElectronicInvoice(self::LOCAL_RESULT_FILE, $arrayData, false, true);
84
        $this->assertXmlFileEqualsXmlFile($url, self::LOCAL_RESULT_FILE);
85
    }
86
87
    public function testGetRemoteInvoiceIntoArrayAsExample7()
88
    {
89
        $url        = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example7.xml';
90
        $classRead  = new \danielgp\efactura\ElectornicInvoiceRead();
91
        $arrayData  = $classRead->readElectronicInvoice($url);
92
        $classWrite = new \danielgp\efactura\ElectornicInvoiceWrite();
93
        $classWrite->writeElectronicInvoice(self::LOCAL_RESULT_FILE, $arrayData, false, true);
94
        $this->assertXmlFileEqualsXmlFile($url, self::LOCAL_RESULT_FILE);
95
    }
96
97
    public function testGetRemoteInvoiceIntoArrayAsExample8()
98
    {
99
        $url        = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example8.xml';
100
        $classRead  = new \danielgp\efactura\ElectornicInvoiceRead();
101
        $arrayData  = $classRead->readElectronicInvoice($url);
102
        $classWrite = new \danielgp\efactura\ElectornicInvoiceWrite();
103
        $classWrite->writeElectronicInvoice(self::LOCAL_RESULT_FILE, $arrayData, false, true);
104
        $this->assertXmlFileEqualsXmlFile($url, self::LOCAL_RESULT_FILE);
105
    }
106
107
    public function testGetRemoteInvoiceIntoArrayAsExample9()
108
    {
109
        $url        = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example9.xml';
110
        $classRead  = new \danielgp\efactura\ElectornicInvoiceRead();
111
        $arrayData  = $classRead->readElectronicInvoice($url);
112
        $classWrite = new \danielgp\efactura\ElectornicInvoiceWrite();
113
        $classWrite->writeElectronicInvoice(self::LOCAL_RESULT_FILE, $arrayData, false, true);
114
        $this->assertXmlFileEqualsXmlFile($url, self::LOCAL_RESULT_FILE);
115
    }
116
117
    public function tearDown(): void
118
    {
119
        unlink(self::LOCAL_RESULT_FILE);
120
    }
121
}
122