From 4191150cbc21378c47995ea176e58fc31d013cad Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Mon, 12 Oct 2026 15:56:48 +0000 Subject: [PATCH] fix(nfse): preserve DpsData positional API when adding regApTribSN (#424) Append the optional Simples field instead of shifting existing constructor arguments; keep named callers and the E0162/E0166/E0175 serializer intact. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/Dto/DpsData.php | 16 ++++++++-------- tests/Unit/Xml/XmlBuilderTest.php | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Dto/DpsData.php b/src/Dto/DpsData.php index 590ca59..7130f13 100644 --- a/src/Dto/DpsData.php +++ b/src/Dto/DpsData.php @@ -117,14 +117,6 @@ public function __construct( /** Whether the provider opts into Simples Nacional. */ public int $opcaoSimplesNacional = 1, - /** - * Regime de apuração do Simples Nacional (regApTribSN). - * Required by E0166 for ME/EPP (opSimpNac=3), otherwise absent. - * 1: federal and ISS via SN; 2: federal SN, ISS outside SN; - * 3: federal and ISS outside SN. - */ - public ?int $regimeApuracaoSimplesNacional = null, - /** Regime especial de tributação. */ public int $regimeEspecialTributacao = 0, @@ -230,6 +222,14 @@ public function __construct( /** Optional municipal benefit identified by the official municipal parameter id. */ public ?MunicipalBenefitData $beneficioMunicipal = null, + + /** + * Regime de apuração do Simples Nacional (regApTribSN). + * Required by E0166 for ME/EPP (opSimpNac=3), otherwise absent. + * 1: federal and ISS via SN; 2: federal SN, ISS outside SN; + * 3: federal and ISS outside SN. + */ + public ?int $regimeApuracaoSimplesNacional = null, ) { } } diff --git a/tests/Unit/Xml/XmlBuilderTest.php b/tests/Unit/Xml/XmlBuilderTest.php index 300e849..2152e1b 100644 --- a/tests/Unit/Xml/XmlBuilderTest.php +++ b/tests/Unit/Xml/XmlBuilderTest.php @@ -50,6 +50,18 @@ public function testProviderMunicipalRegistrationRejectsOversizedValueBeforeXmlI $this->builder->buildDps($this->makeDps(prestadorInscricaoMunicipal: str_repeat('1', 16))); } + public function testExtendedDtoKeepsLegacyPositionalConstructorOrder(): void + { + $parameters = (new \ReflectionMethod(DpsData::class, '__construct'))->getParameters(); + $names = array_map(static fn (\ReflectionParameter $parameter): string => $parameter->getName(), $parameters); + + self::assertSame('regimeApuracaoSimplesNacional', $names[count($names) - 1]); + self::assertLessThan( + array_search('regimeApuracaoSimplesNacional', $names, true), + array_search('regimeEspecialTributacao', $names, true), + ); + } + public function testMeEppWithoutApurationIsRejectedBeforeXmlGeneration(): void { $this->expectException(\InvalidArgumentException::class);