Skip to content

Commit

Permalink
Version 2.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipxe13 committed Jul 18, 2018
2 parents d245d36 + 6ceeb4e commit cf9991c
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 31 deletions.
74 changes: 74 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: "{branch}-{build}"
build: false
platform: x64
clone_folder: c:\projects\project
clone_depth: 1

cache:
- C:\ProgramData\chocolatey\bin -> .appveyor.yml
- C:\ProgramData\chocolatey\lib -> .appveyor.yml
- C:\tools\php -> .appveyor.yml
- C:\tools\composer -> .appveyor.yml
- '%LOCALAPPDATA%\Composer\files -> composer.json'

## Build matrix for lowest and highest possible targets
environment:
matrix:
- php: 7.0
- php: 7.1
- php: 7.2

init:
- SET PATH=C:\Program Files\OpenSSL;c:\tools\php;C:\tools\composer;%PATH%
- SET COMPOSER_NO_INTERACTION=1
- SET ANSICON=121x90 (121x90)
- SET saxonb-path=C:\ProgramData\chocolatey\bin\SaxonHE\bin\Transform.exe

## Install PHP and composer, and run the appropriate composer command
install:
# php
- ps: |
# Check if installation is cached
if (!(Test-Path c:\tools\php)) {
appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
Get-ChildItem -Path c:\tools\php
cd c:\tools\php
copy php.ini-production php.ini
Add-Content php.ini "`n date.timezone=UTC"
Add-Content php.ini "`n extension_dir=ext"
Add-Content php.ini "`n memory_limit=1G"
Add-Content php.ini "`n extension=php_openssl.dll"
Add-Content php.ini "`n extension=php_mbstring.dll"
Add-Content php.ini "`n extension=php_fileinfo.dll"
Add-Content php.ini "`n extension=php_curl.dll"
Add-Content php.ini "`n extension=php_xsl.dll"
Add-Content php.ini "`n extension=php_soap.dll"
}
# composer
- ps: |
if (!(Test-Path C:\tools\composer)) {
New-Item -path c:\tools -name composer -itemtype directory
}
if (!(Test-Path c:\tools\composer\composer.phar)) {
appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar -Filename C:\tools\composer\composer.phar
Set-Content -path 'C:\tools\composer\composer.bat' -Value ('@php C:\tools\composer\composer.phar %*')
}
# saxonb
- ps: |
if (!(Test-Path C:\ProgramData\chocolatey\bin\SaxonHE\bin\Transform.exe)) {
appveyor-retry cinst --ignore-checksums -y saxonhe
}
# install composer dependences
- cd c:\projects\project
- appveyor-retry composer self-update --no-progress --no-interaction
- appveyor-retry composer install --no-progress --no-interaction --prefer-dist

## Run the actual test
test_script:
- cd c:\projects\project
- mkdir build
- vendor\bin\phplint
- vendor\bin\phpcs -sp src tests
- vendor\bin\php-cs-fixer fix --using-cache=no --dry-run --verbose
- vendor\bin\phpunit
- vendor\bin\phpstan.phar.bat --no-progress analyse --level max src tests
6 changes: 5 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=auto eol=lf
*.cer binary
*.pem binary
*.key binary
*.bin binary

# Do not put this files on a distribution package (by .gitignore)
/vendor export-ignore
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![Latest Version][badge-release]][release]
[![Software License][badge-license]][license]
[![Build Status][badge-build]][build]
[![AppVeyor Status][badge-appveyor]][appveyor]
[![Source Code][badge-documentation]][documentation]
[![Scrutinizer][badge-quality]][quality]
[![Coverage Status][badge-coverage]][coverage]
Expand Down Expand Up @@ -87,18 +88,20 @@ and licensed for use under the MIT License (MIT). Please see [LICENSE][] for mor
[release]: https://github.com/eclipxe13/CfdiUtils/releases
[license]: https://github.com/eclipxe13/CfdiUtils/blob/master/LICENSE
[build]: https://travis-ci.org/eclipxe13/CfdiUtils?branch=master
[appveyor]: https://ci.appveyor.com/project/eclipxe13/cfdiutils
[quality]: https://scrutinizer-ci.com/g/eclipxe13/CfdiUtils/
[sensiolabs]: https://insight.sensiolabs.com/projects/87975c73-2f3b-480a-8cce-e78b15986d7b
[coverage]: https://scrutinizer-ci.com/g/eclipxe13/CfdiUtils/code-structure/master/code-coverage
[downloads]: https://packagist.org/packages/eclipxe/CfdiUtils

