Skip to content

Commit 1d3f3c7

Browse files
authored
Merge pull request #26 from eclipxe13/version-1.3.4
Correcciones de ubicaciones de archivos XSD y limpieza de Addenda (versión 1.3.4)
2 parents 46b5e9d + 3433954 commit 1d3f3c7

File tree

10 files changed

+100
-21
lines changed

10 files changed

+100
-21
lines changed

.github/workflows/build.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ jobs:
9393
run: phpstan analyse --no-progress --verbose
9494

9595
tests:
96-
name: Tests on PHP ${{ matrix.php-versions }}
96+
name: Tests on PHP ${{ matrix.php-version }}
9797
runs-on: "ubuntu-latest"
9898
strategy:
9999
matrix:
100-
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
100+
php-version: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
101101
steps:
102102
- name: Checkout
103103
uses: actions/checkout@v4
104104
- name: Setup PHP
105105
uses: shivammathur/setup-php@v2
106106
with:
107-
php-version: ${{ matrix.php-versions }}
107+
php-version: ${{ matrix.php-version }}
108108
coverage: none
109109
tools: composer:v2
110110
env:

.github/workflows/coverage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
jobs:
1212

1313
tests-coverage:
14-
name: Tests on PHP 8.3 (code coverage)
14+
name: Create code coverage
1515
runs-on: "ubuntu-latest"
1616
steps:
1717
- name: Checkout

.phive/phars.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpcs" version="^3.10.1" installed="3.10.1" location="./tools/phpcs" copy="false"/>
4-
<phar name="phpcbf" version="^3.10.1" installed="3.10.1" location="./tools/phpcbf" copy="false"/>
5-
<phar name="php-cs-fixer" version="^3.59.3" installed="3.59.3" location="./tools/php-cs-fixer" copy="false"/>
6-
<phar name="phpstan" version="^1.11.5" installed="1.11.5" location="./tools/phpstan" copy="false"/>
7-
<phar name="composer-normalize" version="^2.43.0" installed="2.43.0" location="./tools/composer-normalize" copy="false"/>
3+
<phar name="phpcs" version="^3.10.3" installed="3.10.3" location="./tools/phpcs" copy="false"/>
4+
<phar name="phpcbf" version="^3.10.3" installed="3.10.3" location="./tools/phpcbf" copy="false"/>
5+
<phar name="php-cs-fixer" version="^3.64.0" installed="3.64.0" location="./tools/php-cs-fixer" copy="false"/>
6+
<phar name="phpstan" version="^1.12.6" installed="1.12.6" location="./tools/phpstan" copy="false"/>
7+
<phar name="composer-normalize" version="^2.44.0" installed="2.44.0" location="./tools/composer-normalize" copy="false"/>
88
</phive>

docs/CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ Utilizamos [Versionado Semántico 2.0.0](SEMVER.md).
88

99
Los cambios no liberados se integran a la rama principal, pero no requieren de la liberación de una nueva versión.
1010

11+
## Versión 1.3.4
12+
13+
Se hacen las siguientes correcciones:
14+
15+
- Se corrige la ubicación del XSD del complemento "Enajenaciones de acciones" para Retenciones e información de pagos.
16+
- Se corrige la el espacio de nombres del complemento "Pagos a extranjeros" para Retenciones e información de pagos.
17+
- El limpiador de *Addenda* incluye también los CFDI de Retenciones e información de pagos.
18+
19+
Se hacen los siguientes cambios al entorno de desarrollo:
20+
21+
- En el flujo de trabajo `build` en el trabajo `tests` se usa la variable `php-version` en singular.
22+
- En el flujo de trabajo `coverage` en el trabajo `test-coverage` se usa mejora el título.
23+
- Se actualizan las herramientas de desarrollo.
24+
1125
## Versión 1.3.3
1226

1327
- Se agrega *Complemento de Carta Porte 3.1* a la lista de espacio de nombres conocidos.

