diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index b424933..df869a9 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,6 +12,7 @@ jobs: php-version: - 7.3 - 7.4 + - 8.0 steps: - uses: actions/checkout@v2 @@ -19,8 +20,11 @@ jobs: - 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: | diff --git a/.gitignore b/.gitignore index 5cf9a2c..224d9f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.phpunit.result.cache /composer.lock /phpunit.xml /vendor/ diff --git a/composer.json b/composer.json index f93921b..b403f36 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6e1f05d..5c98fd7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,8 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" - syntaxCheck="false"> + stopOnFailure="true"> tests/ diff --git a/tests/VatCalculatorTest.php b/tests/VatCalculatorTest.php index e35e978..3c9f523 100644 --- a/tests/VatCalculatorTest.php +++ b/tests/VatCalculatorTest.php @@ -4,7 +4,7 @@ namespace Spaze\VatCalculator; use DateTimeImmutable; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use ReflectionClass; use SoapClient; use SoapFault; @@ -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'; @@ -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); @@ -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()); @@ -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); @@ -76,7 +76,7 @@ public function testGetTaxRateForLocation() } - public function testCanValidateValidVatNumber() + public function testCanValidateValidVatNumber(): void { $result = new stdClass(); $result->valid = true; @@ -101,7 +101,7 @@ public function testCanValidateValidVatNumber() } - public function testCanValidateInvalidVatNumber() + public function testCanValidateInvalidVatNumber(): void { $result = new stdClass(); $result->valid = false; @@ -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([ @@ -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; @@ -188,7 +190,7 @@ public function testCanValidateValidVatNumberWithRequesterVatNumber() } - public function testCanValidateValidVatNumberWithRequesterVatNumberSet() + public function testCanValidateValidVatNumberWithRequesterVatNumberSet(): void { $result = new stdClass(); $result->valid = true; @@ -224,7 +226,8 @@ 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); @@ -232,7 +235,7 @@ public function testAddNonEuRateShouldCollectValidateThrows(): void } - public function testSetBusinessCountryCode() + public function testSetBusinessCountryCode(): void { $this->vatCalculator->setBusinessCountryCode('DE'); $result = $this->vatCalculator->calculate(24.00, 'DE', null, true); @@ -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); @@ -276,7 +279,7 @@ public function testChecksPostalCodeForVatExceptions() } - public function testPostalCodesWithoutExceptionsGetStandardRate() + public function testPostalCodesWithoutExceptionsGetStandardRate(): void { // Invalid post code $postalCode = 'IGHJ987ERT35'; @@ -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')); @@ -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()); @@ -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()); diff --git a/tests/VatRatesTest.php b/tests/VatRatesTest.php index 954395e..6a6bf67 100644 --- a/tests/VatRatesTest.php +++ b/tests/VatRatesTest.php @@ -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(); } @@ -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));