Skip to content

Commit

Permalink
Update requirements (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiabasone committed Mar 3, 2022
1 parent a8bf181 commit 11a31af
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 68 deletions.
31 changes: 7 additions & 24 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
name: Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

on: [push]
jobs:
test:

name: Test PHP ${{ matrix.php-versions }}
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1']

steps:
- uses: actions/checkout@v2
Expand All @@ -32,26 +27,14 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache-dir.outputs.dir }}
# path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
# key: node-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
# restore-keys: composer-7.2
- name: Install dependencies
run: (test -d vendor && echo vendor directory exists) || composer install --prefer-dist --no-progress --no-suggest
- name: Run PHPUnit
run: vendor/bin/phpunit --coverage-text --coverage-clover clover.xml
- name: "[Coveralls] Extract branch name"
if: matrix.php-versions == '7.4'
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: "[Coveralls] Checkout branch"
if: matrix.php-versions == '7.4'
shell: bash
run: git fetch && git checkout ${{ steps.extract_branch.outputs.branch }}
- name: "[Coveralls] Send report"
if: matrix.php-versions == '7.4'
run: vendor/bin/php-coveralls -v -x clover.xml -o coveralls-upload.json
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
- name: Upload Scrutinizer coverage
if: matrix.php-versions == '8.0'
uses: sudo-bot/action-scrutinizer@latest
with:
cli-args: "--format=php-clover clover.xml"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ clover.xml
.phpunit.xml.dist
/tests/demo/config.php
/tests/demo/paymentID.txt
/tests/demo/shopID.txt
/tests/demo/shopID.txt
/.php-cs-fixer.cache
8 changes: 4 additions & 4 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([
__DIR__.'/src',
__DIR__.'/tests'
]);
return PhpCsFixer\Config::create()
return (new \PhpCsFixer\Config())
->setFinder($finder)
->setRules([
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_return' => true,
'blank_line_before_statement' => true,
'blank_line_before_statement' => ['statements' => ['return']],
'declare_strict_types' => false,
'fully_qualified_strict_types' => true,
'line_ending' => true,
'linebreak_after_opening_tag' => true,
'lowercase_constants' => true,
'constant_case' => ['case' => 'lower'],
'mb_str_functions' => true,
'native_function_invocation' => true,
'no_closing_tag' => true,
Expand Down
23 changes: 23 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
build:
nodes:
analysis:
project_setup:
override:
- 'true'
tests:
override:
- php-scrutinizer-run
-
command: phpcs-run
use_website_config: true
tests: true
filter:
excluded_paths:
- 'tests/*'
checks:
php: true
coding_style:
php: { }
tools:
external_code_coverage:
timeout: 600
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ With this package I'm trying to improve the crappy IGFS CG PHP Library provided
[![Latest Stable Version](https://poser.pugx.org/mattiabasone/pagonline/v/stable)](https://packagist.org/packages/mattiabasone/pagonline)
[![Total Downloads](https://poser.pugx.org/mattiabasone/pagonline/downloads)](https://packagist.org/packages/mattiabasone/pagonline)
[![Build Status](https://img.shields.io/github/workflow/status/mattiabasone/PagOnline/Test)](https://github.com/mattiabasone/PagOnline/actions?query=workflow%3ATest)
[![Coverage Status](https://coveralls.io/repos/github/mattiabasone/PagOnline/badge.svg)](https://coveralls.io/github/mattiabasone/PagOnline)
[![Coverage Status](https://scrutinizer-ci.com/g/mattiabasone/PagOnline/badges/coverage.png?b=master)](https://coveralls.io/github/mattiabasone/PagOnline)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mattiabasone/PagOnline/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mattiabasone/PagOnline/?branch=master)

### Basic Usage
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-simplexml": "*",
"illuminate/support": "^5.8|^6.0|^7.0|^8.0",
"illuminate/support": "^5.8|^6.0|^7.0|^8.0|^9.0",
"guzzlehttp/guzzle": "~6.0|^7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"friendsofphp/php-cs-fixer": "^2.16|^3.0",
"phpunit/phpunit": "^7.5|^8.0|^9.0",
"phpstan/phpstan": "^0.12",
"illuminate/config": "^5.8|^6.0|^7.0|^8.0",
"php-coveralls/php-coveralls": "^2.1",
"orchestra/testbench": "^3.7"
"phpstan/phpstan": "^1.4",
"illuminate/config": "^5.8|^6.0|^7.0|^8.0|^9.0",
"orchestra/testbench": "^3.7|^4.0|^5.0|^6.0|^7.0"
},
"autoload": {
"psr-4": {
Expand Down
28 changes: 15 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
</phpunit>
17 changes: 7 additions & 10 deletions src/XmlEntities/BaseXmlEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
use ReflectionProperty;
use SimpleXMLElement;

/**
* Class BaseXmlEntity.
*/
abstract class BaseXmlEntity implements XmlEntityInterface
{
use CastProperties, EntityAttributes;
Expand All @@ -34,7 +31,7 @@ public function __construct()
*
* @return array
*/
public function getAttributes()
public function getAttributes(): array
{
return $this->attributes;
}
Expand Down Expand Up @@ -74,7 +71,7 @@ public function toXml(string $rootNodeName): string
* @param array $response
* @param string $attribute
*/
public function setAttributeFromResponse($response, $attribute)
public function setAttributeFromResponse($response, $attribute): void
{
$value = (string) IgfsUtils::getValue($response, $attribute);
if ($this->isDateAttribute($attribute)) {
Expand Down Expand Up @@ -116,7 +113,7 @@ public static function fromXml($xml): ?XmlEntityInterface
$object->setAttributeFromResponse($xmlArray, $attribute);
} else {
foreach ($dom->xpath($attribute) as $entry) {
\array_push($object->{$attribute}, $entry->__toString());
$object->{$attribute}[] = $entry->__toString();
}
}
} else {
Expand All @@ -131,7 +128,7 @@ public static function fromXml($xml): ?XmlEntityInterface
/**
* @return array
*/
public function toArray()
public function toArray(): array
{
$returnArray = [];
foreach ($this->attributes as $attribute) {
Expand All @@ -148,7 +145,7 @@ protected function loadAttributes(): void
{
$publicProperties = (new ReflectionObject($this))->getProperties(ReflectionProperty::IS_PUBLIC);
foreach ($publicProperties as $publicProperty) {
\array_push($this->attributes, $publicProperty->getName());
$this->attributes[] = $publicProperty->getName();
}
}

Expand All @@ -158,7 +155,7 @@ protected function loadAttributes(): void
*
* @return string
*/
protected function attributeValueToTagString(string $attribute, string $value)
protected function attributeValueToTagString(string $attribute, string $value): string
{
return "<{$attribute}><![CDATA[{$value}]]></{$attribute}>";
}
Expand All @@ -167,7 +164,7 @@ protected function attributeValueToTagString(string $attribute, string $value)
* @param \SimpleXMLElement $dom
* @param string $attribute
*/
protected function setCustomAttributeFromDom(SimpleXMLElement $dom, $attribute)
protected function setCustomAttributeFromDom(SimpleXMLElement $dom, $attribute): void
{
if ($this->entityAttributes[$attribute]['type'] === 'array') {
$value = [];
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/IgfsCgBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
use PagOnline\Exceptions\IgfsException;
use PagOnline\Exceptions\IgfsMissingParException;
use PagOnline\IgfsCgInterface;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
* Class IgfsCgBaseTest.
*/
abstract class IgfsCgBaseTest extends TestCase
abstract class IgfsCgBaseTest extends IgfsTestCase
{
protected $igfsCgClass;
protected $igfsCgAction;
Expand Down Expand Up @@ -163,7 +162,7 @@ public function shouldReturnArrayUniqueBoundaryValue(): void
$getUniqueBoundaryValueMethod = $this->getClassMethod('getUniqueBoundaryValue');
$uniqueId = $getUniqueBoundaryValueMethod->invoke($obj);
$this->assertIsString($uniqueId);
$this->assertRegExp('([a-z0-9]{13})', $uniqueId);
$this->assertMatchesRegex('([a-z0-9]{13})', $uniqueId);
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/IgfsTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace PagOnline\Tests\Unit;

use PHPUnit\Framework\TestCase;

class IgfsTestCase extends TestCase
{
/**
* Compatibility function for older PHPUnit versions
*
* @param string $pattern
* @param string $value
* @return void
*/
public function assertMatchesRegex(string $pattern, string $value): void
{
if (method_exists($this, 'assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression($pattern, $value);
} else {
$this->assertRegExp($pattern, $value);
}
}

}
8 changes: 2 additions & 6 deletions tests/Unit/IgfsUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
namespace PagOnline\Tests\Unit;

use PagOnline\IgfsUtils;
use PHPUnit\Framework\TestCase;

/**
* Class IgfsUtilsTest.
*/
class IgfsUtilsTest extends TestCase
class IgfsUtilsTest extends IgfsTestCase
{
/**
* @test
Expand All @@ -22,7 +18,7 @@ public function shouldReturnUuid(): void
public function shouldReturnUniqueBoundaryValue(): void
{
$uniqueId = IgfsUtils::getUniqueBoundaryValue();
$this->assertRegExp('([a-z0-9]{13})', $uniqueId);
$this->assertMatchesRegex('([a-z0-9]{13})', $uniqueId);
}

/** @test */
Expand Down

0 comments on commit 11a31af

Please sign in to comment.