Skip to content

feat(xml): add tomador block and regEspTrib to XmlBuilder#7

Merged
vitormattos merged 2 commits intomainfrom
feat/xml-tomador
Mar 22, 2026
Merged

feat(xml): add tomador block and regEspTrib to XmlBuilder#7
vitormattos merged 2 commits intomainfrom
feat/xml-tomador

Conversation

@vitormattos
Copy link
Member

Summary

Extends XmlBuilder::buildDps() to include the tomador (buyer) block and optional regime especial de tributação, completing the DPS XML coverage for common NFS-e issuance scenarios.

Changes

src/Xml/XmlBuilder.php

  • buildToma() — new private helper that builds <toma> block:
    • 14-digit documentoTomador<CNPJ>...</CNPJ>
    • 11-digit documentoTomador<CPF>...</CPF>
    • nomeTomador mapped to <xNome> (XML-escaped)
    • <toma> block is omitted entirely when documentoTomador is empty (foreign buyers)
  • regEspTrib element appended to infDPS when regimeEspecialTributacao !== null

tests/Unit/Xml/XmlBuilderTest.php

5 new tests using DOMXPath for structural assertion:

  • testTomadorCnpjBlockIsIncludedWhenDocumentHas14Digits
  • testTomadorCpfBlockIsIncludedWhenDocumentHas11Digits
  • testTomadorBlockIsAbsentWhenDocumentoTomadorIsEmpty
  • testRegimeEspecialTributacaoIsIncludedWhenSet
  • testRegimeEspecialTributacaoIsAbsentWhenNull

makeDps() test helper extended with documentoTomador, nomeTomador, regimeEspecialTributacao params (all optional with safe defaults).

Test count: 27 → 32 unit tests

Gates

  • phpunit: 32/32 ✓
  • cs:fix: 0 files changed (after auto-fix) ✓
  • psalm: No errors found ✓

Signed-off-by: Vitor Mattos <vitor@php.rio>
Signed-off-by: Vitor Mattos <vitor@php.rio>
@vitormattos vitormattos merged commit 1701595 into main Mar 22, 2026
10 checks passed
@vitormattos vitormattos deleted the feat/xml-tomador branch March 22, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant