Skip to content

Commit

Permalink
Merge pull request #23 from spaze/spaze/php8
Browse files Browse the repository at this point in the history
Support PHP 8
  • Loading branch information
spaze authored Nov 26, 2020
2 parents 6a0adbc + 64fb7e1 commit bb9c66e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 33 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ jobs:
php-version:
- 7.3
- 7.4
- 8.0

steps:
- uses: actions/checkout@v2

- name: OS info
run: cat /etc/os-release

- name: Set default PHP version
run: sudo update-alternatives --set php /usr/bin/php${{ matrix.php-version }}
- name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: PHP info
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.phpunit.result.cache
/composer.lock
/phpunit.xml
/vendor/
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
}
],
"require": {
"php": ">=7.3",
"php": "^7.3 || ^8.0",
"ext-soap": "*"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"php-parallel-lint/php-console-highlighter": "^0.5.0",
"phpstan/phpstan": "^0.12.44",
"phpunit/php-timer": "1.0.*",
"phpunit/phpunit": "4.7.*",
"spaze/coding-standard": "^0.0.3"
"phpunit/php-timer": "^5.0",
"phpunit/phpunit": "^9.4",
"spaze/coding-standard": "^0.0.4"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
syntaxCheck="false">
stopOnFailure="true">
<testsuites>
<testsuite name="VatCalculator Suite">
<directory>tests/</directory>
Expand Down
45 changes: 24 additions & 21 deletions tests/VatCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Spaze\VatCalculator;

use DateTimeImmutable;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use SoapClient;
use SoapFault;
Expand All @@ -13,7 +13,7 @@
use Spaze\VatCalculator\Exceptions\VatCheckUnavailableException;
use stdClass;

class VatCalculatorTest extends PHPUnit_Framework_TestCase
class VatCalculatorTest extends TestCase
{

private const DATE = '2020-06-30 23:59:59 Europe/Berlin';
Expand All @@ -28,7 +28,7 @@ class VatCalculatorTest extends PHPUnit_Framework_TestCase
private $vatRates;


protected function setUp()
protected function setUp(): void
{
$this->vatRates = new VatRates();
$this->vatCalculator = new VatCalculator($this->vatRates);
Expand All @@ -41,7 +41,7 @@ protected function setUp()
}


public function testCalculateVat()
public function testCalculateVat(): void
{
$result = $this->vatCalculator->calculate(24.00, 'DE', null, false);
$this->assertEquals(28.56, $result->getPrice());
Expand All @@ -63,7 +63,7 @@ public function testCalculateVat()
}


public function testGetTaxRateForLocation()
public function testGetTaxRateForLocation(): void
{
$result = $this->vatCalculator->getTaxRateForLocation('DE', null, false);
$this->assertEquals(0.19, $result);
Expand All @@ -76,7 +76,7 @@ public function testGetTaxRateForLocation()
}


public function testCanValidateValidVatNumber()
public function testCanValidateValidVatNumber(): void
{
$result = new stdClass();
$result->valid = true;
Expand All @@ -101,7 +101,7 @@ public function testCanValidateValidVatNumber()
}


public function testCanValidateInvalidVatNumber()
public function testCanValidateInvalidVatNumber(): void
{
$result = new stdClass();
$result->valid = false;
Expand All @@ -126,9 +126,9 @@ public function testCanValidateInvalidVatNumber()
}


public function testValidateVatNumberThrowsExceptionOnSoapFailure()
public function testValidateVatNumberThrowsExceptionOnSoapFailure(): void
{
$this->setExpectedException(VatCheckUnavailableException::class);
$this->expectException(VatCheckUnavailableException::class);
$this->vatCheck->expects($this->any())
->method('checkVatApprox')
->with([
Expand All @@ -147,19 +147,21 @@ public function testValidateVatNumberThrowsExceptionOnSoapFailure()

public function testValidateVatNumberThrowsExceptionOnInvalidCountry(): void
{
$this->setExpectedException(UnsupportedCountryException::class, 'Unsupported/non-EU country In');
$this->expectException(UnsupportedCountryException::class);
$this->expectExceptionMessage('Unsupported/non-EU country In');
$this->vatCalculator->isValidVatNumber('InvalidEuCountry');
}


public function testValidateVatNumberThrowsExceptionOnInvalidChars(): void
{
$this->setExpectedException(InvalidCharsInVatNumberException::class, 'VAT number CY123Μ456_789 contains invalid characters: Μ (0xce9c) at offset 5, _ (0x5f) at offset 10');
$this->expectException(InvalidCharsInVatNumberException::class);
$this->expectExceptionMessage('VAT number CY123Μ456_789 contains invalid characters: Μ (0xce9c) at offset 5, _ (0x5f) at offset 10');
$this->vatCalculator->isValidVatNumber('CY123Μ456_789');
}


public function testCanValidateValidVatNumberWithRequesterVatNumber()
public function testCanValidateValidVatNumberWithRequesterVatNumber(): void
{
$result = new stdClass();
$result->valid = true;
Expand Down Expand Up @@ -188,7 +190,7 @@ public function testCanValidateValidVatNumberWithRequesterVatNumber()
}


public function testCanValidateValidVatNumberWithRequesterVatNumberSet()
public function testCanValidateValidVatNumberWithRequesterVatNumberSet(): void
{
$result = new stdClass();
$result->valid = true;
Expand Down Expand Up @@ -224,15 +226,16 @@ public function testAddNonEuRateShouldCollectValidateThrows(): void
$this->assertTrue($this->vatCalculator->shouldCollectVat('NO'));
$this->assertFalse($this->vatCalculator->shouldCollectEuVat('NO'));

$this->setExpectedException(UnsupportedCountryException::class, 'Unsupported/non-EU country No');
$this->expectException(UnsupportedCountryException::class);
$this->expectExceptionMessage('Unsupported/non-EU country No');

$vatNumber = 'Norway132'; // unsupported country NO
$result = $this->vatCalculator->isValidVatNumber($vatNumber);
$this->assertFalse($result);
}


public function testSetBusinessCountryCode()
public function testSetBusinessCountryCode(): void
{
$this->vatCalculator->setBusinessCountryCode('DE');
$result = $this->vatCalculator->calculate(24.00, 'DE', null, true);
Expand All @@ -248,7 +251,7 @@ public function testSetBusinessCountryCode()
}


public function testChecksPostalCodeForVatExceptions()
public function testChecksPostalCodeForVatExceptions(): void
{
$postalCode = '27498'; // Heligoland
$result = $this->vatCalculator->calculate(24.00, 'DE', $postalCode, false);
Expand Down Expand Up @@ -276,7 +279,7 @@ public function testChecksPostalCodeForVatExceptions()
}


public function testPostalCodesWithoutExceptionsGetStandardRate()
public function testPostalCodesWithoutExceptionsGetStandardRate(): void
{
// Invalid post code
$postalCode = 'IGHJ987ERT35';
Expand All @@ -296,7 +299,7 @@ public function testPostalCodesWithoutExceptionsGetStandardRate()
}


public function testShouldCollectVat()
public function testShouldCollectVat(): void
{
$this->assertTrue($this->vatCalculator->shouldCollectVat('DE'));
$this->assertTrue($this->vatCalculator->shouldCollectVat('NL'));
Expand All @@ -305,7 +308,7 @@ public function testShouldCollectVat()
}


public function testCalculateNet()
public function testCalculateNet(): void
{
$result = $this->vatCalculator->calculateNet(28.56, 'DE', null, false);
$this->assertEquals(24.00, $result->getNetPrice());
Expand All @@ -319,14 +322,14 @@ public function testCalculateNet()
}


public function testCalculateHighVatType()
public function testCalculateHighVatType(): void
{
$result = $this->vatCalculator->calculate(24.00, 'NL', null, false, VatRates::HIGH);
$this->assertEquals(29.04, $result->getPrice());
}


public function testCalculateLowVatType()
public function testCalculateLowVatType(): void
{
$result = $this->vatCalculator->calculate(24.00, 'NL', null, false, VatRates::LOW);
$this->assertEquals(26.16, $result->getPrice());
Expand Down
8 changes: 4 additions & 4 deletions tests/VatRatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
namespace Spaze\VatCalculator;

use DateTimeImmutable;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Spaze\VatCalculator\Exceptions\NoVatRulesForCountryException;

class VatRatesTest extends PHPUnit_Framework_TestCase
class VatRatesTest extends TestCase
{

/** @var VatRates */
private $vatRates;


protected function setUp()
protected function setUp(): void
{
$this->vatRates = new VatRates();
}
Expand All @@ -37,7 +37,7 @@ public function testAddRateUnknownCountry(): void
$country = 'yEs';
$this->assertFalse($this->vatRates->shouldCollectVat($country));
$this->assertEquals(0, $this->vatRates->getTaxRateForLocation($country, null));
$this->setExpectedException(NoVatRulesForCountryException::class);
$this->expectException(NoVatRulesForCountryException::class);
$this->vatRates->addRateForCountry($country);
$this->assertFalse($this->vatRates->shouldCollectVat($country));
$this->assertEquals(0, $this->vatRates->getTaxRateForLocation($country, null));
Expand Down

0 comments on commit bb9c66e

Please sign in to comment.