From b5c0a465c30c45513a0f0d0c78a5bbd895828b9a Mon Sep 17 00:00:00 2001 From: HorstOeko Date: Fri, 8 Nov 2024 16:44:10 +0100 Subject: [PATCH] Allow save generated test xml to buildlogs --- .gitignore | 1 + tests/testcases/UblToCiiSimple2Test.php | 3 ++- tests/testcases/UblToCiiSimpleTest.php | 1 + tests/traits/HandlesXmlTests.php | 22 +++++++++++++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5e5f7c0..bfbf20a 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,7 @@ _backup* /build/pdepend/ /build/phpdox/ /build/phpdoc/ +/build/xmlresults/ /*.phar /composer.lock /examples/*.xml diff --git a/tests/testcases/UblToCiiSimple2Test.php b/tests/testcases/UblToCiiSimple2Test.php index b420d35..7309a70 100644 --- a/tests/testcases/UblToCiiSimple2Test.php +++ b/tests/testcases/UblToCiiSimple2Test.php @@ -14,6 +14,7 @@ public function testLoadAndConvert(): void { self::$document = XmlConverterUblToCii::fromFile(dirname(__FILE__) . "/../assets/ubl/2_ubl_simple.xml")->convert(); $this->assertNotNull(self::$document); + $this->assertNotFalse($this->saveFinalXmlToBuildResults('2_ubl_simple_as_cii.xml')); } public function testDocumentGeneral(): void @@ -232,7 +233,7 @@ public function testSellerTaxRepresentativeTradeParty(): void $this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTaxRepresentativeTradeParty/ram:Name', 0, 'Dick Panama'); $this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTaxRepresentativeTradeParty/ram:Description', 0); $this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTaxRepresentativeTradeParty/ram:SpecifiedLegalOrganization/ram:ID', 0); - $this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTaxRepresentativeTradeParty/ram:SpecifiedLegalOrganization/ram:TradingBusinessName', 0, 'Buyco'); + $this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTaxRepresentativeTradeParty/ram:SpecifiedLegalOrganization/ram:TradingBusinessName', 0); $this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTaxRepresentativeTradeParty/ram:SpecifiedLegalOrganization/ram:PostalTradeAddress/ram:PostcodeCode', 0); $this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTaxRepresentativeTradeParty/ram:SpecifiedLegalOrganization/ram:PostalTradeAddress/ram:LineOne', 0); $this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTaxRepresentativeTradeParty/ram:SpecifiedLegalOrganization/ram:PostalTradeAddress/ram:LineTwo', 0); diff --git a/tests/testcases/UblToCiiSimpleTest.php b/tests/testcases/UblToCiiSimpleTest.php index 07f2a34..d5d47c6 100644 --- a/tests/testcases/UblToCiiSimpleTest.php +++ b/tests/testcases/UblToCiiSimpleTest.php @@ -14,6 +14,7 @@ public function testLoadAndConvert(): void { self::$document = XmlConverterUblToCii::fromFile(dirname(__FILE__) . "/../assets/ubl/1_ubl_simple.xml")->convert(); $this->assertNotNull(self::$document); + $this->assertNotFalse($this->saveFinalXmlToBuildResults('1_ubl_simple_as_cii.xml')); } public function testDocumentGeneral(): void diff --git a/tests/traits/HandlesXmlTests.php b/tests/traits/HandlesXmlTests.php index efa81ab..cbd42b3 100644 --- a/tests/traits/HandlesXmlTests.php +++ b/tests/traits/HandlesXmlTests.php @@ -239,10 +239,30 @@ protected function assertXPathNotExistsWithIndex(string $xpath, int $index) } /** - * @covers \horstoeko\zugferd\ZugferdDocumentBuilder::writeFile + * Write debug file + * + * @return void */ public function debugWriteFile(): void { self::$document->saveXmlFile(getcwd() . "/myfile_dbg.xml"); } + + /** + * Save generated XML to buildlogs + * + * @param string $filename + * @return int|false + */ + public function saveFinalXmlToBuildResults(string $filename) + { + $buildDir = dirname(__FILE__) . '/../../build'; + $buildXmlResultDir = $buildDir . '/xmlresults'; + + if (!is_dir($buildXmlResultDir)) { + @mkdir($buildXmlResultDir); + } + + return self::$document->saveXmlFile($buildXmlResultDir . '/' . $filename); + } }