Skip to content

Commit

Permalink
Merge pull request #17 from eclipxe13/master
Browse files Browse the repository at this point in the history
Upgrade to PHP 7.3
  • Loading branch information
eclipxe13 authored May 2, 2020
2 parents 9438837 + 5100b0a commit a565fb1
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 79 deletions.
3 changes: 2 additions & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ declare(strict_types=1);

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/build/.php_cs.cache')
->setCacheFile(__DIR__ . '/build/php-cs-fixer.cache')
->setRules([
'@PSR2' => true,
'@PHP70Migration' => true,
'@PHP70Migration:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHP73Migration' => true,
// symfony
'class_attributes_separation' => true,
'whitespace_after_comma_in_array' => true,
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php

# php compatibility
php: ["7.2", "7.3", "7.4"]
php: ["7.3", "7.4"]

cache:
- directories:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ foreach ($metadataReader->metadata() as $metadata) {
### Acerca de la interfaz `WebClientInterface`

Para hacer esta librería compatible con diferentes formas de comunicación se utiliza una interfaz de cliente HTTP.
Tu *puedes* crear tu implementación para poderla utilizar.
*puedes* crear tu implementación para poderla utilizar.

Si lo prefieres -como en el ejemplo de uso- podrías instalar Guzzle `composer require guzzlehttp/guzzle` y usar la clase
[`GuzzleWebClient`](https://github.com/phpcfdi/sat-ws-descarga-masiva/blob/master/src/WebClient/GuzzleWebClient.php).
Expand All @@ -116,15 +116,15 @@ El servicio se compone de 4 partes:
3. Verificación: pregunta al SAT si ya tiene disponible la solicitud.
4. Descargar los paquetes emitidos por la solicitud.

La mejor manera de entenderlo es la siguiente, imagina que el servicio del SAT se compone de tres ventanillas con tres
Una forma burda de entenderlo es: imagina que el servicio del SAT se compone de tres ventanillas con tres
personas diferentes atendiendo cada una de estas ventanillas.

* En la primera vas y presentas una solicitud de información. Te firman de recibido, pero eso no significa que tu
información esté lista, solo que han recibido tu solicitud.

* En la segunda ventanilla preguntas por tu número de solicitud y te responden que aun no la tienen lista, regresas
después y te dicen que aun no la tienen hasta que finalmente te dicen que ya está lista, y te piden pasar a otra
ventanilla por las cajas con tu información.
* En la segunda ventanilla preguntas por tu número de solicitud y te responden que aún no tienen lista la solicitud,
regresas después y te dicen que aún no está lista, hasta que finalmente te dicen que ya está completada, y te piden
pasar a otra ventanilla por las cajas con tu información.

* En la última ventanilla llegas y pides cada una de las cajas, una a la vez, te las entregan y te las llevas.
Si perdiste tu caja y regresaste varios días después y pides la caja, puede que ya no esté disponible.
Expand All @@ -133,7 +133,7 @@ al funcionario del SAT y no te la da más.

* Todo esto sucede con un máximo de seguridad, cada vez que hablas con un funcionario te pide que le enseñes tu permiso
y si no lo tienes o ya está vencido (duran apenas unos minutos) te mandan con el de la entrada para que le demuestres
que eres tu y te extienda un nuevo permiso.
que eres y te extienda un nuevo permiso.

### Información oficial

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"chat": "https://discord.gg/aFGYXvX"
},
"require": {
"php": ">=7.2",
"php": ">=7.3",
"ext-openssl": "*",
"ext-dom": "*",
"ext-json": "*",
Expand All @@ -32,7 +32,7 @@
"require-dev": {
"guzzlehttp/guzzle": "^6.3",
"robrichards/xmlseclibs": "^3.0.4",
"phpunit/phpunit": "^8.0",
"phpunit/phpunit": "^9.1",
"squizlabs/php_codesniffer": "^3.0",
"friendsofphp/php-cs-fixer": "^2.4",
"phpstan/phpstan": "^0.12"
Expand Down
8 changes: 7 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ In summary, [SemVer](https://semver.org/) can be viewed as ` Breaking . Feature

**Version `0.x.x` doesn't have to apply any of the SemVer rules**

## Version 0.3.0 2020-05-01

- Se actualizan las dependencias `php: >=7.3` y `phpunit: ^9.1`.
- Se actualiza `php-cs-fixer` para usar `@PHP73Migration`.


## Version 0.2.6 2020-04-11

- Se actualizan los test para que usen el RFC `EKU9003173C9`.
- Se actualizan los tests para que usen el RFC `EKU9003173C9`.
- Se agrega un test para probar qué ocurre al usar un `CSD` en lugar de una `FIEL`.
- Se actualiza el proyecto para satisfacer `phpstan: ^0.12`.
- En Scrutinizer-CI se eliminan las dependencias de desarrollo que no son útiles para la generación del *code coverage*.
Expand Down
8 changes: 6 additions & 2 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# phpcfdi/sat-ws-descarga-masiva To Do List

- Poner la versión mínima de PHP a 7.3
- Generar excepciones del proyecto en lugar de excepciones genéricas

- Mover el script de consumo con credenciales válidas a su propio proyecto dependiente de este.

- Llevar el code coverage a 100% con test unitarios
2019-12-06: Cersion 0.2.4 92%
2020-05-01: Version 0.3.0 93%
2019-12-06: Version 0.2.4 92%
2019-09-23: Version 0.2.3 93%
2019-08-23: Current 93%
2019-08-09: Current 86%
2019-08-08: Current 84%

## Tareas resueltas

- Poner la versión mínima de PHP a 7.3
2020-05-01: Hecho!

- Traducir CHANGELOG.md a español
2019-12-06: Hecho!

Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./tests/bootstrap.php" colors="true" verbose="true" cacheResultFile="./build/phpunit.result.cache">
<testsuites>
<testsuite name="Default">
Expand Down
61 changes: 30 additions & 31 deletions src/Services/Authenticate/AuthenticateTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function createSoapRequestWithData(Fiel $fiel, DateTime $since, DateTime
$expires = $until->formatSat();
$toDigest = $this->nospaces(
<<<EOT
<u:Timestamp xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" u:Id="_0">
<u:Created>${created}</u:Created>
<u:Expires>${expires}</u:Expires>
</u:Timestamp>
EOT
<u:Timestamp xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" u:Id="_0">
<u:Created>${created}</u:Created>
<u:Expires>${expires}</u:Expires>
</u:Timestamp>
EOT
);
$digested = base64_encode(sha1($toDigest, true));
$signedInfoData = $this->createSignedInfoCanonicalExclusive($digested, '#_0');
Expand All @@ -52,37 +52,36 @@ public function createSoapRequestWithData(Fiel $fiel, DateTime $since, DateTime
$certificate = Helpers::cleanPemContents($fiel->getCertificatePemContents());

$xml = <<<EOT
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
<u:Timestamp u:Id="_0">
<u:Created>${created}</u:Created>
<u:Expires>${expires}</u:Expires>
</u:Timestamp>
<o:BinarySecurityToken u:Id="${uuid}" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">
${certificate}
</o:BinarySecurityToken>
${signatureData}
</o:Security>
</s:Header>
<s:Body>
<Autentica xmlns="http://DescargaMasivaTerceros.gob.mx"/>
</s:Body>
</s:Envelope>
EOT;
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
<u:Timestamp u:Id="_0">
<u:Created>${created}</u:Created>
<u:Expires>${expires}</u:Expires>
</u:Timestamp>
<o:BinarySecurityToken u:Id="${uuid}" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">
${certificate}
</o:BinarySecurityToken>
${signatureData}
</o:Security>
</s:Header>
<s:Body>
<Autentica xmlns="http://DescargaMasivaTerceros.gob.mx"/>
</s:Body>
</s:Envelope>
EOT;

return $this->nospaces($xml);
}

public function createKeyInfoSecurityToken(string $uuid): string
{
$xml = <<<EOT
<KeyInfo>
<o:SecurityTokenReference>
<o:Reference URI="#${uuid}" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
</o:SecurityTokenReference>
</KeyInfo>
EOT;
return $xml;
return <<<EOT
<KeyInfo>
<o:SecurityTokenReference>
<o:Reference URI="#${uuid}" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
</o:SecurityTokenReference>
</KeyInfo>
EOT;
}
}
10 changes: 5 additions & 5 deletions src/Services/Download/DownloadTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function createSoapRequestWithData(Fiel $fiel, string $rfc, string $packa
{
$toDigest = $this->nospaces(
<<<EOT
<des:PeticionDescargaMasivaTercerosEntrada xmlns:des="http://DescargaMasivaTerceros.sat.gob.mx">
<des:peticionDescarga IdPaquete="${packageId}" RfcSolicitante="${rfc}"></des:peticionDescarga>
</des:PeticionDescargaMasivaTercerosEntrada>
EOT
<des:PeticionDescargaMasivaTercerosEntrada xmlns:des="http://DescargaMasivaTerceros.sat.gob.mx">
<des:peticionDescarga IdPaquete="${packageId}" RfcSolicitante="${rfc}"></des:peticionDescarga>
</des:PeticionDescargaMasivaTercerosEntrada>
EOT
);

$digested = base64_encode(sha1($toDigest, true));
Expand All @@ -53,7 +53,7 @@ public function createSoapRequestWithData(Fiel $fiel, string $rfc, string $packa
</des:PeticionDescargaMasivaTercerosEntrada>
</s:Body>
</s:Envelope>
EOT;
EOT;
return $this->nospaces($xml);
}
}
10 changes: 5 additions & 5 deletions src/Services/Query/QueryTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public function createSoapRequestWithData(

$toDigest = $this->nospaces(
<<<EOT
<des:SolicitaDescarga xmlns:des="http://DescargaMasivaTerceros.sat.gob.mx">
<des:solicitud FechaFinal="${end}" FechaInicial="${start}" ${rfcKey}="${rfc}" RfcSolicitante="${rfc}" TipoSolicitud="${requestTypeValue}"></des:solicitud>
</des:SolicitaDescarga>
EOT
<des:SolicitaDescarga xmlns:des="http://DescargaMasivaTerceros.sat.gob.mx">
<des:solicitud FechaFinal="${end}" FechaInicial="${start}" ${rfcKey}="${rfc}" RfcSolicitante="${rfc}" TipoSolicitud="${requestTypeValue}"></des:solicitud>
</des:SolicitaDescarga>
EOT
);
$digested = base64_encode(sha1($toDigest, true));
$signedInfoData = $this->createSignedInfoCanonicalExclusive($digested);
Expand All @@ -77,7 +77,7 @@ public function createSoapRequestWithData(
</des:SolicitaDescarga>
</s:Body>
</s:Envelope>
EOT;
EOT;

return $this->nospaces($xml);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Services/Verify/VerifyTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public function createSoapRequestWithData(
): string {
$toDigest = $this->nospaces(
<<<EOT
<des:VerificaSolicitudDescarga xmlns:des="http://DescargaMasivaTerceros.sat.gob.mx">
<des:solicitud IdSolicitud="${requestId}" RfcSolicitante="${rfc}"></des:solicitud>
</des:VerificaSolicitudDescarga>
EOT
<des:VerificaSolicitudDescarga xmlns:des="http://DescargaMasivaTerceros.sat.gob.mx">
<des:solicitud IdSolicitud="${requestId}" RfcSolicitante="${rfc}"></des:solicitud>
</des:VerificaSolicitudDescarga>
EOT
);
$digested = base64_encode(sha1($toDigest, true));
$signedInfoData = $this->createSignedInfoCanonicalExclusive($digested);
Expand All @@ -67,7 +67,7 @@ public function createSoapRequestWithData(
</des:VerificaSolicitudDescarga>
</s:Body>
</s:Envelope>
EOT;
EOT;

return $this->nospaces($xml);
}
Expand Down
9 changes: 4 additions & 5 deletions src/Shared/InteractsXmlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function createSignedInfoCanonicalExclusive(string $digested, string $
<DigestValue>${digested}</DigestValue>
</Reference>
</SignedInfo>
EOT;
EOT;
return $this->nospaces($xml);
}

Expand All @@ -174,20 +174,19 @@ protected function createKeyInfoData(Fiel $fiel): string
<X509Certificate>${certificate}</X509Certificate>
</X509Data>
</KeyInfo>
EOT;
EOT;
return $xml;
}

protected function createSignatureData(string $signedInfo, string $signatureValue, string $keyInfo): string
{
$signedInfo = str_replace('<SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#">', '<SignedInfo>', $signedInfo);
$xml = <<<EOT
return <<<EOT
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
${signedInfo}
<SignatureValue>${signatureValue}</SignatureValue>
${keyInfo}
</Signature>
EOT;
return $xml;
EOT;
}
}
2 changes: 1 addition & 1 deletion tests/Scripts/CLI/Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function parseParameters(array $parameters): array
return ['matched' => $matches, 'unmatched' => $unmatched];
}

public function findArgumentByParameter(string $parameter): ? Argument
public function findArgumentByParameter(string $parameter): ?Argument
{
foreach ($this->arguments as $argument) {
if ($argument->matchParameter($parameter)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/PackageReader/CfdiPackageReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testReaderZipWhenTheContentValid(): void
$cfdiPackageReader = CfdiPackageReader::createFromContents($zipContents);
$temporaryFilename = $cfdiPackageReader->getFilename();
unset($cfdiPackageReader);
$this->assertFileNotExists(
$this->assertFileDoesNotExist(
$temporaryFilename,
'When creating a CfdiPackageReader from contents, once it is destroyed relative file must not exists'
);
Expand Down
24 changes: 12 additions & 12 deletions tests/Unit/Shared/InteractsXmlTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ class InteractsXmlTraitTest extends TestCase
public function testNoSpacesContents(): void
{
$source = <<<EOT
<root>
<foo a="1" b="2">foo</foo>
<bar>
<baz>
BAZZ
</baz>
</bar>
</root>
EOT;
<root>
<foo a="1" b="2">foo</foo>
<bar>
<baz>
BAZZ
</baz>
</bar>
</root>
EOT;

$expected = '<root><foo a="1" b="2">foo</foo><bar><baz>BAZZ</baz></bar></root>';
$specimen = new InteractsXmlTraitSpecimen();
Expand Down

0 comments on commit a565fb1

Please sign in to comment.