From a3118fbe8695543c352752cfb3fe07675f314327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Gusm=C3=A3o?= Date: Mon, 15 Jul 2024 19:23:13 +0100 Subject: [PATCH 1/2] Convert show errors --- src/Convert.php | 2 +- src/Factories/Parser.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Convert.php b/src/Convert.php index 831ff091..d40d3cca 100755 --- a/src/Convert.php +++ b/src/Convert.php @@ -74,7 +74,7 @@ public function toXml(): array $parser = new Parser($version, $this->baselayout); try { $this->xmls[] = $parser->toXml($nota); - } catch (\Exception $e) { + } catch (\Throwable $e) { if ($errors = $parser->getErrors()) { throw new ParserException(implode(', ', $errors)); } else { diff --git a/src/Factories/Parser.php b/src/Factories/Parser.php index 61d00420..22f14634 100755 --- a/src/Factories/Parser.php +++ b/src/Factories/Parser.php @@ -141,7 +141,7 @@ public function toXml(array $nota): ?string */ public function getErrors(): array { - return $this->make->errors; + return $this->make->getErrors(); } /** From fc90773b4214d3f6a2bf5ae13337a1daaaf4e3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Gusm=C3=A3o?= Date: Wed, 17 Jul 2024 10:57:11 +0100 Subject: [PATCH 2/2] phpunit convert error --- tests/ConvertTest.php | 10 +++ tests/fixtures/txt/nfe_4.00_local_error.txt | 70 +++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/fixtures/txt/nfe_4.00_local_error.txt diff --git a/tests/ConvertTest.php b/tests/ConvertTest.php index dbdcc256..76be74c0 100644 --- a/tests/ConvertTest.php +++ b/tests/ConvertTest.php @@ -3,6 +3,7 @@ namespace NFePHP\NFe\Tests; use NFePHP\NFe\Convert; +use NFePHP\NFe\Exception\ParserException; use PHPUnit\Framework\TestCase; class ConvertTest extends TestCase @@ -30,6 +31,15 @@ public function test_convert() $this->assertInfoAdicional($nfe); } + public function test_convert_errors() + { + $this->expectException(ParserException::class); + $this->expectExceptionMessageMatches('/A chave informada está incorreta/'); + $txt = file_get_contents(__DIR__ . '/fixtures/txt/nfe_4.00_local_error.txt'); + $conv = new Convert($txt); + $conv->toXml(); + } + /** * @param \SimpleXMLElement $nfe * @return void diff --git a/tests/fixtures/txt/nfe_4.00_local_error.txt b/tests/fixtures/txt/nfe_4.00_local_error.txt new file mode 100644 index 00000000..0006016c --- /dev/null +++ b/tests/fixtures/txt/nfe_4.00_local_error.txt @@ -0,0 +1,70 @@ +NOTAFISCAL|1| +A|4.00|NFe3518082502833200010|| +B|35|00000501|VENDA MERC.SUB.TRIBUTARIA|55|1|502|2018-08-13T17:28:10-03:00|2018-08-14T09:00:00-03:00|1|1|3550308|1|1|8|1|1|0|3|0|0|3.2.1.1||| +C|GSMMY COMERCIO DE CHOCOLATES LTDA|GSMMY|140950881119||||3| +C02|25028332000105| +C05|RUA CAETEZAL|296||AGUA FRIA|3550308|SAO PAULO|SP|02334130||Brasil|1122813500| +E|SILVANA MARCONI - VL LEOPOLDINA|1|142304338112|||vilaleopoldina@munik.com.br| +E02|17812455000295| +E05|R SCHILLING|491||VILA LEOPOLDINA|3550308|SAO PAULO|SP|05302001|1058|BRASIL|1143053063| +H|3|| +I|11352|7897112913525|CX DE BOMBOM SORTIDO 105G - 11352|18069000|||5401|CX|10.0000|2.5300|25.30|7897112913525|CX|10.0000|2.5300|||||1||0|| +I05c|1700700||| +M|0.00| +N| +N03|0|10|3|25.30|18.00|4.55||||0|||42.27|18.00|3.06|||| +O|||0|999| +O07|50|0.12| +O10|25.30|0.00| +Q| +Q02|01|25.30|0.65|0.16| +S| +S02|01|25.30|3.00|0.76| +H|4|| +I|14169|SEM GTIN|BOLO MEL BRIGADEIRO 65G CELOFANE E FITA - 14169|19052090|||5401|UN|10.0000|1.1200|11.20|SEM GTIN|UN|10.0000|1.1200|||||1||0|| +I05c|1705600||| +M|0.00| +N| +N09|0|70|3|61.11|4.35|18.00|0.78||||0|||7.50|0.00|1.33|||||| +O|||0|999| +O08|53| +Q| +Q02|01|11.20|0.65|0.07| +S| +S02|01|11.20|3.00|0.34| +H|2|| +I|355|7897112903557|CX PAO DE MEL M/M 430 G - 355|19052090|||5401|CX|2.0000|11.2300|22.46|7897112903557|CX|2.0000|11.2300|||||1||0|| +I05c|1705600||| +M|0.00| +N| +N09|0|70|3|61.11|8.73|18.00|1.57||||0|||15.03|0.00|2.67|||||| +O|||0|999| +O08|53| +Q| +Q02|01|22.46|0.65|0.15| +S| +S02|01|22.46|3.00|0.67| +H|1|| +I|45|7897112900457|CX PAO DE MEL LEITE 430 G - 45|19052090|||5401|CX|4.0000|11.2300|44.92|7897112900457|CX|4.0000|11.2300|||||1||0|| +I05c|1705600||| +M|0.00| +N| +N09|0|70|3|61.11|17.46|18.00|3.14||||0|||30.07|0.00|5.33|||||| +O|||0|999| +O08|53| +Q| +Q02|01|44.92|0.65|0.29| +S| +S02|01|44.92|3.00|1.35| +W| +W02|55.84|10.04|0.00|0.00|94.87|12.39|0.00|0.00|103.88|0.00|0.00|0.00|0.00|0.12|0.00|0.67|3.12|0.00|116.39|0.00|0.00|0.00|0.00| +X|3| +X03|CARRO PROPRIO -MUNIK|111220540115|R CAITEZAL, 316|SAO PAULO|SP| +X04|47269568000257| +X26|1|VOLUME|MUNIK||4.230|4.230| +Y|| +Y02|502|116.39|0.00|116.39| +Y07|001|2018-08-13|116.39| +YA|0|01|116.39||00||0| +Z||BASE DO ICMS REDUZIDA EM 61,11 CF RICMS Pedido 000068| +