Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
name: PHP Composer

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

jobs:
build:
name: ViesBuild
runs-on: ${{ matrix.operating-system }}
# Let the experimental (next-PHP) leg fail without failing the workflow.
# Legs without an "experimental" value resolve to false and stay blocking.
continue-on-error: ${{ matrix.experimental || false }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.0', '8.1']
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
include:
# Forward-looking, non-blocking signal against the next PHP.
# This plugin exists to smooth installs on newer PHP, so an
# early-warning leg against the upcoming release fits its purpose.
- operating-system: ubuntu-latest
php: '8.6'
experimental: true

steps:
- name: Set default PHP version ${{ matrix.php-versions }}
- name: Set default PHP version ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-versions }}"
php-version: "${{ matrix.php }}"

- name: Display current PHP version
run: php --version

- uses: actions/checkout@v2
- uses: actions/checkout@v5

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v5
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-php-
${{ runner.os }}-php-${{ matrix.php }}-

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
Expand Down
4 changes: 3 additions & 1 deletion src/Vies/Validator/ValidatorIE.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ private function validateIENew(string $vatNumber): bool

$checkChar = 'A';
for ($i = $checkVal - 1; $i > 0; $i--) {
$checkChar++;
// chr(ord(...) + 1) replaces $checkChar++ to avoid incrementing a
// non-numeric string, deprecated since PHP 8.3 (valid on PHP 7.3+).
$checkChar = chr(ord($checkChar) + 1);
}

return $checkChar == $checksum;
Expand Down
1 change: 1 addition & 0 deletions src/Vies/Validator/ValidatorSK.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ValidatorSK extends ValidatorAbstract
public function validate(string $vatNumber): bool
{
if (strlen($vatNumber) != 10
|| ! ctype_digit($vatNumber)
|| intval($vatNumber[0]) == 0
|| ! in_array((int) $vatNumber[2], [2, 3, 4, 7, 8, 9])
) {
Expand Down
23 changes: 23 additions & 0 deletions tests/Vies/Validator/ValidatorSKTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace DragonBe\Test\Vies\Validator;

use DragonBe\Vies\Validator\ValidatorSK;

class ValidatorSKTest extends AbstractValidatorTest
{
/**
Expand All @@ -25,4 +27,25 @@ public function vatNumberProvider()
['4060000007', false],
];
}

/**
* @covers \DragonBe\Vies\Validator\ValidatorSK
*/
public function testValidateRaisesNoWarningOnNonNumericInput()
{
$raised = null;
set_error_handler(static function (int $errno, string $errstr) use (&$raised): bool {
$raised = $errstr;
return true;
}, E_DEPRECATED | E_WARNING);

try {
$result = (new ValidatorSK())->validate('222222222A');
} finally {
restore_error_handler();
}

self::assertFalse($result, 'Non-numeric SK input must be invalid');
self::assertNull($raised, 'Validator must not trigger E_WARNING or E_DEPRECATED');
}
}
20 changes: 15 additions & 5 deletions tests/Vies/ViesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ public function testCanAddOptionalArgumentsWithValue()
{
$viesRef = new \ReflectionClass(Vies::class);
$addOptionalArguments = $viesRef->getMethod('addOptionalArguments');
$addOptionalArguments->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$addOptionalArguments->setAccessible(true);
}

$array = [];
$object = new Vies();
Expand All @@ -409,7 +411,9 @@ public function testCanNotAddOptionalArgumentsWithoutValue()
{
$viesRef = new \ReflectionClass(Vies::class);
$addOptionalArguments = $viesRef->getMethod('addOptionalArguments');
$addOptionalArguments->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$addOptionalArguments->setAccessible(true);
}

$array = [];
$object = new Vies();
Expand Down Expand Up @@ -484,7 +488,9 @@ public function testRejectBadOptionalInformation(
) {
$viesRef = new \ReflectionClass(Vies::class);
$addOptionalArguments = $viesRef->getMethod('addOptionalArguments');
$addOptionalArguments->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$addOptionalArguments->setAccessible(true);
}

$array = [];
$object = new Vies();
Expand Down Expand Up @@ -538,7 +544,9 @@ public function testAllowValidOptionalInformation(
) {
$viesRef = new \ReflectionClass(Vies::class);
$addOptionalArguments = $viesRef->getMethod('addOptionalArguments');
$addOptionalArguments->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$addOptionalArguments->setAccessible(true);
}

$array = [];
$object = new Vies();
Expand All @@ -561,7 +569,9 @@ public function testBreakValidationOfOptionalArguments()
{
$viesRef = new \ReflectionClass(Vies::class);
$addOptionalArguments = $viesRef->getMethod('addOptionalArguments');
$addOptionalArguments->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$addOptionalArguments->setAccessible(true);
}

$this->expectException(\TypeError::class);
$array = [];
Expand Down