src/XmlDocumentCleaners/RemoveAddenda.php

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public function clean(DOMDocument $document): void
1616
{
1717
$this->removeAddendas($document, 'http://www.sat.gob.mx/cfd/3');
1818
$this->removeAddendas($document, 'http://www.sat.gob.mx/cfd/4');
19+
$this->removeAddendas($document, 'http://www.sat.gob.mx/esquemas/retencionpago/2');
20+
$this->removeAddendas($document, 'http://www.sat.gob.mx/esquemas/retencionpago/1');
1921
}
2022

2123
private function removeAddendas(DOMDocument $document, string $namespace): void

src/XmlDocumentCleaners/SetKnownSchemaLocations.php

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class SetKnownSchemaLocations implements XmlDocumentCleanerInterface
141141
'http://www.sat.gob.mx/esquemas/retencionpago/1/dividendos#1.0'
142142
=> 'http://www.sat.gob.mx/esquemas/retencionpago/1/dividendos/dividendos.xsd',
143143
'http://www.sat.gob.mx/esquemas/retencionpago/1/enajenaciondeacciones#1.0'
144+
=> 'http://www.sat.gob.mx/esquemas/retencionpago/1/enajenaciondeacciones/enajenaciondeacciones.xsd',
145+
'http://www.sat.gob.mx/esquemas/retencionpago/1/pagosaextranjeros#1.0'
144146
=> 'http://www.sat.gob.mx/esquemas/retencionpago/1/pagosaextranjeros/pagosaextranjeros.xsd',
145147
'http://www.sat.gob.mx/esquemas/retencionpago/1/fideicomisonoempresarial#1.0'
146148
=> 'http://www.sat.gob.mx/esquemas/retencionpago/1/fideicomisonoempresarial/fideicomisonoempresarial.xsd',

tests/Features/XmlDocumentCleaners/RemoveAddendaTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ public function providerCleanDocumentWithAddenda(): array
3333
</x:Comprobante>
3434
XML,
3535
],
36+
'RET 2.0' => [
37+
'http://www.sat.gob.mx/esquemas/retencionpago/2',
38+
<<<XML
39+
<x:Retenciones xmlns:x="http://www.sat.gob.mx/esquemas/retencionpago/2">
40+
<x:Addenda>
41+
<o:OtherData xmlns:o="http://tempuri.org/other" foo="bar" />
42+
</x:Addenda>
43+
</x:Retenciones>
44+
XML,
45+
],
46+
'RET 1.0' => [
47+
'http://www.sat.gob.mx/esquemas/retencionpago/1',
48+
<<<XML
49+
<x:Retenciones xmlns:x="http://www.sat.gob.mx/esquemas/retencionpago/1">
50+
<x:Addenda>
51+
<o:OtherData xmlns:o="http://tempuri.org/other" foo="bar" />
52+
</x:Addenda>
53+
</x:Retenciones>
54+
XML,
55+
],
3656
];
3757
}
3858

tests/Features/XmlDocumentCleaners/SetKnownSchemaLocationsTest.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
namespace PhpCfdi\CfdiCleaner\Tests\Features\XmlDocumentCleaners;
88

99
use PhpCfdi\CfdiCleaner\Tests\TestCase;
10+
use PhpCfdi\CfdiCleaner\Tests\Traits\UseSatNsRegistryTrait;
1011
use PhpCfdi\CfdiCleaner\XmlDocumentCleaners\SetKnownSchemaLocations;
1112

