diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml new file mode 100644 index 0000000..e9e6c58 --- /dev/null +++ b/.github/workflows/code_checks.yml @@ -0,0 +1,37 @@ +# .github/workflows/code_checks.yaml +name: Code_Checks + +on: ["push", "pull_request"] + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ['7.2', '7.3', '7.4', '8.0', '8.1'] + stability: [ prefer-lowest, prefer-stable ] + + name: PHP ${{ matrix.php }} - ${{ matrix.stability }} tests + steps: + # basically git clone + - uses: actions/checkout@v2 + + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: ~/.composer/cache/files + key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + # use PHP of specific version + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: pcov + coverage: pcov + + - name: Install dependencies + run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/phpunit --verbose diff --git a/.gitignore b/.gitignore index d575ea2..e946f56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ vendor/ +var/ composer.lock Tests/Functional/app/cache .idea +.phpunit.result.cache +.github/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 92ddf87..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -sudo: false - -language: php - -php: - - 7.2 - - 7.3 - -matrix: - include: - - php: 7.2 - env: COMPOSER_FLAGS="--prefer-lowest" - -install: composer update --prefer-dist --no-interaction $COMPOSER_FLAGS - -script: vendor/bin/phpunit --coverage-text diff --git a/DependencyInjection/DdeboerVatinExtension.php b/DependencyInjection/DdeboerVatinExtension.php index e54d594..158c8e8 100644 --- a/DependencyInjection/DdeboerVatinExtension.php +++ b/DependencyInjection/DdeboerVatinExtension.php @@ -10,7 +10,7 @@ /** * This is the class that loads and manages your bundle configuration * - * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} + * To learn more see {@link https://symfony.com/doc/current/cookbook/bundles/extension.html} */ class DdeboerVatinExtension extends Extension { diff --git a/README.md b/README.md index e1563f9..01e7373 100644 --- a/README.md +++ b/README.md @@ -16,18 +16,18 @@ $ composer require ddeboer/vatin-bundle Then add the bundle to your application: +If you don't use [Symfony Flex](https://symfony.com/doc/current/setup/flex.html), you must enable the bundle manually in the application: + ```php -// app/AppKernel.php -public function registerBundles() -{ - return [ - ... - new Ddeboer\VatinBundle\DdeboerVatinBundle(), - ... - ]; -} +// config/bundles.php +// in older Symfony apps, enable the bundle in app/AppKernel.php +return [ + // ... + Ddeboer\VatinBundle\DdeboerVatinBundle::class => ['all' => true], +]; ``` + Usage ----- @@ -48,7 +48,7 @@ class Company ``` Symfony’s validator will now check whether `$vatNumber` has a valid VAT number -format. For more information, see [Symfony’s documentation](http://symfony.com/doc/current/book/validation.html). +format. For more information, see [Symfony’s documentation](https://symfony.com/doc/current/book/validation.html). ### Validate number existence @@ -61,8 +61,16 @@ Additionally, you can check whether the VAT number is in use: protected $vatNumber; ``` +```php + /** + * PHP 8 Attribute + */ + #[Vatin(checkExistence: true)] + protected $vatNumber; +``` + The validator will now check the VAT number against the -[VAT Information Exchange System (VIES)](http://ec.europa.eu/taxation_customs/vies/faq.html) +[VAT Information Exchange System (VIES)](https://ec.europa.eu/taxation_customs/vies/faq.html) SOAP web service. This service’s availability is rather unreliable, so it’s a good idea to catch the case where it’s unreachable: diff --git a/Tests/Functional/ValidatorAnnotationTest.php b/Tests/Functional/ValidatorAnnotationTest.php index c60df61..1a75283 100644 --- a/Tests/Functional/ValidatorAnnotationTest.php +++ b/Tests/Functional/ValidatorAnnotationTest.php @@ -14,32 +14,49 @@ class ValidatorAnnotationTest extends WebTestCase */ private $validator; - protected function setUp() + protected function setUp(): void { static::bootKernel(); $container = static::$kernel->getContainer(); $this->validator = $container->get('validator'); } + /** + * @requires PHP 8.0 + */ public function testValid() { $model = new Model(); $errors = $this->validator->validate($model); - $this->assertEquals(0, count($errors)); + $this->assertCount(0, $errors); $model->vat = 'NL123456789B01'; $this->assertCount(0, $this->validator->validate($model)); } + /** + * @requires PHP 8.0 + */ public function testCheckExistence() { $model = new Model(); + # invalid value $model->vatCheckExistence = '123'; - $this->assertCount(1, $this->validator->validate($model)); + try { + $this->assertCount(0, $this->validator->validate($model)); + } catch (ValidatorException $e) { + if (!$e->getPrevious() instanceof ViesException) { + throw $e; + } + + // Ignore unreachable VIES service: at least the check was triggered + } + + # valid value $model->vatCheckExistence = 'NL123456789B01'; try { - $this->assertCount(1, $this->validator->validate($model)); + $this->assertCount(0, $this->validator->validate($model)); } catch (ValidatorException $e) { if (!$e->getPrevious() instanceof ViesException) { throw $e; diff --git a/Tests/Functional/app/AppKernel.php b/Tests/Functional/app/AppKernel.php index 7125ab3..29f8b88 100644 --- a/Tests/Functional/app/AppKernel.php +++ b/Tests/Functional/app/AppKernel.php @@ -5,7 +5,7 @@ class AppKernel extends Kernel { - public function registerBundles() + public function registerBundles(): array { return [ new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), diff --git a/Tests/Functional/app/autoload.php b/Tests/Functional/app/autoload.php index 8a62af0..8f781ab 100644 --- a/Tests/Functional/app/autoload.php +++ b/Tests/Functional/app/autoload.php @@ -1,12 +1,5 @@ isValidVatin($value, $constraint->checkExistence)) { - return; - } + try { + #var_dump('Check '.$value. ' '.$constraint->checkExistence); + if ($this->isValidVatin($value, $constraint->checkExistence)) { + return; + } - $this->context->buildViolation($constraint->message) - ->addViolation(); + $this->context->buildViolation($constraint->message)->addViolation(); + } + catch (\Exception $e) + { + #var_dump($e->getMessage()); + #var_dump("error build violation for ".$value); + $this->context->buildViolation($constraint->message)->addViolation(); + } } /** * Is the value a valid VAT identification number? - * - * @param string $value Value - * @param bool $checkExistence Also check whether the VAT number exists - * - * @return bool */ - private function isValidVatin($value, $checkExistence) + private function isValidVatin(string $value, bool $checkExistence): bool { try { return $this->validator->isValid($value, $checkExistence); diff --git a/composer.json b/composer.json index ce826bd..7a7fc78 100644 --- a/composer.json +++ b/composer.json @@ -11,14 +11,18 @@ } ], "require": { - "ddeboer/vatin": "^2.0", - "symfony/framework-bundle": "^3.4.26 || ^4.1.12 || ^5.0", - "symfony/validator": "^3.0 || ^4.0 || ^5.0" + "php": "^7.2 || ^8.0", + "ddeboer/vatin": "^2.2.2", + "symfony/framework-bundle": "^4.4.31 || ^5.3", + "symfony/validator": "^4.4.31 || ^5.3" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0", - "doctrine/annotations": "^1.2", - "symfony/yaml": "^2.7 || ^3.0 || ^4.0 || ^5.0" + "phpunit/phpunit": "^8.5.21 || ^9.5", + "doctrine/annotations": "^1.13.2", + "symfony/yaml": "^4.4.31 || ^5.3", + "symfony/dependency-injection": "^4.4.31 || ^5.3", + "symfony/config": "^4.4.31 || ^5.3", + "symfony/error-handler": "^4.4.31 || ^5.3" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 040fcd5..100bab6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,31 +1,31 @@ - - - - - ./Tests - - - - - - ./ - - ./Resources - ./Tests - ./vendor - - - - - - - - - - \ No newline at end of file + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> + + + ./ + + + ./github + ./Resources + ./Tests + ./var + ./vendor + + + + + ./Tests + + + + + + + +