From 1227709c57878b597d0cce059563d19d8112cb83 Mon Sep 17 00:00:00 2001 From: marekrzytki Date: Fri, 4 Mar 2022 13:05:27 +0100 Subject: [PATCH 1/9] Add Sylius 1.11 support --- composer.json | 5 +- tests/Application/.env | 8 + tests/Application/Kernel.php | 2 +- .../Application/config/api_platform/.gitkeep | 0 .../config/sylius/1.11/bundles.php | 7 + .../1.11/packages/dev/jms_serializer.yaml | 12 ++ .../1.11/packages/prod/jms_serializer.yaml | 10 ++ .../config/sylius/1.11/packages/security.yaml | 148 ++++++++++++++++++ 8 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 tests/Application/config/api_platform/.gitkeep create mode 100644 tests/Application/config/sylius/1.11/bundles.php create mode 100644 tests/Application/config/sylius/1.11/packages/dev/jms_serializer.yaml create mode 100644 tests/Application/config/sylius/1.11/packages/prod/jms_serializer.yaml create mode 100644 tests/Application/config/sylius/1.11/packages/security.yaml diff --git a/composer.json b/composer.json index 902f74e..70f0bf5 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "require": { "php": "^7.4 || ^8.0", "bitbag/shipping-export-plugin": "^1.5", - "sylius/sylius": "~1.9.0 || ~1.10.0", + "sylius/sylius": "~1.9.0 || ~1.10.0 || ~1.11.0", "ext-soap": "*" }, "require-dev": { @@ -41,7 +41,8 @@ "symfony/dotenv": "^4.4 || ^5.2", "symfony/intl": "^4.4 || ^5.2", "symfony/web-profiler-bundle": "^4.4 || ^5.2", - "vimeo/psalm": "4.7.1" + "vimeo/psalm": "4.7.1", + "polishsymfonycommunity/symfony-mocker-container": "^1.0" }, "config": { "sort-packages": true diff --git a/tests/Application/.env b/tests/Application/.env index fbb2f64..bc06239 100644 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -15,6 +15,14 @@ APP_SECRET=EDITME DATABASE_URL=mysql://root@127.0.0.1/sylius_dhl24pl_plugin_%kernel.environment%?serverVersion=5.7 ###< doctrine/doctrine-bundle ### +###> symfony/messenger ### +# Choose one of the transports below +# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages +# MESSENGER_TRANSPORT_DSN=doctrine://default +# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages +MESSENGER_TRANSPORT_DSN=sync:// +###< symfony/messenger ### + ###> lexik/jwt-authentication-bundle ### JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php index a2e3535..9e49a65 100644 --- a/tests/Application/Kernel.php +++ b/tests/Application/Kernel.php @@ -67,7 +67,7 @@ protected function configureRoutes(RouteCollectionBuilder $routes): void protected function getContainerBaseClass(): string { - if ($this->isTestEnvironment()) { + if ($this->isTestEnvironment() && class_exists(MockerContainer::class)) { return MockerContainer::class; } diff --git a/tests/Application/config/api_platform/.gitkeep b/tests/Application/config/api_platform/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Application/config/sylius/1.11/bundles.php b/tests/Application/config/sylius/1.11/bundles.php new file mode 100644 index 0000000..ce7c123 --- /dev/null +++ b/tests/Application/config/sylius/1.11/bundles.php @@ -0,0 +1,7 @@ + ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], + Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], +]; diff --git a/tests/Application/config/sylius/1.11/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.11/packages/dev/jms_serializer.yaml new file mode 100644 index 0000000..2f32a9b --- /dev/null +++ b/tests/Application/config/sylius/1.11/packages/dev/jms_serializer.yaml @@ -0,0 +1,12 @@ +jms_serializer: + visitors: + json_serialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.11/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.11/packages/prod/jms_serializer.yaml new file mode 100644 index 0000000..c288182 --- /dev/null +++ b/tests/Application/config/sylius/1.11/packages/prod/jms_serializer.yaml @@ -0,0 +1,10 @@ +jms_serializer: + visitors: + json_serialization: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.11/packages/security.yaml b/tests/Application/config/sylius/1.11/packages/security.yaml new file mode 100644 index 0000000..1062810 --- /dev/null +++ b/tests/Application/config/sylius/1.11/packages/security.yaml @@ -0,0 +1,148 @@ +parameters: + sylius.security.admin_regex: "^/%sylius_admin.path_name%" + sylius.security.api_regex: "^/api" + sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++" + sylius.security.new_api_route: "/new-api" + sylius.security.new_api_regex: "^%sylius.security.new_api_route%" + sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin" + sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%" + sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/shop" + sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%" + +security: + always_authenticate_before_granting: true + providers: + sylius_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_api_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_chain_provider: + chain: + providers: [sylius_api_shop_user_provider, sylius_api_admin_user_provider] + + encoders: + Sylius\Component\User\Model\UserInterface: argon2i + firewalls: + admin: + switch_user: true + context: admin + pattern: "%sylius.security.admin_regex%" + provider: sylius_admin_user_provider + form_login: + provider: sylius_admin_user_provider + login_path: sylius_admin_login + check_path: sylius_admin_login_check + failure_path: sylius_admin_login + default_target_path: sylius_admin_dashboard + use_forward: false + use_referer: true + csrf_token_generator: security.csrf.token_manager + csrf_parameter: _csrf_admin_security_token + csrf_token_id: admin_authenticate + remember_me: + secret: "%env(APP_SECRET)%" + path: "/%sylius_admin.path_name%" + name: APP_ADMIN_REMEMBER_ME + lifetime: 31536000 + remember_me_parameter: _remember_me + logout: + path: sylius_admin_logout + target: sylius_admin_login + anonymous: true + + new_api_admin_user: + pattern: "%sylius.security.new_api_route%/admin-user-authentication-token" + provider: sylius_admin_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/admin-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api_shop_user: + pattern: "%sylius.security.new_api_route%/shop-user-authentication-token" + provider: sylius_shop_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/shop-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api: + pattern: "%sylius.security.new_api_regex%/*" + provider: sylius_api_chain_provider + stateless: true + anonymous: lazy + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + shop: + switch_user: { role: ROLE_ALLOWED_TO_SWITCH } + context: shop + pattern: "%sylius.security.shop_regex%" + provider: sylius_shop_user_provider + form_login: + success_handler: sylius.authentication.success_handler + failure_handler: sylius.authentication.failure_handler + provider: sylius_shop_user_provider + login_path: sylius_shop_login + check_path: sylius_shop_login_check + failure_path: sylius_shop_login + default_target_path: sylius_shop_homepage + use_forward: false + use_referer: true + csrf_token_generator: security.csrf.token_manager + csrf_parameter: _csrf_shop_security_token + csrf_token_id: shop_authenticate + remember_me: + secret: "%env(APP_SECRET)%" + name: APP_SHOP_REMEMBER_ME + lifetime: 31536000 + remember_me_parameter: _remember_me + logout: + path: sylius_shop_logout + target: sylius_shop_login + invalidate_session: false + success_handler: sylius.handler.shop_user_logout + anonymous: true + + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + + access_control: + - { path: "%sylius.security.admin_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.admin_regex%/_partial", role: ROLE_NO_ACCESS } + - { path: "%sylius.security.shop_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS } + + - { path: "%sylius.security.admin_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.api_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.shop_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + + - { path: "%sylius.security.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.shop_regex%/verify", role: IS_AUTHENTICATED_ANONYMOUSLY } + + - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } + - { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY } From ad02a6dcb289b4a0afed8556dad0038c2e6919a1 Mon Sep 17 00:00:00 2001 From: marekrzytki Date: Fri, 4 Mar 2022 13:05:39 +0100 Subject: [PATCH 2/9] Update build --- .github/workflows/build.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a3fe2d7..28df7e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,19 +9,26 @@ jobs: tests: runs-on: ubuntu-latest - name: "PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}" + name: "Sylius ${{ matrix.sylius}}, PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}" strategy: fail-fast: false matrix: php: [7.4, 8.0] - node: [10.x] + node: [14.x] + sylius: [~1.9.0, ~1.10.0, ~1.11.0] mysql: [5.7, 8.0] exclude: - # Segmentation fault while clearing cache php: 8.0 mysql: 5.7 + - + sylius: ~1.9.0 + php: 8.0 + - + sylius: ~1.11.0 + php: 7.4 env: APP_ENV: test @@ -87,6 +94,12 @@ jobs: key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }} restore-keys: | ${{ runner.os }}-php-${{ matrix.php }}-composer- + + - + name: Restrict Sylius version + if: matrix.sylius != '' + run: composer require "sylius/sylius:${{ matrix.sylius }}" --no-update --no-scripts --no-interaction + - name: Install PHP dependencies run: composer install --no-interaction @@ -133,7 +146,9 @@ jobs: - name: Validate database schema run: (cd tests/Application && bin/console doctrine:schema:validate) - + - + name: Run PHPSpec + run: vendor/bin/phpspec run --ansi -f progress --no-interaction - name: Run Behat run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun \ No newline at end of file From 55522e8355b93187197c6af2f38f5c720e226aac Mon Sep 17 00:00:00 2001 From: marekrzytki Date: Fri, 4 Mar 2022 13:05:48 +0100 Subject: [PATCH 3/9] Remove scrutinizer --- .scrutinizer.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index e6c6037..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,12 +0,0 @@ -build: - nodes: - analysis: - tests: - override: - - php-scrutinizer-run - environment: - variables: - COMPOSER_MEMORY_LIMIT: -1 - -filter: - excluded_paths: [tests/*, spec/*] From d40b73a09f26d496042e38c6a221b8b3282bed89 Mon Sep 17 00:00:00 2001 From: marekrzytki Date: Fri, 4 Mar 2022 13:21:33 +0100 Subject: [PATCH 4/9] Try to fix Sylius 1.9 build --- composer.json | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 70f0bf5..f26e28a 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,21 @@ "polishsymfonycommunity/symfony-mocker-container": "^1.0" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "symfony/thanks": true, + "composer/package-versions-deprecated": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true + } + }, + "conflict": { + "doctrine/dbal": "^3.0", + "symfony/symfony": "4.1.8", + "symfony/browser-kit": "4.1.8", + "symfony/dom-crawler": "4.1.8", + "symfony/routing": "4.1.8", + "symfony/doctrine-bridge": "4.4.16" }, "prefer-stable": true, "autoload": { From a074805897725d95010e7a039161f7046b0ebd1b Mon Sep 17 00:00:00 2001 From: marekrzytki Date: Fri, 4 Mar 2022 14:01:33 +0100 Subject: [PATCH 5/9] Try to fix build - add symfony version and restrict to build --- .github/workflows/build.yml | 10 +++++++++- composer.json | 16 +--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 28df7e2..f49b25c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,13 +9,14 @@ jobs: tests: runs-on: ubuntu-latest - name: "Sylius ${{ matrix.sylius}}, PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}" + name: "Sylius ${{ matrix.sylius }}, Symfony ${{ matrix.symfony }}, PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}" strategy: fail-fast: false matrix: php: [7.4, 8.0] node: [14.x] + symfony: [^4.4, ^5.2] sylius: [~1.9.0, ~1.10.0, ~1.11.0] mysql: [5.7, 8.0] @@ -95,6 +96,13 @@ jobs: restore-keys: | ${{ runner.os }}-php-${{ matrix.php }}-composer- + - + name: Restrict Symfony version + if: matrix.symfony != '' + run: | + composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10" + composer config extra.symfony.require "${{ matrix.symfony }}" + - name: Restrict Sylius version if: matrix.sylius != '' diff --git a/composer.json b/composer.json index f26e28a..70f0bf5 100644 --- a/composer.json +++ b/composer.json @@ -45,21 +45,7 @@ "polishsymfonycommunity/symfony-mocker-container": "^1.0" }, "config": { - "sort-packages": true, - "allow-plugins": { - "symfony/thanks": true, - "composer/package-versions-deprecated": true, - "dealerdirect/phpcodesniffer-composer-installer": true, - "phpstan/extension-installer": true - } - }, - "conflict": { - "doctrine/dbal": "^3.0", - "symfony/symfony": "4.1.8", - "symfony/browser-kit": "4.1.8", - "symfony/dom-crawler": "4.1.8", - "symfony/routing": "4.1.8", - "symfony/doctrine-bridge": "4.4.16" + "sort-packages": true }, "prefer-stable": true, "autoload": { From 35e2f1c3c1430b0f2cb046c1dfa2b116ac43d963 Mon Sep 17 00:00:00 2001 From: marekrzytki Date: Fri, 4 Mar 2022 14:13:15 +0100 Subject: [PATCH 6/9] Add twig as a templating engine --- tests/Application/config/packages/framework.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Application/config/packages/framework.yaml b/tests/Application/config/packages/framework.yaml index 9b44501..3481655 100644 --- a/tests/Application/config/packages/framework.yaml +++ b/tests/Application/config/packages/framework.yaml @@ -1,6 +1,7 @@ framework: secret: '%env(APP_SECRET)%' form: true + templating: { engines: ['twig'] } csrf_protection: true session: handler_id: ~ From 162ce18975d017e7f86c716880751c350d2229e4 Mon Sep 17 00:00:00 2001 From: marekrzytki Date: Fri, 4 Mar 2022 14:23:57 +0100 Subject: [PATCH 7/9] Move templating to Sylius 1.9, add conflict section to composer json --- composer.json | 16 +++++++++++++++- tests/Application/config/packages/framework.yaml | 1 - .../config/sylius/1.9/packages/framework.yaml | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/Application/config/sylius/1.9/packages/framework.yaml diff --git a/composer.json b/composer.json index 70f0bf5..f26e28a 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,21 @@ "polishsymfonycommunity/symfony-mocker-container": "^1.0" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "symfony/thanks": true, + "composer/package-versions-deprecated": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true + } + }, + "conflict": { + "doctrine/dbal": "^3.0", + "symfony/symfony": "4.1.8", + "symfony/browser-kit": "4.1.8", + "symfony/dom-crawler": "4.1.8", + "symfony/routing": "4.1.8", + "symfony/doctrine-bridge": "4.4.16" }, "prefer-stable": true, "autoload": { diff --git a/tests/Application/config/packages/framework.yaml b/tests/Application/config/packages/framework.yaml index 3481655..9b44501 100644 --- a/tests/Application/config/packages/framework.yaml +++ b/tests/Application/config/packages/framework.yaml @@ -1,7 +1,6 @@ framework: secret: '%env(APP_SECRET)%' form: true - templating: { engines: ['twig'] } csrf_protection: true session: handler_id: ~ diff --git a/tests/Application/config/sylius/1.9/packages/framework.yaml b/tests/Application/config/sylius/1.9/packages/framework.yaml new file mode 100644 index 0000000..50603af --- /dev/null +++ b/tests/Application/config/sylius/1.9/packages/framework.yaml @@ -0,0 +1,2 @@ +framework: + templating: { engines: ['twig'] } \ No newline at end of file From cda76d4ba1784f77bd3c19232b8f333e80db3539 Mon Sep 17 00:00:00 2001 From: marekrzytki Date: Fri, 4 Mar 2022 14:30:28 +0100 Subject: [PATCH 8/9] Remove prefer stable from composer json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index f26e28a..2441246 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,6 @@ "symfony/routing": "4.1.8", "symfony/doctrine-bridge": "4.4.16" }, - "prefer-stable": true, "autoload": { "psr-4": { "BitBag\\SyliusDhl24PlShippingExportPlugin\\": "src/", From cb79c8b190bd1537de9b1d6cd573ddbacb474500 Mon Sep 17 00:00:00 2001 From: marekrzytki Date: Fri, 4 Mar 2022 14:39:02 +0100 Subject: [PATCH 9/9] Move templating to symfony 4.4 config --- tests/Application/config/sylius/1.9/packages/framework.yaml | 2 -- tests/Application/config/symfony/4.4/packages/framework.yaml | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 tests/Application/config/sylius/1.9/packages/framework.yaml create mode 100644 tests/Application/config/symfony/4.4/packages/framework.yaml diff --git a/tests/Application/config/sylius/1.9/packages/framework.yaml b/tests/Application/config/sylius/1.9/packages/framework.yaml deleted file mode 100644 index 50603af..0000000 --- a/tests/Application/config/sylius/1.9/packages/framework.yaml +++ /dev/null @@ -1,2 +0,0 @@ -framework: - templating: { engines: ['twig'] } \ No newline at end of file diff --git a/tests/Application/config/symfony/4.4/packages/framework.yaml b/tests/Application/config/symfony/4.4/packages/framework.yaml new file mode 100644 index 0000000..bae81e9 --- /dev/null +++ b/tests/Application/config/symfony/4.4/packages/framework.yaml @@ -0,0 +1,2 @@ +framework: + templating: { engines: ["twig"] } \ No newline at end of file