Skip to content

Commit

Permalink
Prepare 2.9.0
Browse files Browse the repository at this point in the history
- Fix windows compatibility
- Change internals namespace
  • Loading branch information
eclipxe13 committed Mar 16, 2019
2 parents 56ac531 + 6420177 commit 50cf317
Show file tree
Hide file tree
Showing 31 changed files with 310 additions and 164 deletions.
114 changes: 76 additions & 38 deletions .appveyor.yml
Expand Up @@ -9,7 +9,7 @@ cache:
- C:\ProgramData\chocolatey\lib -> .appveyor.yml
- C:\tools\php -> .appveyor.yml
- C:\tools\composer -> .appveyor.yml
- '%LOCALAPPDATA%\Composer\files -> composer.json'
- '%LOCALAPPDATA%\Composer\files -> .appveyor.yml'

## Build matrix for lowest and highest possible targets
environment:
Expand All @@ -19,60 +19,98 @@ environment:
- php: 7.2
- php: 7.3

matrix:
allow_failures:
- php: 7.0

init:
- SET PATH=C:\OpenSSL-v111-Win64\bin;c:\tools\php;C:\tools\composer;%PATH%
- SET PATH=c:\tools\php;C:\tools\composer;C:\OpenSSL-v111-Win64\bin;%PATH%
- SET COMPOSER_NO_INTERACTION=1
- SET ANSICON=121x90 (121x90)
- 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
## Check for openssl, install php using version environment, install
install:
# php
# check openssl exists and run from PATH
- openssl version
# php is not cached because this script change versions
- ps: |
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"
Write-Host "PHP build version: $Env:php"
# Get current version of php (if any)
$current_version = ""
if (Test-Path c:\tools\php\php.exe) {
[string]$current_version = php -r "printf('%s.%s.%s', PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION);"
Write-Host "PHP current version: $current_version"
} else {
Write-Host "PHP current version: (none)"
}
# Get latest available version for php environment variable
$php_install_version = (( `
choco search php --exact --all-versions -r `
| Select-String -Pattern $env:php `
| Sort-Object { [version]($_ -Split '\|' | Select-Object -Last 1) } -Descending `
| Select-Object -First 1 `
) -Replace '[php|]', '')
Write-Host "PHP available version: $php_install_version"
# Test if require installation (not installed or upgrade available)
if (! ($current_version -eq $php_install_version)) {
# uninstall if previous version exists
if (! ($current_version -eq "")) {
choco uninstall php --yes --force --ignore-package-exit-codes --ignore-autouninstaller-failure
}
# install php on C:\tools\php
appveyor-retry choco install --ignore-checksums --params='""/InstallDir:C:\tools\php""' `
php --version $php_install_version --yes
}
# setup c:\tools\php\php.ini
if (Test-Path c:\tools\php\php.ini-production) {
Copy-Item -Path c:\tools\php\php.ini-production -Destination c:\tools\php\php.ini
Add-Content c:\tools\php\php.ini "`
`n; PHP Custom config `
date.timezone=UTC `
extension_dir=ext `
memory_limit=1G `
extension=php_openssl `
extension=php_mbstring `
extension=php_fileinfo `
extension=php_curl `
extension=php_xsl `
extension=php_soap `
"
}
# show contents of extension directory
Get-ChildItem -Path c:\tools\php\ext
# show php information
php -i
# 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)) {
if (! (Test-Path c:\tools\composer\composer.phar)) {
New-Item -ItemType Directory -Force -Path c:\tools\composer
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 %*')
Set-Content -Path 'C:\tools\composer\composer.bat' -Value ('@php C:\tools\composer\composer.phar %*')
} else {
appveyor-retry composer self-update --stable --no-progress --no-interaction --ansi
}
composer --version
# saxonb
- ps: |
if (!(Test-Path C:\ProgramData\chocolatey\bin\SaxonHE\bin\Transform.exe)) {
appveyor-retry cinst --ignore-checksums -y saxonhe
if (! (Test-Path ${Env:saxonb-path})) {
appveyor-retry choco install --ignore-checksums --yes saxonhe
}
# install composer dependences
# install project dependences and list available tools
- cd c:\projects\project
- appveyor-retry composer self-update --no-progress --no-interaction
- appveyor-retry composer install --no-progress --no-interaction --prefer-dist
- appveyor-retry composer install --prefer-dist --no-progress --no-interaction --ansi
- dir vendor\bin

## 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 --testdox --verbose
- vendor\bin\phpstan.phar.bat --no-progress analyse --level max src tests
- vendor\bin\phplint.bat
- vendor\bin\phpcs.bat -sp src tests
- vendor\bin\php-cs-fixer.bat fix --dry-run --verbose
- if "%php%"=="7.0" vendor\bin\phpunit.bat --verbose
- if not "%php%"=="7.0" vendor\bin\phpunit.bat --testdox --verbose
- if "%php%"=="7.3" vendor\bin\phpstan.phar.bat --no-progress analyse --level max src tests
12 changes: 12 additions & 0 deletions .editorconfig
@@ -0,0 +1,12 @@
# top-most EditorConfig file
root = true

[*]
indent_style: space
indent_size: 4
end_of_line: lf

[**.{php,md,xml,yml,json,dist}]
charset = utf-8
trim_trailing_whitespace: true
insert_final_newline = true
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -7,6 +7,10 @@ php:
- 7.2
- 7.3

branches:
except:
- appveyor # exclude appveyor branch

before_install:
- nvm install 8

Expand Down
9 changes: 4 additions & 5 deletions docs/CHANGELOG.md
Expand Up @@ -20,7 +20,7 @@
- Remove static `CfdiUtils\PemPrivateKey\PemPrivateKey::isPEM` method.


## Version 2.9.0 2019-03-13
## Version 2.9.0 2019-03-15

- Add `CfdiUtils\OpenSSL`, a library to help working with `openssl` commands and CER, KEY and PEM files.
Fully tested and [documented](https://cfdiutils.readthedocs.io/es/utilerias/openssl/).
Expand Down Expand Up @@ -50,10 +50,9 @@
- Internal: Add `ShellExec` class that works around with `symfony/process` component. Also added:
- `ShellExecResponse`: contains the response of ShellExec::run().
- `ShellExecTemplate`: basic command array creation from a string template.
- CI: Allow AppVeyor to fail when testing
- PHPUnit ends with exit code 2, don't know exactly why.
- Add `--testdox` and `--verbose` to command line.
- CI: Change Travis build version to PHP 7.3, only run `phpstan` on build version.
- Internal: Move internal to `CfdiUtils\Internal`. Check `@internal` annotation on all elements. Add README.md
- CI: AppVeyor complete refactory, now uses correctly caches and upgrade php if required.
- CI: Only run `phpstan` on PHP 7.3.
- Dev: Add --testdox --verbose and --stop-on-failure on composer dev:build.


Expand Down
6 changes: 3 additions & 3 deletions src/CfdiUtils/CadenaOrigen/SaxonbCliBuilder.php
@@ -1,8 +1,8 @@
<?php
namespace CfdiUtils\CadenaOrigen;

use CfdiUtils\Utils\Internal\ShellExec;
use CfdiUtils\Utils\Internal\TemporaryFile;
use CfdiUtils\Internals\ShellExec;
use CfdiUtils\Internals\TemporaryFile;

class SaxonbCliBuilder extends AbstractXsltBuilder
{
Expand Down Expand Up @@ -39,7 +39,7 @@ 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';
$devnull = ('\\' === DIRECTORY_SEPARATOR) ? 'NUL' : '/dev/null';
return implode(' ', [
escapeshellarg($this->getExecutablePath()),
escapeshellarg('-s:' . $xmlFile),
Expand Down
2 changes: 1 addition & 1 deletion src/CfdiUtils/Certificado/NodeCertificado.php
@@ -1,8 +1,8 @@
<?php
namespace CfdiUtils\Certificado;

use CfdiUtils\Internals\TemporaryFile;
use CfdiUtils\Nodes\NodeInterface;
use CfdiUtils\Utils\Internal\TemporaryFile;

class NodeCertificado
{
Expand Down
2 changes: 1 addition & 1 deletion src/CfdiUtils/Certificado/SerialNumber.php
@@ -1,7 +1,7 @@
<?php
namespace CfdiUtils\Certificado;

use CfdiUtils\Utils\Internal\BaseConverter;
use CfdiUtils\Internals\BaseConverter;

/**
* This class is used to load hexadecimal or decimal data as a certificate serial number.
Expand Down
@@ -1,5 +1,5 @@
<?php
namespace CfdiUtils\Utils\Internal;
namespace CfdiUtils\Internals;

/**
* Converts any string of any base to any other base without
Expand All @@ -8,8 +8,7 @@
* @see https://php.net/base_convert
* Original author: https://github.com/credomane/php_baseconvert
*
* NOTE: Changes on this file will not be considering a BC since this utility class is for internal usage only
*
* NOTE: Changes will not be considering a bracking compatibility change since this utility is for internal usage only
* @internal
*/
class BaseConverter
Expand Down
@@ -1,11 +1,10 @@
<?php
namespace CfdiUtils\Utils\Internal;
namespace CfdiUtils\Internals;

/**
* This is a value object for BaseConverter containing the sequence
*
* NOTE: Changes on this file will not be considering a BC since this utility class is for internal usage only
*
* NOTE: Changes will not be considering a bracking compatibility change since this utility is for internal usage only
* @internal
*/
class BaseConverterSequence
Expand Down
30 changes: 30 additions & 0 deletions src/CfdiUtils/Internals/NormalizeLineEndingsTrait.php
@@ -0,0 +1,30 @@
<?php
namespace CfdiUtils\Internals;

/**
* NormalizeLineEndingsTrait contains a private function normalizeLineEndings
* This help the implementer class to work with EOL
*
* NOTE: Changes will not be considering a bracking compatibility change since this utility is for internal usage only
* @internal
*/
trait NormalizeLineEndingsTrait
{
/**
* Changes EOL CRLF or LF to PHP_EOL.
* This won't alter CR that are not at EOL.
* This won't alter LFCR used in old Mac style
*
* @param string $content
* @return string
* @internal
*/
private function normalizeLineEndings(string $content): string
{
// move '\r\n' or '\n' to PHP_EOL
// first substitution '\r\n' -> '\n'
// second substitution '\n' -> PHP_EOL
// remove any EOL at the EOF
return rtrim(str_replace(["\r\n", "\n"], ["\n", PHP_EOL], $content), PHP_EOL);
}
}
13 changes: 13 additions & 0 deletions src/CfdiUtils/Internals/README.md
@@ -0,0 +1,13 @@
# CfdiUtils\Internals

Dear user of `CfdiUtils`:

**This namespace is for project internal usage.**
**Do not use any of the elements (classes, traits, etc) stored in this namespaces.**

The elements on this namespace could change and it won't be considered a Breack Compatilibity Change.

The elements on this namespace must never be exposed outside this library (by example, by return).

The elements on this namespace have the `@internal` annotation, if you use an IDE or a code inspector
you will be warned about it.
@@ -1,13 +1,12 @@
<?php
namespace CfdiUtils\Utils\Internal;
namespace CfdiUtils\Internals;

use Symfony\Component\Process\Process;

/**
* Execute a command and retrieve results
*
* NOTE: Changes on this file will not be considering a BC since this utility class is for internal usage only
*
* NOTE: Changes will not be considering a bracking compatibility change since this utility is for internal usage only
* @internal
*/
class ShellExec
Expand Down Expand Up @@ -76,9 +75,9 @@ public function getEnvironment(): array

public function run(): ShellExecResult
{
// Set environment on run command for compatibility with symfony/process ^3.4 & php ~ 7.0
$process = new Process($this->getCommand());
$process->setEnv($this->getEnvironment());
$process->run();
$process->run(null, $this->getEnvironment());
return new ShellExecResult(
$process->getCommandLine(),
$process->getExitCode() ?? -1,
Expand Down
@@ -1,11 +1,12 @@
<?php
namespace CfdiUtils\Utils\Internal;
namespace CfdiUtils\Internals;

/**
* Internal class, contains the result of ShellExec::exec()
* Contains the result of ShellExec::exec()
*
* NOTE: Changes on this file will not be considering a BC since this utility class is for internal usage only
* @see ShellExec
*
* NOTE: Changes will not be considering a bracking compatibility change since this utility is for internal usage only
* @internal
*/
class ShellExecResult
Expand Down
@@ -1,11 +1,10 @@
<?php
namespace CfdiUtils\Utils\Internal;
namespace CfdiUtils\Internals;

/**
* Build a command array from a template
*
* NOTE: Changes on this file will not be considering a BC since this utility class is for internal usage only
*
* NOTE: Changes will not be considering a bracking compatibility change since this utility is for internal usage only
* @internal
*/
class ShellExecTemplate
Expand Down
@@ -1,12 +1,10 @@
<?php
namespace CfdiUtils\Utils\Internal;
namespace CfdiUtils\Internals;

/**
* Utility to work with temporary the creation of files.
* Use it instead of \tempnam PHP function
*
* NOTE: Changes on this file will not be considering a BC since this utility class is for internal usage only
* Utility to work with the creation of temporary files.
*
* NOTE: Changes will not be considering a bracking compatibility change since this utility is for internal usage only
* @internal
*/
final class TemporaryFile
Expand Down
4 changes: 2 additions & 2 deletions src/CfdiUtils/OpenSSL/Caller.php
@@ -1,8 +1,8 @@
<?php
namespace CfdiUtils\OpenSSL;

use CfdiUtils\Utils\Internal\ShellExec;
use CfdiUtils\Utils\Internal\ShellExecTemplate;
use CfdiUtils\Internals\ShellExec;
use CfdiUtils\Internals\ShellExecTemplate;

class Caller
{
Expand Down

0 comments on commit 50cf317

Please sign in to comment.