Skip to content

Commit

Permalink
Merge pull request #107 from eclipxe13/development
Browse files Browse the repository at this point in the history
Maintenance 2022-12-07
  • Loading branch information
eclipxe13 committed Dec 7, 2022
2 parents 500ec47 + f9f4d07 commit 61c64f1
Show file tree
Hide file tree
Showing 13 changed files with 397 additions and 200 deletions.
222 changes: 133 additions & 89 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,149 +9,193 @@ on:
schedule:
- cron: '0 16 * * 0' # sunday 16:00

# Actions
# shivammathur/setup-php@v2 - https://github.com/marketplace/actions/setup-php-action
# nosborn/github-action-markdown-cli@v1.1.1 https://github.com/marketplace/actions/markdownlint-cli
# Tiryoh/actions-mkdocs@v0 https://github.com/marketplace/actions/mkdocs-action

jobs:

# this job performs phpunit tests on linux, windows and all php supported versions
tests:
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-systems }}
runs-on: ${{ matrix.operating-systems }}
phpcs:
name: Code style (phpcs)
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2 # see https://github.com/marketplace/actions/setup-php-action
with:
php-version: '8.1'
coverage: none
tools: cs2pr, phpcs
env:
fail-fast: true
- name: Code style (phpcs)
run: phpcs -q --report=checkstyle src/ tests/ | cs2pr

php-cs-fixer:
name: Code style (php-cs-fixer)
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2 # see https://github.com/marketplace/actions/setup-php-action
with:
php-version: '8.1'
coverage: none
tools: cs2pr, php-cs-fixer
env:
fail-fast: true
- name: Code style (php-cs-fixer)
run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr

markdownlint:
name: Markdown style (markdownlint)
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Code style (markdownlint-cli)
uses: nosborn/github-action-markdown-cli@v3.2.0
with:
files: '*.md docs/'
config_file: '.markdownlint.json'

mkdocs:
name: Test docs building
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run mkdocs
uses: Tiryoh/actions-mkdocs@v0
with:
mkdocs_version: 'latest'
configfile: 'mkdocs.yml'

phpstan:
name: Code analysis (phpstan)
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer:v2, phpstan
env:
fail-fast: true
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist
- name: PHPStan
run: phpstan analyse --no-progress --verbose src/ tests/

tests-linux:
name: Test PHP ${{ matrix.php-versions }} on Linux
runs-on: "ubuntu-latest"
strategy:
matrix:
operating-systems: [ "ubuntu-latest", "windows-latest" ]
php-versions: [ '7.3', '7.4', '8.0', '8.1' ]

steps:
- name: Checkout
uses: actions/checkout@v3

with:
fetch-depth: 0 # required for scrutinizer
- name: Install libsaxonb-java on linux
if: matrix.operating-systems == 'ubuntu-latest'
run: |
sudo apt-get update -y -qq
sudo apt-get install -y -qq default-jre libsaxonb-java
- name: Install saxonhe on windows
if: matrix.operating-systems == 'windows-latest'
run: choco install --ignore-checksums --no-progress --yes saxonhe

# see https://github.com/marketplace/actions/setup-php-action
- name: Install dependencies running on nektos/act
if: github.actor == 'nektos/act'
run: sudo apt-get install -y -qq zstd
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: libxml, dom, xsl, simplexml, mbstring, openssl, soap, iconv, json, intl, fileinfo
coverage: none
coverage: xdebug
tools: composer:v2
env:
fail-fast: true

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install SAT XML resources
shell: bash
run: |
git clone --depth 1 https://github.com/phpcfdi/resources-sat-xml resources-sat-xml-cloned
mv resources-sat-xml-cloned/resources build/resources
rm -r -f resources-sat-xml-cloned
- name: Install project dependencies
run: |
composer remove squizlabs/php_codesniffer friendsofphp/php-cs-fixer phpstan/phpstan --dev --no-interaction --no-progress --no-update
composer upgrade --no-interaction --no-progress --prefer-dist
- name: Tests (phpunit) on linux
if: matrix.operating-systems == 'ubuntu-latest'
run: vendor/bin/phpunit --testdox --verbose

- name: Tests (phpunit) on windows
if: matrix.operating-systems == 'windows-latest'
run: vendor/bin/phpunit --testdox --verbose
env:
saxonb-path: 'C:\ProgramData\chocolatey\bin\SaxonHE\bin\Transform.exe'

