-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Evert Harmeling
committed
Jul 23, 2019
1 parent
e32de17
commit 994e089
Showing
5 changed files
with
119 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.phpunit.result.cache | ||
composer.lock | ||
coverage | ||
phpunit.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,47 @@ | ||
language: php | ||
sudo: false | ||
cache: | ||
directories: | ||
- $HOME/.composer/cache/files | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
env: | ||
global: | ||
- PHPUNIT_FLAGS="-v -c ." | ||
- SYMFONY_DEPRECATIONS_HELPER="max[self]=0" | ||
|
||
before_script: | ||
- composer install | ||
matrix: | ||
fast_finish: true | ||
include: | ||
# Minimum supported dependencies with the latest and oldest PHP version | ||
- php: 7.3 | ||
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" | ||
- php: 7.1 | ||
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" | ||
|
||
script: vendor/bin/phpunit --coverage-text | ||
# Test the latest stable release | ||
- php: 7.1 | ||
- php: 7.2 | ||
- php: 7.3 | ||
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text" | ||
|
||
# Latest commit to master | ||
- php: 7.3 | ||
env: STABILITY="dev" | ||
|
||
allow_failures: | ||
# Dev-master is allowed to fail. | ||
- env: STABILITY="dev" | ||
|
||
before_install: | ||
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi | ||
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi; | ||
|
||
install: | ||
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction | ||
|
||
script: | ||
- composer validate --strict --no-check-lock | ||
- ./vendor/bin/phpunit $PHPUNIT_FLAGS | ||
|
||
notifications: | ||
email: '[email protected]' | ||
email: [ '[email protected]' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,61 +3,60 @@ | |
namespace Tests\VIESApi\Client; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Http\Mock\Client as MockClient; | ||
use PHPUnit\Framework\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
use VIESApi\Client\Client; | ||
use VIESApi\Exception\TaxableObjectNotFoundException; | ||
use VIESApi\Model\TaxableObject; | ||
use VIESApi\Parser\VATParser; | ||
|
||
use function file_get_contents; | ||
use function GuzzleHttp\Psr7\parse_response; | ||
use function sprintf; | ||
use function ucfirst; | ||
|
||
/** | ||
* @author Evert Harmeling <[email protected]> | ||
*/ | ||
class ClientTest extends \PHPUnit_Framework_TestCase | ||
class ClientTest extends TestCase | ||
{ | ||
const VAT_NUMBER = 'NL818918172B01'; | ||
const VAT_NUMBER_INVALID = 'NL818918172B99'; | ||
private const VAT_NUMBER = 'NL818918172B01'; | ||
private const VAT_NUMBER_INVALID = 'NL818918172B99'; | ||
|
||
public function testGetInfo() | ||
public function testGetInfo(): void | ||
{ | ||
$client = $this->createClient($this->loadMockResponse('response.get_vat_number')); | ||
$taxableObject = $client->getInfo(self::VAT_NUMBER); | ||
|
||
static::assertInstanceOf(TaxableObject::class, $taxableObject); | ||
static::assertEquals(self::VAT_NUMBER, sprintf('%s%s', $taxableObject->getCountryCode(), $taxableObject->getVATNumber())); | ||
static::assertNotNull($taxableObject->getName()); | ||
static::assertNotNull($taxableObject->getAddress()); | ||
Assert::assertInstanceOf(TaxableObject::class, $taxableObject); | ||
Assert::assertEquals(self::VAT_NUMBER, sprintf('%s%s', $taxableObject->getCountryCode(), $taxableObject->getVATNumber())); | ||
Assert::assertNotNull($taxableObject->getName()); | ||
Assert::assertNotNull($taxableObject->getAddress()); | ||
} | ||
|
||
/** | ||
* @expectedException \VIESApi\Exception\TaxableObjectNotFoundException | ||
*/ | ||
public function testGetInvalidInfo() | ||
public function testGetInvalidInfo(): void | ||
{ | ||
$this->expectException(TaxableObjectNotFoundException::class); | ||
|
||
$client = $this->createClient($this->loadMockResponse('response.invalid_vat_number')); | ||
$taxableObject = $client->getInfo(self::VAT_NUMBER_INVALID); | ||
$client->getInfo(self::VAT_NUMBER_INVALID); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return Response | ||
*/ | ||
private function loadMockResponse($name) | ||
private function loadMockResponse(string $name): Response | ||
{ | ||
list($dir, $name) = explode('.', $name); | ||
[$dir, $name] = explode('.', $name); | ||
|
||
return \GuzzleHttp\Psr7\parse_response( | ||
return parse_response( | ||
file_get_contents( | ||
sprintf('%s/../../Mock/%s/%s', __DIR__, ucfirst($dir), $name) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @param Response $mockedResponse | ||
* | ||
* @return Client | ||
*/ | ||
private function createClient(Response $mockedResponse) | ||
private function createClient(Response $mockedResponse): Client | ||
{ | ||
$httpClient = new \Http\Mock\Client(); | ||
$httpClient = new MockClient(); | ||
$httpClient->addResponse($mockedResponse); | ||
|
||
return new Client($httpClient, new VATParser()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,51 +3,55 @@ | |
namespace Tests\VIESApi\Validator; | ||
|
||
use PHPUnit\Framework\Assert; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use VIESApi\Client\Client; | ||
use VIESApi\Exception\InvalidVATNumberException; | ||
use VIESApi\Model\Country; | ||
use VIESApi\Validator\VATNumberValidator; | ||
|
||
use function is_array; | ||
|
||
/** | ||
* @link https://www.btw-nummer-controle.nl/Userfiles/images/Format%20btw-nummers%20EU(4).pdf | ||
* | ||
* @author Evert Harmeling <[email protected]> | ||
*/ | ||
class VATNumberValidatorTest extends \PHPUnit_Framework_TestCase | ||
class VATNumberValidatorTest extends TestCase | ||
{ | ||
const VALID_AT_VAT_NUMBER = 'ATU123456789'; | ||
const VALID_BE_VAT_NUMBER = 'BE0123456789'; | ||
const VALID_BG_VAT_NUMBER = [ 'BG123456789', 'BG1234567890' ]; | ||
const VALID_CY_VAT_NUMBER = 'CY12345678A'; | ||
const VALID_CZ_VAT_NUMBER = [ 'CZ12345678', 'CZ123456789', 'CZ1234567890' ]; | ||
const VALID_DE_VAT_NUMBER = 'DE123456789'; | ||
const VALID_DK_VAT_NUMBER = 'DK12 34 56 78'; | ||
const VALID_EE_VAT_NUMBER = 'EE123456789'; | ||
const VALID_EL_VAT_NUMBER = 'EL123456789'; | ||
const VALID_ES_VAT_NUMBER = [ 'ES123456789', 'ESA23456789', 'ESA2345678A', 'ES12345678A' ]; | ||
const VALID_FI_VAT_NUMBER = 'FI12345678'; | ||
const VALID_FR_VAT_NUMBER = [ 'FR12 123456789', 'FRA1 123456789', 'FR1A 123456789', 'FRAA 123456789' ]; | ||
const VALID_GB_VAT_NUMBER = [ 'GB123 4567 89', 'GB123 4567 89 012', 'GBGD123', 'GBHA123' ]; | ||
const VALID_HR_VAT_NUMBER = 'HR12345678901'; | ||
const VALID_HU_VAT_NUMBER = 'HU12345678'; | ||
const VALID_IE_VAT_NUMBER = [ 'IE1234567A', 'IE1A34567A', 'IE1+34567A', 'IE1*34567A' ]; | ||
const VALID_IT_VAT_NUMBER = 'IT12345678901'; | ||
const VALID_LT_VAT_NUMBER = [ 'LT123456789', 'LT123456789012' ]; | ||
const VALID_LU_VAT_NUMBER = 'LU12345678'; | ||
const VALID_LV_VAT_NUMBER = 'LV12345678901'; | ||
const VALID_MT_VAT_NUMBER = 'MT12345678'; | ||
const VALID_NL_VAT_NUMBER = 'NL123456789B01'; | ||
const VALID_PL_VAT_NUMBER = 'PL1234567890'; | ||
const VALID_PT_VAT_NUMBER = 'PT123456789'; | ||
const VALID_RO_VAT_NUMBER = [ 'RO12', 'RO123', 'RO1234', 'RO12345', 'RO123456', 'RO1234567', 'RO12345678', 'RO123456789', 'RO1234567890' ]; | ||
const VALID_SE_VAT_NUMBER = 'SE123456789012'; | ||
const VALID_SL_VAT_NUMBER = 'SL12345678'; | ||
const VALID_SK_VAT_NUMBER = 'SK1234567890'; | ||
|
||
private const VALID_AT_VAT_NUMBER = 'ATU123456789'; | ||
private const VALID_BE_VAT_NUMBER = 'BE0123456789'; | ||
private const VALID_BG_VAT_NUMBER = [ 'BG123456789', 'BG1234567890' ]; | ||
private const VALID_CY_VAT_NUMBER = 'CY12345678A'; | ||
private const VALID_CZ_VAT_NUMBER = [ 'CZ12345678', 'CZ123456789', 'CZ1234567890' ]; | ||
private const VALID_DE_VAT_NUMBER = 'DE123456789'; | ||
private const VALID_DK_VAT_NUMBER = 'DK12 34 56 78'; | ||
private const VALID_EE_VAT_NUMBER = 'EE123456789'; | ||
private const VALID_EL_VAT_NUMBER = 'EL123456789'; | ||
private const VALID_ES_VAT_NUMBER = [ 'ES123456789', 'ESA23456789', 'ESA2345678A', 'ES12345678A' ]; | ||
private const VALID_FI_VAT_NUMBER = 'FI12345678'; | ||
private const VALID_FR_VAT_NUMBER = [ 'FR12 123456789', 'FRA1 123456789', 'FR1A 123456789', 'FRAA 123456789' ]; | ||
private const VALID_GB_VAT_NUMBER = [ 'GB123 4567 89', 'GB123 4567 89 012', 'GBGD123', 'GBHA123' ]; | ||
private const VALID_HR_VAT_NUMBER = 'HR12345678901'; | ||
private const VALID_HU_VAT_NUMBER = 'HU12345678'; | ||
private const VALID_IE_VAT_NUMBER = [ 'IE1234567A', 'IE1A34567A', 'IE1+34567A', 'IE1*34567A' ]; | ||
private const VALID_IT_VAT_NUMBER = 'IT12345678901'; | ||
private const VALID_LT_VAT_NUMBER = [ 'LT123456789', 'LT123456789012' ]; | ||
private const VALID_LU_VAT_NUMBER = 'LU12345678'; | ||
private const VALID_LV_VAT_NUMBER = 'LV12345678901'; | ||
private const VALID_MT_VAT_NUMBER = 'MT12345678'; | ||
private const VALID_NL_VAT_NUMBER = 'NL123456789B01'; | ||
private const VALID_PL_VAT_NUMBER = 'PL1234567890'; | ||
private const VALID_PT_VAT_NUMBER = 'PT123456789'; | ||
private const VALID_RO_VAT_NUMBER = [ 'RO12', 'RO123', 'RO1234', 'RO12345', 'RO123456', 'RO1234567', 'RO12345678', 'RO123456789', 'RO1234567890' ]; | ||
private const VALID_SE_VAT_NUMBER = 'SE123456789012'; | ||
private const VALID_SL_VAT_NUMBER = 'SL12345678'; | ||
private const VALID_SK_VAT_NUMBER = 'SK1234567890'; | ||
|
||
/** | ||
* @dataProvider validVATNumberProvider | ||
*/ | ||
public function testValidVATNumbers($values) | ||
public function testValidVATNumbers($values): void | ||
{ | ||
if (!is_array($values)) { | ||
$values = [ $values ]; | ||
|
@@ -60,10 +64,11 @@ public function testValidVATNumbers($values) | |
|
||
/** | ||
* @dataProvider invalidVATNumberProvider | ||
* @expectedException \VIESApi\Exception\InvalidVATNumberException | ||
*/ | ||
public function testInvalidVATNumbers($values) | ||
public function testInvalidVATNumbers($values): void | ||
{ | ||
$this->expectException(InvalidVATNumberException::class); | ||
|
||
if (!is_array($values)) { | ||
$values = [ $values ]; | ||
} | ||
|
@@ -73,13 +78,14 @@ public function testInvalidVATNumbers($values) | |
} | ||
} | ||
|
||
public function validVATNumberProvider() | ||
public function validVATNumberProvider(): array | ||
{ | ||
return [ | ||
Country::CODE_AUSTRIA => [ self::VALID_AT_VAT_NUMBER ], | ||
Country::CODE_BELGIUM => [ self::VALID_BE_VAT_NUMBER ], | ||
Country::CODE_BULGARY => [ self::VALID_BG_VAT_NUMBER ], | ||
Country::CODE_CZECH_REPUBLIC => [ self::VALID_CZ_VAT_NUMBER ], | ||
Country::CODE_CYPRUS => [ self::VALID_CY_VAT_NUMBER ], | ||
Country::CODE_GERMANY => [ self::VALID_DE_VAT_NUMBER ], | ||
Country::CODE_DENMARK => [ self::VALID_DK_VAT_NUMBER ], | ||
Country::CODE_ESTONIA => [ self::VALID_EE_VAT_NUMBER ], | ||
|
@@ -106,7 +112,7 @@ public function validVATNumberProvider() | |
]; | ||
} | ||
|
||
public function invalidVATNumberProvider() | ||
public function invalidVATNumberProvider(): array | ||
{ | ||
return [ | ||
Country::CODE_AUSTRIA => [ [ 'ATU12345678', 'ATU1234567890' ] ], | ||
|
@@ -140,18 +146,15 @@ public function invalidVATNumberProvider() | |
]; | ||
} | ||
|
||
/** | ||
* @return VATNumberValidator | ||
*/ | ||
private function getValidator() | ||
private function getValidator(): VATNumberValidator | ||
{ | ||
return new VATNumberValidator($this->createClientMock()); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit_Framework_MockObject_MockObject|Client | ||
* @return MockObject|Client | ||
*/ | ||
private function createClientMock() | ||
private function createClientMock(): MockObject | ||
{ | ||
return $this->getMockBuilder(Client::class) | ||
->disableOriginalConstructor() | ||
|