1213
final class SetKnownSchemaLocationsTest extends TestCase
1314
{
15+
use UseSatNsRegistryTrait;
16+
1417
public function testSetKnownSchemaLocations(): void
1518
{
1619
$document = $this->createDocument(<<<XML
@@ -82,28 +85,24 @@ public function testSetKnownSchemaLocationsWithUnknownNamespace(): void
8285
$this->assertEquals($expected, $document);
8386
}
8487

85-
/** @noinspection PhpUnhandledExceptionInspection */
8688
public function testKnowAllLocationsFromSatNsRegistry(): void
8789
{
88-
// obtain the list of known locations from phpcfdi/sat-ns-registry
89-
$satNsRegistryUrl = 'https://raw.githubusercontent.com/phpcfdi/sat-ns-registry/master/complementos_v1.json';
90-
/** @var array<array{namespace: ?string, version: ?string, xsd: ?string}> $registry */
91-
$registry = json_decode(file_get_contents($satNsRegistryUrl) ?: '[]', true, 512, JSON_THROW_ON_ERROR);
90+
$registry = $this->getSatNsRegistry();
9291

9392
// re-create the known list of namespace#version => xsd-location
9493
$expected = [];
9594
foreach ($registry as $entry) {
96-
$namespace = $entry['namespace'] ?? '';
97-
$version = $entry['version'] ?? '';
98-
$xsd = $entry['xsd'] ?? '';
95+
$namespace = $entry->namespace ?? '';
96+
$version = $entry->version ?? '';
97+
$xsd = $entry->xsd ?? '';
9998
if ($namespace && $xsd) {
10099
$expected[$namespace . '#' . $version] = $xsd;
101100
}
102101
}
103-
asort($expected);
102+
ksort($expected, SORT_STRING);
104103

105104
$knownLocations = SetKnownSchemaLocations::getKnownNamespaces();
106-
asort($knownLocations);
105+
ksort($knownLocations, SORT_STRING);
107106

108107
$this->assertSame(
109108
$expected,

tests/Features/XmlStringCleaners/RepairXmlNsSchemaLocationTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public function providerInputCases(): array
3434
<<< EOT
3535
<root foo="bar"
3636
xsi:schemaLocation="http://localhost/a http://localhost/a.xsd"
37-
xmlns:schemaLocation="foo bar">
37+
xmlns:schemaLocation="with line terminators
38+
">
3839
</root>
3940
EOT,
4041
],
@@ -46,7 +47,8 @@ public function providerInputCases(): array
4647
EOT,
4748
<<< EOT
4849
<root foo="bar"
49-
xmlns:schemaLocation="foo bar"
50+
xmlns:schemaLocation="with line terminators
51+
"
5052
xsi:schemaLocation="http://localhost/a http://localhost/a.xsd">
5153
</root>
5254
EOT,
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpCfdi\CfdiCleaner\Tests\Traits;
6+
7+
use RuntimeException;
8+
use Throwable;
9+
10+
trait UseSatNsRegistryTrait
11+
{
12+
/** @var array<object{namespace: ?string, prefix: ?string, version: ?string, xsd: ?string}>|null */
13+
private $satNsRegistry = null;
14+
15+
/** @return array<object{namespace: ?string, prefix: ?string, version: ?string, xsd: ?string}> */
16+
protected function getSatNsRegistry(): array
17+
{
18+
if (null === $this->satNsRegistry) {
19+
$this->satNsRegistry = $this->loadSatNsRegistry();
20+
}
21+
22+
return $this->satNsRegistry;
23+
}
24+
25+
/** @return array<object{namespace: ?string, prefix: ?string, version: ?string, xsd: ?string}> */
26+
protected function loadSatNsRegistry(): array
27+
{
28+
// obtain the list of known locations from phpcfdi/sat-ns-registry
29+
$satNsRegistryUrl = 'https://raw.githubusercontent.com/phpcfdi/sat-ns-registry/master/complementos_v1.json';
30+
try {
31+
/** @var array<object{namespace: ?string, prefix: ?string, version: ?string, xsd: ?string}> $registry */
32+
$registry = json_decode((string) file_get_contents($satNsRegistryUrl), false, 512, JSON_THROW_ON_ERROR);
33+
} catch (Throwable $exception) {
34+
$message = sprintf('Unable to load SAT Namespaces Registry from %s', $satNsRegistryUrl);
35+
throw new RuntimeException($message, 0, $exception);
36+
}
37+
38+
return $registry;
39+
}
40+
}

0 commit comments

Comments
 (0)