# this job performs a full build (check style, testing with coverage, code analysis and build docs)
full-build:
name: Full build
runs-on: "ubuntu-latest"
run: vendor/bin/phpunit --testdox --verbose --coverage-clover=build/coverage-clover.xml
- name: Upload code coverage to scrutinizer
run: |
mkdir -p build/scrutinizer
composer require scrutinizer/ocular:dev-master --working-dir=build/scrutinizer --no-progress
php build/scrutinizer/vendor/bin/ocular code-coverage:upload -vvv --no-interaction --format=php-clover build/coverage-clover.xml
tests-windows:
name: Tests PHP ${{ matrix.php-versions }} on Windows
runs-on: "windows-latest"
strategy:
matrix:
php-versions: [ '7.3', '7.4', '8.0', '8.1' ]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

# see https://github.com/marketplace/actions/setup-php-action
- name: Install saxonhe
run: choco install --ignore-checksums --no-progress --yes saxonhe
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.0"
extensions: libxml, dom, xsl, simplexml, mbstring, openssl, soap, iconv, json, intl, fileinfo
coverage: xdebug
tools: composer:v2, cs2pr
php-version: ${{ matrix.php-versions }}
extensions: soap, intl, xsl, fileinfo
coverage: none
tools: composer:v2
env:
fail-fast: true

- name: Install libsaxonb-java on linux
if: matrix.operating-systems == 'ubuntu-latest'
run: |
sudo apt-get update -y -qq
sudo apt-get install -y -qq default-jre libsaxonb-java
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

shell: bash
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install SAT XML resources
run: bash tests/resource-sat-xml-download build/

shell: bash
run: |
git clone --depth 1 https://github.com/phpcfdi/resources-sat-xml resources-sat-xml-cloned
mv resources-sat-xml-cloned/resources build/resources
rm -r -f resources-sat-xml-cloned
- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist

# https://github.com/marketplace/actions/markdown-cli
- name: Code style (markdownlint-cli)
uses: nosborn/github-action-markdown-cli@v1.1.1
with:
files: '*.md docs/'
config_file: '.markdownlint.json'

- name: Code style (phpcs)
run: vendor/bin/phpcs -q --report=checkstyle src/ tests/ | cs2pr

- name: Code style (php-cs-fixer)
run: vendor/bin/php-cs-fixer fix --dry-run --format=checkstyle | cs2pr

- name: Tests (phpunit)
run: vendor/bin/phpunit --testdox --verbose --coverage-clover=build/coverage-clover.xml

- name: Code analysis (phpstan)
run: vendor/bin/phpstan analyse --no-progress --verbose src/ tests/

- name: Upload code coverage to scrutinizer
run: |
mkdir -p build/scrutinizer
composer require scrutinizer/ocular:dev-master --working-dir=build/scrutinizer --no-progress
php build/scrutinizer/vendor/bin/ocular code-coverage:upload -vvv --no-interaction --format=php-clover build/coverage-clover.xml
# see https://github.com/marketplace/actions/mkdocs-action
- name: Run mkdocs
uses: Tiryoh/actions-mkdocs@v0
with:
mkdocs_version: 'latest'
configfile: 'mkdocs.yml'
composer remove squizlabs/php_codesniffer friendsofphp/php-cs-fixer phpstan/phpstan --dev --no-interaction --no-progress --no-update
composer upgrade --no-interaction --no-progress --prefer-dist
- name: Tests (phpunit)
run: vendor/bin/phpunit --testdox --verbose
env:
saxonb-path: 'C:\ProgramData\chocolatey\bin\SaxonHE\bin\Transform.exe'
17 changes: 17 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@
- Merge methods from `\CfdiUtils\Nodes\NodeHasValueInterface` into `\CfdiUtils\Nodes\NodeInterface`.
- Remove deprecated constant `CfdiUtils\Retenciones\Retenciones::RET_NAMESPACE`.

## Version 2.23.4 2022-12-07

This is a maintenance release fo fix the continuous integration workflow and append pending development changes.