[badge-source]: http://img.shields.io/badge/source-eclipxe13/CfdiUtils-blue.svg?style=flat-square
[badge-documentation]: https://img.shields.io/readthedocs/cfdiutils/stable.svg
[badge-source]: http://img.shields.io/badge/source-eclipxe13/CfdiUtils-blue.svg?logo=github&style=flat-square
[badge-documentation]: https://img.shields.io/readthedocs/cfdiutils/stable.svg?style=flat-square
[badge-gitter]: https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square
[badge-release]: https://img.shields.io/github/release/eclipxe13/CfdiUtils.svg?style=flat-square
[badge-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[badge-build]: https://img.shields.io/travis/eclipxe13/CfdiUtils/master.svg?style=flat-square
[badge-quality]: https://img.shields.io/scrutinizer/g/eclipxe13/CfdiUtils/master.svg?style=flat-square
[badge-build]: https://img.shields.io/travis/eclipxe13/CfdiUtils/master.svg?logo=travis&style=flat-square
[badge-appveyor]: https://img.shields.io/appveyor/ci/eclipxe13/cfdiutils/master.svg?logo=appveyor&style=flat-square
[badge-quality]: https://img.shields.io/scrutinizer/g/eclipxe13/CfdiUtils/master.svg?logo=scrutinizer&style=flat-square
[badge-sensiolabs]: https://insight.sensiolabs.com/projects/87975c73-2f3b-480a-8cce-e78b15986d7b/mini.png
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/eclipxe13/CfdiUtils/master.svg?style=flat-square
[badge-downloads]: https://img.shields.io/packagist/dt/eclipxe/CfdiUtils.svg?style=flat-square
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ext-openssl": "*",
"ext-soap": "*",
"eclipxe/xmlresourceretriever": "^1.2",
"eclipxe/xmlschemavalidator": "^2.0"
"eclipxe/xmlschemavalidator": "^2.0.1"
},
"suggest": {
"genkgo/xsl": "^0.5.20"
Expand Down
14 changes: 14 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
- Remove `trigger_error` on `\CfdiUtils\Elements\Cfdi33\Comprobante::getCfdiRelacionados` when called with arguments.


## Version 2.6.2 2018-07-17

- Dependence on <https://github.com/eclipxe13/XmlSchemaValidator> has been set to `^2.0.1`
to fix validation using XSD local repository on MS Windows.
- Improve docblocks in property traits
- Restore previous error handler on `ComprobanteGetCfdiRelacionadosTest`
- Make sure that input file on `PemPrivateKey` is not a directory and is readable
- On MS Windows send to `NUL` instead of `/dev/null`
- Convert from `UTF-8` to `ASCII//TRANSLIT` can add single quotes, remove it.
- Add [AppVeyor](https://ci.appveyor.com/project/eclipxe13/cfdiutils) continious integration
- Add documentation about developing this library on windows
- Allow to set `saxonb` path using environment variable `saxonb-path`


## Version 2.6.1 2018-07-16

- Fix order of `Impuestos` children (thanks @aldolinares):
Expand Down
128 changes: 128 additions & 0 deletions docs/contribuir/guia-windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Guía para trabajar en MS Windows

Microsoft windows no es el entorno de desarrollo primario, sin embargo aquí unos consejos
para poder desarrollar (código o documentación) en esta plataforma.

Recuerda consultar la [Guía del desarrollador](guia-desarrollador.md)
y la [Guía del documentador](guia-documentador.md) como primeros pasos.

## AppVeyor

[AppVeyor] es una plataforma de integración continua con sistema operativo MS Windows.
Esta librería es construida en esta plataforma para garantizar la compatibilidad.

Gracias a la integración hecha en 2018-07-17 se pudieron encontrar algunos bugs menores
y hacer las reparaciones necesarias, en especial en el paquete [XmlSchemaValidator].


## Chocolatey

La forma más conveniente de preparar un entorno de desarrollo dentro de MS Windows es
utilizar [Chocolatey]. Este es un gestor de paquetes (tipo `apt` o `yum`) que permite la
instalación y actualización de software de manera ágil.

Recuerda que para instalar, desinstalar o actualizar paquetes requieres privilegios administrativos.

Estos son algunos comandos útiles para la instalación de paquetería:

```shell
choco install -y git php saxonhe
```


## git

Para evitar problemas con git y los finales de línea, es importante que configures tu entorno
de desarrollo de la siguiente forma.
Al momento de que [AppVeyor] hace el clon del proyecto está trabajando de esta misma manera.

```shell
git config --global core.autocrlf input
```

> Referencias:
> * <https://help.github.com/articles/dealing-with-line-endings/>
> * <https://www.appveyor.com/docs/appveyor-yml/>

## Ejecución de pruebas locales

Para que puedas ejecutar los comandos que forman las pruebas del proyecto (lo "construyen") ejecuta:

```shell
:: verificar que se están compliendo las reglas de estilo
vendor\bin\phpcs -sp src tests
vendor\bin\php-cs-fixer fix --dry-run --verbose

:: hacer las correcciones de estilo de forma automática
vendor\bin\phpcbf -sp src tests
vendor\bin\php-cs-fixer fix --verbose


:: ejecutar las pruebas
vendor\bin\phpunit

:: ejecutar el analizador el analizador estático
vendor\bin\phpstan.phar.bat --no-progress analyse --level max src tests
```

Lamentablemente no se puede ejecutar `composer build` o alguno de los comandos personalizados
definidos `composer.json` porque no funcionan correctamente.


## SaxonB

En [chocolatey] no se encuentra el código de SaxonB pero sí el de SaxonHE.

El ejecutable se instala en `C:\ProgramData\chocolatey\bin\SaxonHE\bin\Transform.exe`
y es compatible con la clase `SaxonBCliBuilder`.
Si no lo tienes instalado no habrá problema, solamente los test relacionados se marcarán como saltados.
Si no quieres que se salten puedes instalar SaxonHE y configurar una variable de entorno con lo que
los test reconocerán el lugar donde está instalado y podrá ejecutar los tests:

```shell
:: definir la variable de entorno
SET saxonb-path=C:\ProgramData\chocolatey\bin\SaxonHE\bin\Transform.exe

:: mostrar el contenido de la variable de entorno
ECHO %saxonb-path%

:: ejecutar los tests
vendor\bin\phpunit
```


## Documentación

En teoría, si tienes instalado [nodejs] y [python] ya sea usando [chocolatey] o por algún instalador
deberías de poder ejecutar las herramientas de construcción de paquetes sin mayor complicación
siguiendo los pasos generales de la [Guía del documentador](guia-documentador.md).

```shell
:: instalar las dependencias de nodejs para markdownlint
npm install
:: revisar la sintaxis de markdown
node node_modules\markdownlint-cli\markdownlint.js *.md docs

:: instalar mkdocs usando chocolatey
choco install -y mkdocs mkdocs-material
:: construyendo los documentos
mkdocs build --strict --site-dir build\docs
:: sirviendo los documentos
mkdocs serve
```


## GNU/Linux en MS Windows

Con las últimas versiones de MS Windows es podible ejecutar en una máquina virtual interna
alguna versión de GNU/Linux como Ubuntu o SUSE. Si sigues este camino, solo ten en cuenta que,
aunque estés en un sistema operativo MS Windows en realidad los comandos se ejecutan en otra
*máquina virtual* por lo que las pruebas y comandos que ejecutes será como Linux, no como MS Windows.


[appveyor]: https://www.appveyor.com/
[chocolatey]: https://chocolatey.org/
[XmlSchemaValidator]: https://github.com/eclipxe13/XmlSchemaValidator
[nodejs]: https://nodejs.org/es/
[python]: https://www.python.org/
12 changes: 8 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![Latest Version][badge-release]][release]
[![Software License][badge-license]][license]
[![Build Status][badge-build]][build]
[![AppVeyor Status][badge-appveyor]][appveyor]
[![Source Code][badge-documentation]][documentation]
[![Scrutinizer][badge-quality]][quality]
[![Coverage Status][badge-coverage]][coverage]
Expand Down Expand Up @@ -69,6 +70,7 @@ Solo hay métodos específicos para CFDI 3.3.
- [Listado de tareas pendientes e ideas](TODO.md)
- [Guía de contribución para desarrolladores](contribuir/guia-desarrollador.md)
- [Guía de contribución para documentadores](contribuir/guia-documentador.md)
- [Guía de contribución para MS Windows](contribuir/guia-windows.md)
- Reportar un problema


Expand Down Expand Up @@ -96,18 +98,20 @@ Consulte el archivo [LICENSE][] para más información.
[release]: https://github.com/eclipxe13/CfdiUtils/releases
[license]: https://github.com/eclipxe13/CfdiUtils/blob/master/LICENSE
[build]: https://travis-ci.org/eclipxe13/CfdiUtils?branch=master
[appveyor]: https://ci.appveyor.com/project/eclipxe13/cfdiutils
[quality]: https://scrutinizer-ci.com/g/eclipxe13/CfdiUtils/
[sensiolabs]: https://insight.sensiolabs.com/projects/87975c73-2f3b-480a-8cce-e78b15986d7b
[coverage]: https://scrutinizer-ci.com/g/eclipxe13/CfdiUtils/code-structure/master/code-coverage
[downloads]: https://packagist.org/packages/eclipxe/CfdiUtils

[badge-source]: http://img.shields.io/badge/source-eclipxe13/CfdiUtils-blue.svg?style=flat-square
[badge-documentation]: https://img.shields.io/readthedocs/cfdiutils/stable.svg
[badge-source]: http://img.shields.io/badge/source-eclipxe13/CfdiUtils-blue.svg?logo=github&style=flat-square
[badge-documentation]: https://img.shields.io/readthedocs/cfdiutils/stable.svg?style=flat-square
[badge-gitter]: https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square
[badge-release]: https://img.shields.io/github/release/eclipxe13/CfdiUtils.svg?style=flat-square
[badge-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[badge-build]: https://img.shields.io/travis/eclipxe13/CfdiUtils/master.svg?style=flat-square
[badge-quality]: https://img.shields.io/scrutinizer/g/eclipxe13/CfdiUtils/master.svg?style=flat-square
[badge-build]: https://img.shields.io/travis/eclipxe13/CfdiUtils/master.svg?logo=travis&style=flat-square
[badge-appveyor]: https://img.shields.io/appveyor/ci/eclipxe13/cfdiutils/master.svg?logo=appveyor&style=flat-square
[badge-quality]: https://img.shields.io/scrutinizer/g/eclipxe13/CfdiUtils/master.svg?logo=scrutinizer&style=flat-square
[badge-sensiolabs]: https://insight.sensiolabs.com/projects/87975c73-2f3b-480a-8cce-e78b15986d7b/mini.png
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/eclipxe13/CfdiUtils/master.svg?style=flat-square
[badge-downloads]: https://img.shields.io/packagist/dt/eclipxe/CfdiUtils.svg?style=flat-square
2 changes: 1 addition & 1 deletion docs/validar/validacion-cfdi.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ escribir un `Assert` con el mismo código entonces el previo es sobre escrito.
/** @var \CfdiUtils\CfdiCreator33 $creator */
$asserts = $creator->validate();
foreach ($asserts as $assert) {
echo $assert, "\n";
echo $assert, PHP_EOL;
}
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pages:
- "Contribuir":
- contribuir/guia-desarrollador.md
- contribuir/guia-documentador.md
- contribuir/guia-windows.md
- "Acerca de":
- "To Do List": "TODO.md"
- "Changelog": "CHANGELOG.md"
Expand Down
4 changes: 3 additions & 1 deletion src/CfdiUtils/CadenaOrigen/SaxonbCliBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ public function setExecutablePath(string $executablePath)

public function createCommand(string $xmlFile, string $xsltLocation): string
{
// if is running on windows then use NUL instead of /dev/null
$devnull = (0 === stripos(PHP_OS, 'win')) ? 'NUL' : '/dev/null';
return implode(' ', [
escapeshellcmd($this->getExecutablePath()),
escapeshellarg('-s:' . $xmlFile),
escapeshellarg('-xsl:' . $xsltLocation),
escapeshellarg('-warnings:silent'), // default recover
'2>/dev/null',
"2>$devnull",
]);
}

Expand Down
6 changes: 3 additions & 3 deletions src/CfdiUtils/Certificado/Certificado.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(string $filename)
$this->assertFileExists($filename);
// read contents, cast to string to avoid FALSE
if ('' === $contents = (string) file_get_contents($filename)) {
throw new \UnexpectedValueException("Cannot read the certificate file $filename or is empty");
throw new \UnexpectedValueException("File $filename is empty");
}

// change to PEM format if it is not already
Expand Down Expand Up @@ -73,7 +73,7 @@ public function __construct(string $filename)
} elseif (isset($data['serialNumber'])) {
$serial->loadDecimal($data['serialNumber']);
} else {
throw new \RuntimeException('Cannot get serialNumberHex or serialNumber from certificate');
throw new \RuntimeException("Cannot get serialNumberHex or serialNumber from certificate file $filename");
}
$this->serial = $serial->asAscii();
$this->validFrom = $data['validFrom_time_t'];
Expand Down Expand Up @@ -187,7 +187,7 @@ public function verify(string $data, string $signature, int $algorithm = OPENSSL
*/
protected function assertFileExists(string $filename)
{
if (! file_exists($filename) || ! is_readable($filename)) {
if (! file_exists($filename) || ! is_readable($filename) || is_dir($filename)) {
throw new \UnexpectedValueException("File $filename does not exists or is not readable");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/CfdiUtils/PemPrivateKey/PemPrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(string $key)
if (0 === strpos($key, 'file://')) {
$contents = '';
$filename = substr($key, 7);
if ('' !== $filename && file_exists($filename)) {
if ('' !== $filename && file_exists($filename) && is_readable($filename) && ! is_dir($filename)) {
$contents = file_get_contents($filename);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,6 @@ private function compareNames(string $first, string $second): bool

private function castNombre(string $nombre): string
{
return str_replace([' ', '-', ',', '.', '#', '&'], '', iconv('UTF-8', 'ASCII//TRANSLIT', $nombre));
return str_replace([' ', '-', ',', '.', '#', '&', "'", '"'], '', iconv('UTF-8', 'ASCII//TRANSLIT', $nombre));
}
}
Loading

0 comments on commit cf9991c

Please sign in to comment.