| 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 |  |  |         $strTargetFile = __DIR__ . '/' . basename($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, false, false); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     public function testGetRemoteInvoiceIntoArrayAsExample1() | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         $url           = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example1.xml'; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         $classRead     = new \danielgp\efactura\ElectornicInvoiceRead(); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         $arrayData     = $classRead->readElectronicInvoice($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         $classWrite    = new \danielgp\efactura\ElectornicInvoiceWrite(); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $strTargetFile = __DIR__ . '/' . basename($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, false, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     public function testGetRemoteInvoiceIntoArrayAsExample2() | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         $this->markTestSkipped('Full logic not yest implemented... WIP'); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         $url           = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example2.xml'; | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         $classRead     = new \danielgp\efactura\ElectornicInvoiceRead(); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $arrayData     = $classRead->readElectronicInvoice($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         $classWrite    = new \danielgp\efactura\ElectornicInvoiceWrite(); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         $strTargetFile = __DIR__ . '/' . basename($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, false, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     public function testGetRemoteInvoiceIntoArrayAsExample3() | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $url           = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example3.xml'; | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         $classRead     = new \danielgp\efactura\ElectornicInvoiceRead(); | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $arrayData     = $classRead->readElectronicInvoice($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         $classWrite    = new \danielgp\efactura\ElectornicInvoiceWrite(); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $strTargetFile = __DIR__ . '/' . basename($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, false, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |     public function testGetRemoteInvoiceIntoArrayAsExample4() | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         $url           = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example4.xml'; | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |         $classRead     = new \danielgp\efactura\ElectornicInvoiceRead(); | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         $arrayData     = $classRead->readElectronicInvoice($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |         $classWrite    = new \danielgp\efactura\ElectornicInvoiceWrite(); | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |         $strTargetFile = __DIR__ . '/' . basename($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, false, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |     public function testGetRemoteInvoiceIntoArrayAsExample6() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |         $url           = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example6.xml'; | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |         $classRead     = new \danielgp\efactura\ElectornicInvoiceRead(); | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |         $arrayData     = $classRead->readElectronicInvoice($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |         $classWrite    = new \danielgp\efactura\ElectornicInvoiceWrite(); | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |         $strTargetFile = __DIR__ . '/' . basename($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, false, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |     public function testGetRemoteInvoiceIntoArrayAsExample7() | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |         $url           = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example7.xml'; | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |         $classRead     = new \danielgp\efactura\ElectornicInvoiceRead(); | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |         $arrayData     = $classRead->readElectronicInvoice($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |         $classWrite    = new \danielgp\efactura\ElectornicInvoiceWrite(); | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |         $strTargetFile = __DIR__ . '/' . basename($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, false, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |     public function testGetRemoteInvoiceIntoArrayAsExample8() | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |         $url           = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example8.xml'; | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |         $classRead     = new \danielgp\efactura\ElectornicInvoiceRead(); | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |         $arrayData     = $classRead->readElectronicInvoice($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |         $classWrite    = new \danielgp\efactura\ElectornicInvoiceWrite(); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |         $strTargetFile = __DIR__ . '/' . basename($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, false, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |     public function testGetRemoteInvoiceIntoArrayAsExample9() | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |         $url           = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example9.xml'; | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |         $classRead     = new \danielgp\efactura\ElectornicInvoiceRead(); | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |         $arrayData     = $classRead->readElectronicInvoice($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |         $classWrite    = new \danielgp\efactura\ElectornicInvoiceWrite(); | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |         $strTargetFile = __DIR__ . '/' . basename($url); | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, false, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |     public function testGetRemoteInvoiceIntoArrayAsExample9WithOutComments() | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |         $url           = self::REMOTE_UBL_EXAMPLES_PATH . 'ubl-tc434-example9.xml'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $classRead     = new \danielgp\efactura\ElectornicInvoiceRead(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         $arrayData     = $classRead->readElectronicInvoice($url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         $classWrite    = new \danielgp\efactura\ElectornicInvoiceWrite(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         $strTargetFile = __DIR__ . '/' . str_replace('.xml', '_withComments.xml', basename($url)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         $classWrite->writeElectronicInvoice($strTargetFile, $arrayData, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $this->assertXmlFileEqualsXmlFile($url, $strTargetFile); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     public function tearDown(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $arrayFiles = new RecursiveDirectoryIterator(__DIR__, FilesystemIterator::SKIP_DOTS); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         foreach ($arrayFiles as $strFile) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             if ($strFile->isFile() && ($strFile->getExtension() === 'xml')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                 unlink($strFile->getRealPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 147 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 148 |  |  |  |