- Fix test `CertificadoTest::testConstructWithValidExample()` to allow quoted slashes on name.
- Add *phpdoc* to the method `Certificate::getCertificateName()`.
The value can contain quoted slashes `\/` depending on the OpenSSL version.
- Update script `tests/validate.php` to validate CFDI 3.3 or CFDI 4.0.
- Add return types to some methods:
- `Status::comparableValue` and `Status::__toString`.
- `Discoverer::discoverInFile`.
- Improve `TestCase::installCertificate()`: It doesn't depend on the certificate's file name to install correctly.
- Update GitHub build workflow:
- Update GH Workflows: Remove deprecated `::set-output` & `::save-state`.
- Split **full build** actions to individual jobs.
- Split Windows and Linux testing.

## Version 2.23.3 2022-08-11

Fix CFDI 4.0, must include `Comprobante/Impuestos/Traslados/Traslado@TipoFactor=Exento` when exists at least one
Expand Down
24 changes: 15 additions & 9 deletions src/CfdiUtils/Certificado/Certificado.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Certificado
*
* @param string $filename Allows filename or certificate contents (PEM or DER)
* @param OpenSSL|null $openSSL
* @throws \UnexpectedValueException when the certificate does not exists or is not readable
* @throws \UnexpectedValueException when the certificate does not exist or is not readable
* @throws \UnexpectedValueException when cannot read the certificate or is empty
* @throws \RuntimeException when cannot parse the certificate or is empty
* @throws \RuntimeException when cannot get serialNumberHex or serialNumber from certificate
Expand Down Expand Up @@ -100,7 +100,7 @@ private function extractPemCertificate(string $contents): string
{
$openssl = $this->getOpenSSL();
$decoded = @base64_decode($contents, true) ?: '';
if ('' !== $decoded && $contents === base64_encode($decoded)) { // is a one liner certificate
if ('' !== $decoded && $contents === base64_encode($decoded)) { // is a one-liner certificate
$doubleEncoded = $openssl->readPemContents($decoded)->certificate();
if ('' !== $doubleEncoded) {
return $doubleEncoded;
Expand Down Expand Up @@ -129,9 +129,9 @@ private function obtainPemCertificate(string $contents): string
*
* @return bool
*
* @throws \UnexpectedValueException if the file does not exists or is not readable
* @throws \UnexpectedValueException if the file does not exist or is not readable
* @throws \UnexpectedValueException if the file is not a PEM private key
* @throws \RuntimeException if cannot open the private key file
* @throws \RuntimeException if the private key file cannot be opened
*/
public function belongsTo(string $pemKeyFile, string $passPhrase = ''): bool
{
Expand Down Expand Up @@ -165,6 +165,12 @@ public function getRfc(): string
return $this->rfc;
}

/**
* Certificate name value as returned by openssl.
* In come cases (openssl version 3) it contains quoted slashes (\/)
*
* @return string
*/
public function getCertificateName(): string
{
return $this->certificateName;
Expand All @@ -180,7 +186,7 @@ public function getName(): string
}

/**
* Certificate serial number as ASCII, this data is in the format required by CFDI
* Return the certificate serial number ASCII formatted, this data is in the format required by CFDI
* @return string
*/
public function getSerial(): string
Expand Down Expand Up @@ -221,7 +227,7 @@ public function getPubkey(): string
}

/**
* Place where the certificate was when loaded, it might not exists on the file system
* Place where the certificate was when loaded, it might not exist on the file system
* @return string
*/
public function getFilename(): string
Expand Down Expand Up @@ -256,7 +262,7 @@ public function getPemContentsOneLine(): string
*
* @return bool
*
* @throws \RuntimeException if cannot open the public key from certificate
* @throws \RuntimeException if the public key on the certificate cannot be opened
* @throws \RuntimeException if openssl report an error
*/
public function verify(string $data, string $signature, int $algorithm = OPENSSL_ALGO_SHA256): bool
Expand All @@ -281,15 +287,15 @@ public function verify(string $data, string $signature, int $algorithm = OPENSSL

/**
* @param string $filename
* @throws \UnexpectedValueException when the file does not exists or is not readable
* @throws \UnexpectedValueException when the file does not exist or is not readable
* @return void
*/
protected function assertFileExists(string $filename)
{
$exists = false;
$previous = null;
try {
if (boolval(preg_match('/[[:cntrl:]]/', $filename))) {
if (preg_match('/[[:cntrl:]]/', $filename)) {
$filename = '(invalid file name)';
throw new \RuntimeException('The file name contains control characters, it might be a DER content');
}
Expand Down

0 comments on commit 61c64f1

Please sign in to comment.