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
|
|
|
|
18
|
|
|
public function testReadRemoteXml() |
19
|
|
|
{ |
20
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example1.xml'; |
21
|
|
|
$xmlContent = file_get_contents($url); |
22
|
|
|
$this->assertNotEmpty($xmlContent); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample1() |
26
|
|
|
{ |
27
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example1.xml'; |
28
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
29
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
30
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
31
|
|
|
$strFileToWrite = __DIR__ . '/restulWrite.xml'; |
32
|
|
|
$classWrite->writeElectronicInvoice($strFileToWrite, $arrayData, false, true); |
33
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strFileToWrite); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample4() |
37
|
|
|
{ |
38
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example4.xml'; |
39
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
40
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
41
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
42
|
|
|
$strFileToWrite = __DIR__ . '/restulWrite.xml'; |
43
|
|
|
$classWrite->writeElectronicInvoice($strFileToWrite, $arrayData, false, true); |
44
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strFileToWrite); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample8() |
48
|
|
|
{ |
49
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example8.xml'; |
50
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
51
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
52
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
53
|
|
|
$strFileToWrite = __DIR__ . '/restulWrite.xml'; |
54
|
|
|
$classWrite->writeElectronicInvoice($strFileToWrite, $arrayData, false, true); |
55
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strFileToWrite); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testGetRemoteInvoiceIntoArrayAsExample9() |
59
|
|
|
{ |
60
|
|
|
$url = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example9.xml'; |
61
|
|
|
$classRead = new \danielgp\efactura\ElectornicInvoiceRead(); |
62
|
|
|
$arrayData = $classRead->readElectronicInvoice($url); |
63
|
|
|
$classWrite = new \danielgp\efactura\ElectornicInvoiceWrite(); |
64
|
|
|
$strFileToWrite = __DIR__ . '/restulWrite.xml'; |
65
|
|
|
$classWrite->writeElectronicInvoice($strFileToWrite, $arrayData, false, true); |
66
|
|
|
$this->assertXmlFileEqualsXmlFile($url, $strFileToWrite); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function tearDown(): void |
70
|
|
|
{ |
71
|
|
|
$strFileToWrite = __DIR__ . '/restulWrite.xml'; |
72
|
|
|
unlink($strFileToWrite); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|