From a8099ef4e9dff03cceac0a161fc464da75369c73 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Sat, 19 Mar 2022 20:23:25 +0200 Subject: [PATCH] Modernize and support Symfony 6 (#23) * migrated to GH actions * dropped SF 2.x and 3.x * updated phpunit and composer * updated project structure to match psr-4, removed useless dependencies in require * fixed phpunit.xml.dist * fixing tests * fixing phpunit.xml.dist --- .github/workflows/ci.yml | 31 +++++++++++++++++++ .gitignore | 2 ++ .travis.yml | 16 ---------- README.md | 6 ++-- Tests/Functional/app/config/config.yml | 5 --- composer.json | 25 +++++++++------ phpunit.xml.dist | 16 +++++----- .../DdeboerVatinBundle.php | 0 .../DdeboerVatinExtension.php | 2 +- .../Resources}/config/services.xml | 0 .../Validator}/Constraints/Vatin.php | 0 .../Validator}/Constraints/VatinValidator.php | 0 {Tests => tests}/Functional/Model.php | 2 +- .../Functional/ValidatorAnnotationTest.php | 4 +-- {Tests => tests}/Functional/app/AppKernel.php | 4 +-- {Tests => tests}/Functional/app/autoload.php | 0 tests/Functional/app/config/config.yml | 12 +++++++ .../Validator/Constraints/ValidatorTest.php | 7 +---- 18 files changed, 80 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml delete mode 100644 Tests/Functional/app/config/config.yml rename DdeboerVatinBundle.php => src/DdeboerVatinBundle.php (100%) rename {DependencyInjection => src/DependencyInjection}/DdeboerVatinExtension.php (94%) rename {Resources => src/Resources}/config/services.xml (100%) rename {Validator => src/Validator}/Constraints/Vatin.php (100%) rename {Validator => src/Validator}/Constraints/VatinValidator.php (100%) rename {Tests => tests}/Functional/Model.php (99%) rename {Tests => tests}/Functional/ValidatorAnnotationTest.php (93%) rename {Tests => tests}/Functional/app/AppKernel.php (89%) rename {Tests => tests}/Functional/app/autoload.php (100%) create mode 100644 tests/Functional/app/config/config.yml rename {Tests => tests}/Validator/Constraints/ValidatorTest.php (83%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bdbffd3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: Tests + +on: + push: + pull_request: + +jobs: + unit-tests: + name: "Unit tests" + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: ['7.3', '7.4', '8.0', '8.1'] + include: + - { php-version: '7.2', dependencies: '--prefer-lowest' } + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + coverage: xdebug + + - name: Install PHP dependencies + run: composer update --no-interaction ${{ matrix.dependencies }} + + - name: Run tests + run: vendor/bin/phpunit --coverage-text diff --git a/.gitignore b/.gitignore index d575ea2..dbd80e7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ vendor/ composer.lock Tests/Functional/app/cache .idea +/.phpunit.result.cache +/var/ 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/README.md b/README.md index e1563f9..e84a872 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Installation This library is available on [Packagist](https://packagist.org/packages/ddeboer/vatin-bundle): ```bash -$ composer require ddeboer/vatin-bundle +composer require ddeboer/vatin-bundle ``` Then add the bundle to your application: @@ -55,6 +55,8 @@ format. For more information, see [Symfony’s documentation](http://symfony.com Additionally, you can check whether the VAT number is in use: ```php + use Ddeboer\VatinBundle\Validator\Constraints\Vatin; + /** * @Vatin(checkExistence=true) */ @@ -88,7 +90,7 @@ $validator = $container->get('ddeboer_vatin.vatin_validator'); $bool = $validator->isValid('NL123456789B01'); ``` -Additionally check whether the VAT number is in use: +Additionally, check whether the VAT number is in use: ```php $bool = $validator->isValid('NL123456789B01', true); diff --git a/Tests/Functional/app/config/config.yml b/Tests/Functional/app/config/config.yml deleted file mode 100644 index e2f9735..0000000 --- a/Tests/Functional/app/config/config.yml +++ /dev/null @@ -1,5 +0,0 @@ -framework: - secret: ddeboer - test: ~ - validation: - enable_annotations: true \ No newline at end of file diff --git a/composer.json b/composer.json index ce826bd..dee322f 100644 --- a/composer.json +++ b/composer.json @@ -11,21 +11,28 @@ } ], "require": { + "php": ">=7.2", "ddeboer/vatin": "^2.0", - "symfony/framework-bundle": "^3.4.26 || ^4.1.12 || ^5.0", - "symfony/validator": "^3.0 || ^4.0 || ^5.0" + "symfony/http-kernel": "^4.0 || ^5.0 || ^6.0", + "symfony/dependency-injection": "^4.0 || ^5.0 || ^6.0", + "symfony/config": "^4.0 || ^5.0 || ^6.0", + "symfony/validator": "^4.0 || ^5.0 || ^6.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0", + "roave/security-advisories": "dev-latest", + "phpunit/phpunit": "^8.5 || ^9.0", "doctrine/annotations": "^1.2", - "symfony/yaml": "^2.7 || ^3.0 || ^4.0 || ^5.0" + "symfony/framework-bundle": "^5.0 || ^6.0", + "symfony/yaml": "^5.0 || ^6.0" }, "autoload": { "psr-4": { - "Ddeboer\\VatinBundle\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] + "Ddeboer\\VatinBundle\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Ddeboer\\VatinBundle\\Tests\\": "tests" + } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 040fcd5..5e88a28 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,31 +1,31 @@ - +> - ./Tests + ./tests - ./ + ./src - ./Resources - ./Tests + ./src/Resources + ./tests ./vendor - + - \ No newline at end of file + diff --git a/DdeboerVatinBundle.php b/src/DdeboerVatinBundle.php similarity index 100% rename from DdeboerVatinBundle.php rename to src/DdeboerVatinBundle.php diff --git a/DependencyInjection/DdeboerVatinExtension.php b/src/DependencyInjection/DdeboerVatinExtension.php similarity index 94% rename from DependencyInjection/DdeboerVatinExtension.php rename to src/DependencyInjection/DdeboerVatinExtension.php index e54d594..033478f 100644 --- a/DependencyInjection/DdeboerVatinExtension.php +++ b/src/DependencyInjection/DdeboerVatinExtension.php @@ -19,7 +19,7 @@ class DdeboerVatinExtension extends Extension */ public function load(array $configs, ContainerBuilder $container) { - $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); } } diff --git a/Resources/config/services.xml b/src/Resources/config/services.xml similarity index 100% rename from Resources/config/services.xml rename to src/Resources/config/services.xml diff --git a/Validator/Constraints/Vatin.php b/src/Validator/Constraints/Vatin.php similarity index 100% rename from Validator/Constraints/Vatin.php rename to src/Validator/Constraints/Vatin.php diff --git a/Validator/Constraints/VatinValidator.php b/src/Validator/Constraints/VatinValidator.php similarity index 100% rename from Validator/Constraints/VatinValidator.php rename to src/Validator/Constraints/VatinValidator.php diff --git a/Tests/Functional/Model.php b/tests/Functional/Model.php similarity index 99% rename from Tests/Functional/Model.php rename to tests/Functional/Model.php index 27b60d1..b82cc1f 100644 --- a/Tests/Functional/Model.php +++ b/tests/Functional/Model.php @@ -15,4 +15,4 @@ class Model * @Vatin(checkExistence=true) */ public $vatCheckExistence; -} \ No newline at end of file +} diff --git a/Tests/Functional/ValidatorAnnotationTest.php b/tests/Functional/ValidatorAnnotationTest.php similarity index 93% rename from Tests/Functional/ValidatorAnnotationTest.php rename to tests/Functional/ValidatorAnnotationTest.php index c60df61..0291a60 100644 --- a/Tests/Functional/ValidatorAnnotationTest.php +++ b/tests/Functional/ValidatorAnnotationTest.php @@ -14,11 +14,11 @@ class ValidatorAnnotationTest extends WebTestCase */ private $validator; - protected function setUp() + protected function setUp():void { static::bootKernel(); $container = static::$kernel->getContainer(); - $this->validator = $container->get('validator'); + $this->validator = $container->get('test.validator'); } public function testValid() diff --git a/Tests/Functional/app/AppKernel.php b/tests/Functional/app/AppKernel.php similarity index 89% rename from Tests/Functional/app/AppKernel.php rename to tests/Functional/app/AppKernel.php index 7125ab3..dfb3328 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(): iterable { return [ new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), @@ -17,4 +17,4 @@ public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__.'/config/config.yml'); } -} \ No newline at end of file +} diff --git a/Tests/Functional/app/autoload.php b/tests/Functional/app/autoload.php similarity index 100% rename from Tests/Functional/app/autoload.php rename to tests/Functional/app/autoload.php diff --git a/tests/Functional/app/config/config.yml b/tests/Functional/app/config/config.yml new file mode 100644 index 0000000..a69ae49 --- /dev/null +++ b/tests/Functional/app/config/config.yml @@ -0,0 +1,12 @@ +framework: + secret: ddeboer + test: ~ + annotations: + enabled: true + validation: + enable_annotations: true + +services: + test.validator: + alias: validator + public: true diff --git a/Tests/Validator/Constraints/ValidatorTest.php b/tests/Validator/Constraints/ValidatorTest.php similarity index 83% rename from Tests/Validator/Constraints/ValidatorTest.php rename to tests/Validator/Constraints/ValidatorTest.php index 425c4e3..f6761ca 100644 --- a/Tests/Validator/Constraints/ValidatorTest.php +++ b/tests/Validator/Constraints/ValidatorTest.php @@ -2,16 +2,11 @@ namespace Ddeboer\VatinBundle\Tests\Validator\Constraints; +use Ddeboer\Vatin\Validator; use Ddeboer\VatinBundle\Validator\Constraints\Vatin; use Ddeboer\VatinBundle\Validator\Constraints\VatinValidator; -use Ddeboer\Vatin\Validator; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; -// BC for Symfony 2 and Symfony 4. To be removed when support for Symfony 2 is dropped -if (!class_exists('Symfony\Component\Validator\Test\ConstraintValidatorTestCase')) { - class_alias('Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest', 'Symfony\Component\Validator\Test\ConstraintValidatorTestCase'); -} - class ValidatorTest extends ConstraintValidatorTestCase { protected function createValidator()