Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump minimal PHP version and update packages #68

Merged
merged 11 commits into from
Aug 23, 2024
Merged
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
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Build

on: [ push, pull_request ]

on:
- pull_request
- push
jobs:
tests:
runs-on: "ubuntu-latest"
Expand All @@ -12,7 +13,7 @@ jobs:
- "8.3"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -21,11 +22,10 @@ jobs:
tools: "cs2pr"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"

- name: "Run phpcs"
if: ${{ matrix.php-version == '8.3' }}
run: "vendor/bin/phpcs -n -s --report=checkstyle | cs2pr"
- name: "Run PHP CS Fixer"
run: "./vendor/bin/php-cs-fixer fix --format checkstyle | cs2pr"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor
composer.lock
.idea
.phpunit.result.cache
.php-cs-fixer.cache
12 changes: 12 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(['src', 'tests'])
;

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
])
->setFinder($finder)
;
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This is a simple PHP library to help you deal with Europe's VAT rules.

## Installation

[PHP](https://php.net) version 8.1 or higher with the CURL and JSON extension is required.
[PHP](https://php.net) version 8.2 or higher with the CURL and JSON extension is required.

For VAT number existence checking, the PHP SOAP extension is required as well.

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
}
],
"require": {
"php": ">=8.1",
"php": ">=8.2",
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.5"
"phpunit/phpunit": "^11.1",
"friendsofphp/php-cs-fixer": "^3.54"
},
"autoload": {
"psr-4": {
Expand Down
43 changes: 14 additions & 29 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="false"
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="VAT Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" colors="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="VAT Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
5 changes: 2 additions & 3 deletions src/Rates.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function loadFromFile(): void
throw new Exception("Unserializable file content");
}

$data = unserialize($contents, [
$data = @unserialize($contents, [
'allowed_classes' => [
Period::class,
DateTimeImmutable::class
Expand Down Expand Up @@ -153,7 +153,6 @@ public function getRateForCountry(string $countryCode, string $level = self::RAT
*/
public function getRateForCountryOnDate(string $countryCode, \DateTimeInterface $datetime, string $level = self::RATE_STANDARD): float
{
$activePeriod = $this->resolvePeriod($countryCode, $datetime);
return $activePeriod->getRate($level);
return $this->resolvePeriod($countryCode, $datetime)->getRate($level);
}
}
15 changes: 14 additions & 1 deletion src/Vies/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ public function __construct(int $timeout = 10)
* @throws ViesException
*/
public function checkVat(string $countryCode, string $vatNumber): bool
{
return (bool)$this->getInfo($countryCode, $vatNumber)->valid;
}

/**
* @param string $countryCode
* @param string $vatNumber
*
* @return object
*
* @throws ViesException
*/
public function getInfo(string $countryCode, string $vatNumber): object
{
try {
$response = $this->getClient()->checkVat(
Expand All @@ -55,7 +68,7 @@ public function checkVat(string $countryCode, string $vatNumber): bool
throw new ViesException($e->getMessage(), $e->getCode());
}

return (bool) $response->valid;
return $response;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions tests/Clients/ClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

namespace Ibericode\Vat\Tests\Clients;

use Ibericode\Vat\Clients\ClientException;
use Ibericode\Vat\Clients\IbericodeVatRatesClient;
use Ibericode\Vat\Clients\Client;
use Ibericode\Vat\Period;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class ClientsTest extends TestCase
{
/**
* @group remote-http
* @dataProvider clientProvider
* @throws ClientException
*/
public function testClient(Client $client)
#[DataProvider('clientsProvider')]
public function testClient(Client $client): void
{
$data = $client->fetch();
$this->assertIsArray($data);
Expand All @@ -22,7 +25,7 @@ public function testClient(Client $client)
$this->assertInstanceOf(Period::class, $data['NL'][0]);
}

public function clientProvider()
public static function clientsProvider(): \Generator
{
yield [new IbericodeVatRatesClient()];
}
Expand Down
14 changes: 7 additions & 7 deletions tests/CountriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

class CountriesTest extends TestCase
{
public function testIterator()
public function testIterator(): void
{
$countries = new Countries();

$this->assertCount(249, $countries);
}

public function testArrayAccess()
public function testArrayAccess(): void
{
$countries = new Countries();

Expand All @@ -27,35 +27,35 @@ public function testArrayAccess()
$countries['FOO'];
}

public function testArrayAccessWithInvalidCountryCode()
public function testArrayAccessWithInvalidCountryCode(): void
{
$countries = new Countries();
$this->expectException(Exception::class);
$countries['FOO'];
}

public function testArrayAccessSetValue()
public function testArrayAccessSetValue(): void
{
$countries = new Countries();
$this->expectException(Exception::class);
$countries['FOO'] = 'bar';
}

public function testArrayAccessUnsetValue()
public function testArrayAccessUnsetValue(): void
{
$countries = new Countries();
$this->expectException(Exception::class);
unset($countries['FOO']);
}

public function testHasCode()
public function testHasCode(): void
{
$countries = new Countries();
$this->assertFalse($countries->hasCountryCode('FOO'));
$this->assertTrue($countries->hasCountryCode('NL'));
}

public function testIsCodeInEU()
public function testIsCodeInEU(): void
{
$countries = new Countries();
$this->assertFalse($countries->isCountryCodeInEU('FOO'));
Expand Down
7 changes: 4 additions & 3 deletions tests/GeolocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
namespace Ibericode\Vat\Tests;

use Ibericode\Vat\Geolocator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class GeolocatorTest extends TestCase
{
/**
* @dataProvider provider
* @group remote-http
*/
public function testClient($service)
#[DataProvider('servicesProvider')]
public function testService($service): void
{
$geolocator = new Geolocator($service);
$country = $geolocator->locateIpAddress('8.8.8.8');
$this->assertEquals('US', $country);
}

public function provider()
public static function servicesProvider(): \Generator
{
yield ['ip2c.org'];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/RatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function setUp(): void
}
}

private function getRatesClientMock()
private function getRatesClientMock(): \PHPUnit\Framework\MockObject\MockObject
{
$client = $this->getMockBuilder(IbericodeVatRatesClient::class)
->getMock();
Expand Down
35 changes: 14 additions & 21 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Ibericode\Vat\Tests;

use Ibericode\Vat\Validator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -12,9 +13,9 @@
class ValidatorTest extends TestCase
{
/**
* @covers Validator::validateVatNumberFormat
* @coversXXX Validator::validateVatNumberFormat
*/
public function testValidateVatNumberFormat()
public function testValidateVatNumberFormat(): void
{
$valid = [
'ATU12345678',
Expand Down Expand Up @@ -118,33 +119,29 @@ public function testValidateVatNumberFormat()
}
}

/**
* @dataProvider validIpAddresses
*/
public function testValidateIpAddressWithValid($value)
#[DataProvider('validIpAddresses')]
public function testValidateIpAddressWithValid($value): void
{
$validator = new Validator();
$this->assertTrue($validator->validateIpAddress($value));
}

public function validIpAddresses()
public static function validIpAddresses(): array
{
return [
['8.8.8.8'],
['54.18.12.111']
];
}

/**
* @dataProvider invalidIpAddresses
*/
public function testValidateIpAddressWithInvalidValues($value)
#[DataProvider('invalidIpAddresses')]
public function testValidateIpAddressWithInvalidValues($value): void
{
$validator = new Validator();
$this->assertFalse($validator->validateIpAddress($value));
}

public function invalidIpAddresses()
public static function invalidIpAddresses(): array
{
return [
['0.8.8.8.8'],
Expand All @@ -153,26 +150,22 @@ public function invalidIpAddresses()
];
}

/**
* @dataProvider validCountryCodes
*/
public function testValidateCountryCodeWithValidValues($value)
#[DataProvider('validCountryCodes')]
public function testValidateCountryCodeWithValidValues($value): void
{
$validator = new Validator();
$this->assertTrue($validator->validateCountryCode($value));
}

/**
* @dataProvider invalidCountryCodes
*/
#[DataProvider('invalidCountryCodes')]
public function testValidateCountryCodeWithInvalidValues($value)
{
$validator = new Validator();
$this->assertFalse($validator->validateCountryCode($value));
}


public function validCountryCodes()
public static function validCountryCodes(): array
{
return [
['NL'],
Expand All @@ -182,7 +175,7 @@ public function validCountryCodes()
];
}

public function invalidCountryCodes()
public static function invalidCountryCodes(): array
{
return [
['FOO'],
Expand Down