From 5ea20ce6db01a7df706acd5c0631f0034b06b142 Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Thu, 13 Jun 2024 09:14:55 +0200 Subject: [PATCH 01/15] OP-266 - Add sylius 1.13 support --- .github/workflows/build.yml | 30 +++---- composer.json | 12 +-- tests/Application/config/bundles.php | 7 +- .../config/sylius/1.11/bundles.php | 16 ---- .../sylius/1.11/packages/dev/swiftmailer.yaml | 2 - .../sylius/1.11/packages/jms_serializer.yaml | 4 - .../sylius/1.11/packages/swiftmailer.yaml | 2 - .../1.11/packages/test/swiftmailer.yaml | 6 -- .../packages/test_cached/swiftmailer.yaml | 6 -- .../config/sylius/{1.12 => 1.13}/bundles.php | 5 +- .../packages/dev/jms_serializer.yaml | 0 .../packages/prod/jms_serializer.yaml | 0 .../{1.11 => 1.13}/packages/security.yaml | 82 ++++++++----------- .../sylius/1.13/packages/test/mailer.yaml | 7 ++ .../packages/test/security.yaml | 2 +- 15 files changed, 70 insertions(+), 111 deletions(-) delete mode 100644 tests/Application/config/sylius/1.11/bundles.php delete mode 100644 tests/Application/config/sylius/1.11/packages/dev/swiftmailer.yaml delete mode 100644 tests/Application/config/sylius/1.11/packages/jms_serializer.yaml delete mode 100644 tests/Application/config/sylius/1.11/packages/swiftmailer.yaml delete mode 100644 tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml delete mode 100644 tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml rename tests/Application/config/sylius/{1.12 => 1.13}/bundles.php (51%) rename tests/Application/config/sylius/{1.11 => 1.13}/packages/dev/jms_serializer.yaml (100%) rename tests/Application/config/sylius/{1.11 => 1.13}/packages/prod/jms_serializer.yaml (100%) rename tests/Application/config/sylius/{1.11 => 1.13}/packages/security.yaml (57%) create mode 100644 tests/Application/config/sylius/1.13/packages/test/mailer.yaml rename tests/Application/config/sylius/{1.11 => 1.13}/packages/test/security.yaml (60%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2b259d6..5d54079 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,16 +21,12 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0 ] - symfony: [^5.4, ^6.0] - sylius: [~1.11.0, ~1.12.0] - node: [14.19] - mysql: [5.7, 8.0] + php: ["8.0", "8.1", "8.2", "8.3"] + symfony: ["^5.4", "^6.0"] + sylius: ["~1.12.0", "~1.13.0"] + node: ["18.x", "20.x"] + mysql: ["5.7", "8.0"] - exclude: - - - sylius: ~1.11.0 - symfony: ^6.0 env: APP_ENV: test @@ -38,7 +34,7 @@ jobs: steps: - - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP @@ -51,7 +47,7 @@ jobs: - name: Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: "${{ matrix.node }}" @@ -89,7 +85,7 @@ jobs: - name: Cache Composer - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }} @@ -111,10 +107,14 @@ jobs: name: Install PHP dependencies run: composer install --no-interaction + - + name: Install Behat driver + run: vendor/bin/bdi browser:google-chrome drivers + - name: Get Yarn cache directory id: yarn-cache - run: echo "::set-output name=dir::$(yarn cache dir)" + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - name: Cache Yarn @@ -173,13 +173,13 @@ jobs: - name: Upload Behat logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: Behat logs path: etc/build/ if-no-files-found: ignore - + - name: Failed build Slack notification uses: rtCamp/action-slack-notify@v2 diff --git a/composer.json b/composer.json index 7c2da85..6b3a93e 100644 --- a/composer.json +++ b/composer.json @@ -6,14 +6,14 @@ "license": "MIT", "require": { "php": " ^8.0", - "sylius/sylius": "~1.11.0 || ~1.12.0", - "drewm/mailchimp-api": "^v2.5.4", + "sylius/sylius": "~1.12.0 || ~1.13.0", + "drewm/mailchimp-api": "^2.5.4", "ext-json": "*", "symfony/webpack-encore-bundle": "^1.16" }, "require-dev": { - "behat/behat": "^3.6.1", - "behat/mink-selenium2-driver": "^1.4", + "behat/behat": "^3.7", + "behat/mink-selenium2-driver": "~1.6.0", "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", "friends-of-behat/mink": "^1.8", @@ -39,8 +39,8 @@ "bitbag/coding-standard": "^1.0.0 || ^2.0.0" }, "conflict": { - "doctrine/orm": ">=2.15.2" - }, + "doctrine/orm": ">=2.15.2" + }, "prefer-stable": true, "autoload": { "psr-4": { diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index bae5d11..70ab974 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -61,5 +61,10 @@ Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], - Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true] + Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], + League\FlysystemBundle\FlysystemBundle::class => ['all' => true], + BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], + ]; diff --git a/tests/Application/config/sylius/1.11/bundles.php b/tests/Application/config/sylius/1.11/bundles.php deleted file mode 100644 index d216ac1..0000000 --- a/tests/Application/config/sylius/1.11/bundles.php +++ /dev/null @@ -1,16 +0,0 @@ - ['all' => true], - SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], - Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], - Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true], -]; diff --git a/tests/Application/config/sylius/1.11/packages/dev/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/dev/swiftmailer.yaml deleted file mode 100644 index f438078..0000000 --- a/tests/Application/config/sylius/1.11/packages/dev/swiftmailer.yaml +++ /dev/null @@ -1,2 +0,0 @@ -swiftmailer: - disable_delivery: true diff --git a/tests/Application/config/sylius/1.11/packages/jms_serializer.yaml b/tests/Application/config/sylius/1.11/packages/jms_serializer.yaml deleted file mode 100644 index ed7bc61..0000000 --- a/tests/Application/config/sylius/1.11/packages/jms_serializer.yaml +++ /dev/null @@ -1,4 +0,0 @@ -jms_serializer: - visitors: - xml_serialization: - format_output: '%kernel.debug%' diff --git a/tests/Application/config/sylius/1.11/packages/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/swiftmailer.yaml deleted file mode 100644 index 3bab0d3..0000000 --- a/tests/Application/config/sylius/1.11/packages/swiftmailer.yaml +++ /dev/null @@ -1,2 +0,0 @@ -swiftmailer: - url: '%env(MAILER_URL)%' diff --git a/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml deleted file mode 100644 index c438f4b..0000000 --- a/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml +++ /dev/null @@ -1,6 +0,0 @@ -swiftmailer: - disable_delivery: true - logging: true - spool: - type: file - path: "%kernel.cache_dir%/spool" diff --git a/tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml deleted file mode 100644 index c438f4b..0000000 --- a/tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml +++ /dev/null @@ -1,6 +0,0 @@ -swiftmailer: - disable_delivery: true - logging: true - spool: - type: file - path: "%kernel.cache_dir%/spool" diff --git a/tests/Application/config/sylius/1.12/bundles.php b/tests/Application/config/sylius/1.13/bundles.php similarity index 51% rename from tests/Application/config/sylius/1.12/bundles.php rename to tests/Application/config/sylius/1.13/bundles.php index c157876..fe08cf1 100644 --- a/tests/Application/config/sylius/1.12/bundles.php +++ b/tests/Application/config/sylius/1.13/bundles.php @@ -9,8 +9,5 @@ declare(strict_types=1); return [ - BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], - SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], - Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], - League\FlysystemBundle\FlysystemBundle::class => ['all' => true], + Sylius\Abstraction\StateMachine\SyliusStateMachineAbstractionBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/sylius/1.11/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.13/packages/dev/jms_serializer.yaml similarity index 100% rename from tests/Application/config/sylius/1.11/packages/dev/jms_serializer.yaml rename to tests/Application/config/sylius/1.13/packages/dev/jms_serializer.yaml diff --git a/tests/Application/config/sylius/1.11/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.13/packages/prod/jms_serializer.yaml similarity index 100% rename from tests/Application/config/sylius/1.11/packages/prod/jms_serializer.yaml rename to tests/Application/config/sylius/1.13/packages/prod/jms_serializer.yaml diff --git a/tests/Application/config/sylius/1.11/packages/security.yaml b/tests/Application/config/sylius/1.13/packages/security.yaml similarity index 57% rename from tests/Application/config/sylius/1.11/packages/security.yaml rename to tests/Application/config/sylius/1.13/packages/security.yaml index b2e0632..7458c77 100644 --- a/tests/Application/config/sylius/1.11/packages/security.yaml +++ b/tests/Application/config/sylius/1.13/packages/security.yaml @@ -1,11 +1,5 @@ -parameters: - sylius.security.admin_regex: "^/admin" - sylius.security.shop_regex: "^/(?!admin|new-api|api/.*|api$|media/.*)[^/]++" - sylius.security.new_api_route: "/api/v2" - sylius.security.new_api_regex: "^%sylius.security.new_api_route%" - security: - always_authenticate_before_granting: true + enable_authenticator_manager: true providers: sylius_admin_user_provider: id: sylius.admin_user_provider.email_or_name_based @@ -15,11 +9,8 @@ security: 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: + password_hashers: Sylius\Component\User\Model\UserInterface: argon2i firewalls: admin: @@ -35,58 +26,44 @@ security: default_target_path: sylius_admin_dashboard use_forward: false use_referer: true - csrf_token_generator: security.csrf.token_manager + enable_csrf: true csrf_parameter: _csrf_admin_security_token csrf_token_id: admin_authenticate remember_me: secret: "%env(APP_SECRET)%" - path: /admin + 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 + pattern: "%sylius.security.new_api_admin_regex%/.*" + provider: sylius_api_admin_user_provider stateless: true - anonymous: true + entry_point: jwt json_login: - check_path: "%sylius.security.new_api_route%/admin-user-authentication-token" + check_path: "%sylius.security.new_api_admin_route%/administrators/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 + jwt: true new_api_shop_user: - pattern: "%sylius.security.new_api_route%/shop-user-authentication-token" - provider: sylius_shop_user_provider + pattern: "%sylius.security.new_api_shop_regex%/.*" + provider: sylius_api_shop_user_provider stateless: true - anonymous: true + entry_point: jwt json_login: - check_path: "%sylius.security.new_api_route%/shop-user-authentication-token" + check_path: "%sylius.security.new_api_shop_route%/customers/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 + jwt: true shop: switch_user: { role: ROLE_ALLOWED_TO_SWITCH } @@ -103,7 +80,7 @@ security: default_target_path: sylius_shop_homepage use_forward: false use_referer: true - csrf_token_generator: security.csrf.token_manager + enable_csrf: true csrf_parameter: _csrf_shop_security_token csrf_token_id: shop_authenticate remember_me: @@ -113,26 +90,35 @@ security: remember_me_parameter: _remember_me logout: path: sylius_shop_logout - target: sylius_shop_login + target: sylius_shop_homepage invalidate_session: false - success_handler: sylius.handler.shop_user_logout - anonymous: true dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + + image_resolver: + pattern: ^/media/cache/resolve 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: PUBLIC_ACCESS, 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: PUBLIC_ACCESS, 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.shop_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.admin_regex%/login", role: PUBLIC_ACCESS } + - { path: "%sylius.security.shop_regex%/login", role: PUBLIC_ACCESS } - - { path: "%sylius.security.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: "%sylius.security.shop_regex%/verify", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.shop_regex%/register", role: PUBLIC_ACCESS } + - { path: "%sylius.security.shop_regex%/verify", role: PUBLIC_ACCESS } - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_route%/administrators/reset-password", role: PUBLIC_ACCESS } + - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.new_api_admin_route%/administrators/token", role: PUBLIC_ACCESS } + - { path: "%sylius.security.new_api_user_account_regex%/.*", role: ROLE_USER } + - { path: "%sylius.security.new_api_shop_route%/customers/token", role: PUBLIC_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: PUBLIC_ACCESS } diff --git a/tests/Application/config/sylius/1.13/packages/test/mailer.yaml b/tests/Application/config/sylius/1.13/packages/test/mailer.yaml new file mode 100644 index 0000000..56cc28f --- /dev/null +++ b/tests/Application/config/sylius/1.13/packages/test/mailer.yaml @@ -0,0 +1,7 @@ +framework: + mailer: + dsn: 'null://null' + cache: + pools: + test.mailer_pool: + adapter: cache.adapter.filesystem diff --git a/tests/Application/config/sylius/1.11/packages/test/security.yaml b/tests/Application/config/sylius/1.13/packages/test/security.yaml similarity index 60% rename from tests/Application/config/sylius/1.11/packages/test/security.yaml rename to tests/Application/config/sylius/1.13/packages/test/security.yaml index 21cc377..8ccd542 100644 --- a/tests/Application/config/sylius/1.11/packages/test/security.yaml +++ b/tests/Application/config/sylius/1.13/packages/test/security.yaml @@ -1,3 +1,3 @@ security: - encoders: + password_hashers: sha512: sha512 From 90ed4678dbd237b5e1787e2d2967dfda5f840e91 Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Thu, 13 Jun 2024 09:18:10 +0200 Subject: [PATCH 02/15] OP-266 - Apply ECS fixes and update builds --- .github/workflows/build.yml | 4 ++++ src/Controller/MailchimpController.php | 2 +- src/Controller/NewsletterController.php | 2 +- src/EventListener/CustomerNewsletterListener.php | 4 ++-- src/Handler/NewsletterSubscriptionHandler.php | 16 ++++++++-------- src/Model/WebhookData.php | 4 ++-- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5d54079..3786c5e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -154,6 +154,10 @@ jobs: name: Validate database schema run: (cd tests/Application && bin/console doctrine:schema:validate) + - + name: Run ECS + run: vendor/bin/ecs check src + - name: Run PHPStan run: vendor/bin/phpstan analyse -c phpstan.neon -l 7 src/ diff --git a/src/Controller/MailchimpController.php b/src/Controller/MailchimpController.php index 10f3e3b..776f608 100644 --- a/src/Controller/MailchimpController.php +++ b/src/Controller/MailchimpController.php @@ -31,7 +31,7 @@ final class MailchimpController public function __construct( WebhookValidator $validator, NewsletterSubscriptionInterface $handler, - TranslatorInterface $translator + TranslatorInterface $translator, ) { $this->validator = $validator; $this->handler = $handler; diff --git a/src/Controller/NewsletterController.php b/src/Controller/NewsletterController.php index bfe5343..41ef686 100644 --- a/src/Controller/NewsletterController.php +++ b/src/Controller/NewsletterController.php @@ -38,7 +38,7 @@ public function __construct( NewsletterValidator $validator, TranslatorInterface $translator, NewsletterSubscriptionInterface $handler, - CsrfTokenManager $tokenManager + CsrfTokenManager $tokenManager, ) { $this->validator = $validator; $this->translator = $translator; diff --git a/src/EventListener/CustomerNewsletterListener.php b/src/EventListener/CustomerNewsletterListener.php index f559f0c..be70f68 100644 --- a/src/EventListener/CustomerNewsletterListener.php +++ b/src/EventListener/CustomerNewsletterListener.php @@ -39,7 +39,7 @@ public function customerCreateEvent(GenericEvent $event): void if (!$customer instanceof CustomerInterface) { throw new UnexpectedTypeException( $customer, - CustomerInterface::class + CustomerInterface::class, ); } @@ -62,7 +62,7 @@ public function customerPreUpdateEvent(GenericEvent $event): void if (!$customer instanceof CustomerInterface) { throw new UnexpectedTypeException( $customer, - CustomerInterface::class + CustomerInterface::class, ); } diff --git a/src/Handler/NewsletterSubscriptionHandler.php b/src/Handler/NewsletterSubscriptionHandler.php index 394cec1..e49bd4a 100644 --- a/src/Handler/NewsletterSubscriptionHandler.php +++ b/src/Handler/NewsletterSubscriptionHandler.php @@ -46,7 +46,7 @@ public function __construct( FactoryInterface $customerFactory, EntityManagerInterface $customerManager, MailChimp $mailChimp, - string $listId + string $listId, ) { $this->customerRepository = $customerRepository; $this->customerFactory = $customerFactory; @@ -128,8 +128,8 @@ private function exportNewEmail(string $email): void throw new BadRequestHttpException( sprintf( 'Mailchimp returned false instead of response array, last error : %s', - $this->mailChimp->getLastError() - ) + $this->mailChimp->getLastError(), + ), ); } @@ -144,13 +144,13 @@ private function exportNewEmail(string $email): void 'Mailchimp returned %1$d code, is the MAIL_CHIMP_LIST_ID [ %2$s ] one of available ones: [ %3$s ] ?', Response::HTTP_NOT_FOUND, $this->listId, - $concatenatedList - ) + $concatenatedList, + ), ); } if ($response['status'] !== 'subscribed') { throw new BadRequestHttpException( - sprintf('Response status is %s instead of %s', $response['status'], 'subscribed') + sprintf('Response status is %s instead of %s', $response['status'], 'subscribed'), ); } } @@ -174,8 +174,8 @@ protected function addMailchimpData(string $email): void throw new BadRequestHttpException( sprintf( 'Mailchimp returned false instead of response array, last error : %s', - $this->mailChimp->getLastError() - ) + $this->mailChimp->getLastError(), + ), ); } diff --git a/src/Model/WebhookData.php b/src/Model/WebhookData.php index 27e477d..dfbb2d7 100644 --- a/src/Model/WebhookData.php +++ b/src/Model/WebhookData.php @@ -41,7 +41,7 @@ final class WebhookData public function __construct( string $type, string $firedAt, - array $data + array $data, ) { $this->type = $type; $this->firedAt = $firedAt; @@ -55,7 +55,7 @@ public static function createFromRequest(Request $request): self return new self( $request->get('type', self::TYPE_UNSUBSCRIBE), $request->get('fired_at', $dateString), - $request->get('data', []) + $request->get('data', []), ); } From 3e0c6ab907fb6a47f1dfb6cfb0b1a806cd938ef6 Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Thu, 13 Jun 2024 09:22:33 +0200 Subject: [PATCH 03/15] OP-266 - Remove behat driver from build --- .github/workflows/build.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3786c5e..298597e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -107,10 +107,6 @@ jobs: name: Install PHP dependencies run: composer install --no-interaction - - - name: Install Behat driver - run: vendor/bin/bdi browser:google-chrome drivers - - name: Get Yarn cache directory id: yarn-cache From 22baa2db66d8389f7f05446916ffa9e10c756a62 Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Fri, 14 Jun 2024 07:15:02 +0200 Subject: [PATCH 04/15] OP-266 - Update builds and ecs file --- .github/workflows/build.yml | 2 +- ecs.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 298597e..977d699 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - php: ["8.0", "8.1", "8.2", "8.3"] + php: ["8.1", "8.2", "8.3"] symfony: ["^5.4", "^6.0"] sylius: ["~1.12.0", "~1.13.0"] node: ["18.x", "20.x"] diff --git a/ecs.php b/ecs.php index 9fe162b..abcfbcf 100644 --- a/ecs.php +++ b/ecs.php @@ -2,8 +2,12 @@ declare(strict_types=1); -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symplify\EasyCodingStandard\Config\ECSConfig; -return static function (ContainerConfigurator $containerConfigurator): void { - $containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php'); +return static function (ECSConfig $config): void { + + putenv('ALLOW_BITBAG_OS_HEADER=1'); + + $config->import('vendor/bitbag/coding-standard/ecs.php'); + $config->paths(['src', 'tests']); }; From ba90ce135db14485e49c02b17d441db8476ff5b5 Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Fri, 14 Jun 2024 07:15:29 +0200 Subject: [PATCH 05/15] OP-266 - Fix for behats --- tests/Behat/Fake/AlwaysSuccessMailChimpClient.php | 5 +++++ tests/Behat/Resources/services.yml | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/tests/Behat/Fake/AlwaysSuccessMailChimpClient.php b/tests/Behat/Fake/AlwaysSuccessMailChimpClient.php index ccb8bbb..35767af 100644 --- a/tests/Behat/Fake/AlwaysSuccessMailChimpClient.php +++ b/tests/Behat/Fake/AlwaysSuccessMailChimpClient.php @@ -17,4 +17,9 @@ public function get($method, $args = [], $timeout = self::TIMEOUT) { return ['status' => 'subscribed']; } + + public function getLastError():bool + { + return false; + } } diff --git a/tests/Behat/Resources/services.yml b/tests/Behat/Resources/services.yml index 0a358ed..13c32fc 100644 --- a/tests/Behat/Resources/services.yml +++ b/tests/Behat/Resources/services.yml @@ -1,3 +1,10 @@ imports: - { resource: "contexts.yml" } - { resource: "pages.yml" } + +services: + bitbag_sylius_mailchimp_plugin.drewm.mailchimp: + class: Tests\BitBag\SyliusMailChimpPlugin\Behat\Fake\AlwaysSuccessMailChimpClient + public: true + arguments: + - "%mailchimp.api_key%" From 62b90ed0b09b42e12e75bf1e71ac118eb09ed88f Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Fri, 14 Jun 2024 07:20:40 +0200 Subject: [PATCH 06/15] OP-266 - Apply ECS fixes --- src/Controller/MailchimpController.php | 4 ++-- src/Controller/NewsletterController.php | 4 ++-- src/EventListener/CustomerNewsletterListener.php | 2 +- src/Handler/NewsletterSubscriptionHandler.php | 6 +++--- src/Model/WebhookData.php | 2 +- .../Constraints/UniqueNewsletterEmailValidator.php | 6 +++--- src/Validator/NewsletterValidator.php | 2 +- src/Validator/WebhookValidator.php | 8 ++++++-- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Controller/MailchimpController.php b/src/Controller/MailchimpController.php index 776f608..82be373 100644 --- a/src/Controller/MailchimpController.php +++ b/src/Controller/MailchimpController.php @@ -32,7 +32,7 @@ public function __construct( WebhookValidator $validator, NewsletterSubscriptionInterface $handler, TranslatorInterface $translator, - ) { + ) { $this->validator = $validator; $this->handler = $handler; $this->translator = $translator; @@ -43,7 +43,7 @@ public function webhookAction(Request $request): JsonResponse $webhookData = WebhookData::createFromRequest($request); $errors = $this->validateRequest($webhookData, $request); - if (count($errors) === 0) { + if (0 === count($errors)) { $this->handler->unsubscribeCustomerFromLocalDatabase($webhookData->getData()['email']); return new JsonResponse([ diff --git a/src/Controller/NewsletterController.php b/src/Controller/NewsletterController.php index 41ef686..dbc13e5 100644 --- a/src/Controller/NewsletterController.php +++ b/src/Controller/NewsletterController.php @@ -39,7 +39,7 @@ public function __construct( TranslatorInterface $translator, NewsletterSubscriptionInterface $handler, CsrfTokenManager $tokenManager, - ) { + ) { $this->validator = $validator; $this->translator = $translator; $this->handler = $handler; @@ -65,7 +65,7 @@ public function subscribeAction(Request $request): JsonResponse $errors[] = $this->translator->trans('bitbag_sylius_mailchimp_plugin.ui.invalid_csrf_token'); } - if (count($errors) === 0) { + if (0 === count($errors)) { $this->handler->subscribe($email); return new JsonResponse([ diff --git a/src/EventListener/CustomerNewsletterListener.php b/src/EventListener/CustomerNewsletterListener.php index be70f68..ce52075 100644 --- a/src/EventListener/CustomerNewsletterListener.php +++ b/src/EventListener/CustomerNewsletterListener.php @@ -43,7 +43,7 @@ public function customerCreateEvent(GenericEvent $event): void ); } - $customer->isSubscribedToNewsletter() === false ? $this->unsubscribe($customer) : $this->subscribe($customer); + false === $customer->isSubscribedToNewsletter() ? $this->unsubscribe($customer) : $this->subscribe($customer); } public function customerPostUpdateEvent(GenericEvent $event): void diff --git a/src/Handler/NewsletterSubscriptionHandler.php b/src/Handler/NewsletterSubscriptionHandler.php index e49bd4a..352ea11 100644 --- a/src/Handler/NewsletterSubscriptionHandler.php +++ b/src/Handler/NewsletterSubscriptionHandler.php @@ -47,7 +47,7 @@ public function __construct( EntityManagerInterface $customerManager, MailChimp $mailChimp, string $listId, - ) { + ) { $this->customerRepository = $customerRepository; $this->customerFactory = $customerFactory; $this->customerManager = $customerManager; @@ -135,7 +135,7 @@ private function exportNewEmail(string $email): void Assert::keyExists($response, 'status'); - if ($response['status'] === Response::HTTP_NOT_FOUND) { + if (Response::HTTP_NOT_FOUND === $response['status']) { $validListIds = $this->getValidMailchimpListIds(); $concatenatedList = implode(',', $validListIds); @@ -148,7 +148,7 @@ private function exportNewEmail(string $email): void ), ); } - if ($response['status'] !== 'subscribed') { + if ('subscribed' !== $response['status']) { throw new BadRequestHttpException( sprintf('Response status is %s instead of %s', $response['status'], 'subscribed'), ); diff --git a/src/Model/WebhookData.php b/src/Model/WebhookData.php index dfbb2d7..f10b649 100644 --- a/src/Model/WebhookData.php +++ b/src/Model/WebhookData.php @@ -42,7 +42,7 @@ public function __construct( string $type, string $firedAt, array $data, - ) { + ) { $this->type = $type; $this->firedAt = $firedAt; $this->data = $data; diff --git a/src/Validator/Constraints/UniqueNewsletterEmailValidator.php b/src/Validator/Constraints/UniqueNewsletterEmailValidator.php index 7d2c2e9..4e30c27 100644 --- a/src/Validator/Constraints/UniqueNewsletterEmailValidator.php +++ b/src/Validator/Constraints/UniqueNewsletterEmailValidator.php @@ -34,7 +34,7 @@ public function validate($value, Constraint $constraint): void { Assert::isInstanceOf($constraint, UniqueNewsletterEmail::class); - if ($this->isEmailValid($value) === false) { + if (false === $this->isEmailValid($value)) { $this->context->addViolation($constraint->message); } } @@ -43,11 +43,11 @@ private function isEmailValid(?string $email): bool { $customer = $this->customerRepository->findOneBy(['email' => $email]); - if ($customer instanceof CustomerInterface === false) { + if (false === $customer instanceof CustomerInterface) { return true; } - if ($customer->isSubscribedToNewsletter() === true) { + if (true === $customer->isSubscribedToNewsletter()) { return false; } diff --git a/src/Validator/NewsletterValidator.php b/src/Validator/NewsletterValidator.php index f108aa3..d11bebd 100644 --- a/src/Validator/NewsletterValidator.php +++ b/src/Validator/NewsletterValidator.php @@ -36,7 +36,7 @@ public function validate(?string $email): array $errors = []; - if (count($violations) === 0) { + if (0 === count($violations)) { return $errors; } diff --git a/src/Validator/WebhookValidator.php b/src/Validator/WebhookValidator.php index 98fb4c3..dd55088 100644 --- a/src/Validator/WebhookValidator.php +++ b/src/Validator/WebhookValidator.php @@ -29,7 +29,11 @@ final class WebhookValidator /** @var string */ private $webhookSecret; - public function __construct(ValidatorInterface $validator, string $listId, string $webhookSecret) + public function __construct( + ValidatorInterface $validator, + string $listId, + string $webhookSecret + ) { $this->validator = $validator; $this->listId = $listId; @@ -66,7 +70,7 @@ public function validate(WebhookData $webhookData): array $errors = []; - if (count($violations) === 0) { + if (0 === count($violations)) { return $errors; } From 99b59b32cfd8f734de3972bc2c2374b36a63792d Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Fri, 14 Jun 2024 07:24:04 +0200 Subject: [PATCH 07/15] OP-266 - Apply ECS fixes --- src/Validator/WebhookValidator.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Validator/WebhookValidator.php b/src/Validator/WebhookValidator.php index dd55088..24e0c87 100644 --- a/src/Validator/WebhookValidator.php +++ b/src/Validator/WebhookValidator.php @@ -33,8 +33,7 @@ public function __construct( ValidatorInterface $validator, string $listId, string $webhookSecret - ) - { + ) { $this->validator = $validator; $this->listId = $listId; $this->webhookSecret = $webhookSecret; From 79550c6de57b0f31cbb82a9b4734abd5a838edf9 Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Fri, 14 Jun 2024 07:31:57 +0200 Subject: [PATCH 08/15] OP-266 - Added test .env file --- tests/Application/.env.test | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/Application/.env.test diff --git a/tests/Application/.env.test b/tests/Application/.env.test new file mode 100644 index 0000000..9db5577 --- /dev/null +++ b/tests/Application/.env.test @@ -0,0 +1,11 @@ +APP_ENV=test +APP_SECRET='ch4mb3r0f5ecr3ts' + +DATABASE_URL=sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db + +JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem +JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem +JWT_PASSPHRASE=acme_plugin_development + +MAIL_CHIMP_API_KEY="mailchimp-api-key" +MAIL_CHIMP_LIST_ID="mailchimp-list-id" From b9abba73bfa24f9f1441668374f62497515ad966 Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Fri, 14 Jun 2024 07:41:56 +0200 Subject: [PATCH 09/15] OP-266 - Update builds --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 977d699..26301d1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,6 +31,8 @@ jobs: env: APP_ENV: test DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}" + MAIL_CHIMP_API_KEY: "mailchimp-api-key" + MAIL_CHIMP_LIST_ID: "mailchimp-list-id" steps: - From ebed474f0fbe1dfb9cd2bd44aef5f33afcb0ac0c Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Fri, 14 Jun 2024 07:46:09 +0200 Subject: [PATCH 10/15] OP-266 - Added fix for builds --- .github/workflows/build.yml | 2 -- tests/Application/.env | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26301d1..977d699 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,8 +31,6 @@ jobs: env: APP_ENV: test DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}" - MAIL_CHIMP_API_KEY: "mailchimp-api-key" - MAIL_CHIMP_LIST_ID: "mailchimp-list-id" steps: - diff --git a/tests/Application/.env b/tests/Application/.env index 3716f64..60a35c5 100644 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -36,5 +36,5 @@ MAILER_URL=smtp://localhost MESSENGER_TRANSPORT_DSN=sync:// ###< symfony/messenger ### -MAIL_CHIMP_API_KEY="" -MAIL_CHIMP_LIST_ID="" +MAIL_CHIMP_API_KEY="your-api-key" +MAIL_CHIMP_LIST_ID="your-list-id" From a0cbc1a0aeac44d82d4c8c7f2ba51856409abba2 Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Fri, 14 Jun 2024 07:50:25 +0200 Subject: [PATCH 11/15] OP-266 - Added fix for builds --- .github/workflows/build.yml | 4 ++-- tests/Application/.env | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 977d699..79ca7ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -166,8 +166,8 @@ jobs: - name: Run Behat env: - MAIL_CHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_TOKEN }} - MAIL_CHIMP_LIST_ID: ${{ secrets.MAIL_CHIMP_LIST_ID }} + MAIL_CHIMP_API_KEY: "mailchimp-api-key" + MAIL_CHIMP_LIST_ID: "mailchimp-list-id" MAIL_CHIMP_WEBHOOK_SECRET: ${{ secrets.MAIL_CHIMP_WEBHOOK_SECRET }} run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun diff --git a/tests/Application/.env b/tests/Application/.env index 60a35c5..3716f64 100644 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -36,5 +36,5 @@ MAILER_URL=smtp://localhost MESSENGER_TRANSPORT_DSN=sync:// ###< symfony/messenger ### -MAIL_CHIMP_API_KEY="your-api-key" -MAIL_CHIMP_LIST_ID="your-list-id" +MAIL_CHIMP_API_KEY="" +MAIL_CHIMP_LIST_ID="" From 583a37cf104f9cb43c54100c505501f5da56cd3c Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Fri, 14 Jun 2024 07:54:09 +0200 Subject: [PATCH 12/15] OP-266 - Added missing bitbag header --- tests/Behat/Context/Ui/Shop/MailChimpContext.php | 6 ++++++ tests/Behat/Context/Ui/Shop/NewsletterContext.php | 6 ++++++ tests/Behat/Fake/AlwaysSuccessMailChimpClient.php | 6 ++++++ tests/Behat/Page/Shop/NewsletterPage.php | 6 ++++++ tests/Behat/Page/Shop/NewsletterPageInterface.php | 6 ++++++ tests/Behat/Page/Shop/ProfileUpdatePage.php | 6 ++++++ tests/Behat/Page/Shop/ProfileUpdatePageInterface.php | 6 ++++++ 7 files changed, 42 insertions(+) diff --git a/tests/Behat/Context/Ui/Shop/MailChimpContext.php b/tests/Behat/Context/Ui/Shop/MailChimpContext.php index a4ac1a6..7cd86d6 100644 --- a/tests/Behat/Context/Ui/Shop/MailChimpContext.php +++ b/tests/Behat/Context/Ui/Shop/MailChimpContext.php @@ -1,5 +1,11 @@ Date: Fri, 14 Jun 2024 07:54:39 +0200 Subject: [PATCH 13/15] OP-266 - Update dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6b3a93e..7787e2f 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "description": "MailChimp plugin for Sylius.", "license": "MIT", "require": { - "php": " ^8.0", + "php": " ^8.1", "sylius/sylius": "~1.12.0 || ~1.13.0", "drewm/mailchimp-api": "^2.5.4", "ext-json": "*", From 812de79fcd56129381e043f920b59f1f3782bceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 9 Jul 2024 13:24:18 +0200 Subject: [PATCH 14/15] OP-266 Added a comment to installation.md --- doc/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/installation.md b/doc/installation.md index 0c11786..1d1dbfc 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -102,7 +102,7 @@ Add these javascripts to the layout template that includes your subscription for Clear project cache: ```php -bin/console cache:clear +bin/console cache:clear # if there is an issue with translations displaying correctly, clear the cache again. ``` Update your webpack build: From 0a0b5fcc020d4d1e842b8b247b83bd6bde79cf4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 9 Jul 2024 16:23:14 +0200 Subject: [PATCH 15/15] OP-266 Apply ECS fixes --- tests/Application/config/bundles.php | 1 - tests/Behat/Context/Ui/Shop/MailChimpContext.php | 7 +++++-- .../Behat/Fake/AlwaysSuccessMailChimpClient.php | 16 +++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 70ab974..8c4f575 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -66,5 +66,4 @@ League\FlysystemBundle\FlysystemBundle::class => ['all' => true], BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], - ]; diff --git a/tests/Behat/Context/Ui/Shop/MailChimpContext.php b/tests/Behat/Context/Ui/Shop/MailChimpContext.php index 7cd86d6..36ab382 100644 --- a/tests/Behat/Context/Ui/Shop/MailChimpContext.php +++ b/tests/Behat/Context/Ui/Shop/MailChimpContext.php @@ -36,8 +36,11 @@ final class MailChimpContext implements Context * @param string $apiKey * @param string $listId */ - public function __construct(SharedStorageInterface $sharedStorage, $apiKey, $listId) - { + public function __construct( + SharedStorageInterface $sharedStorage, + $apiKey, + $listId + ) { $this->sharedStorage = $sharedStorage; $this->mailChimp = new AlwaysSuccessMailChimpClient($apiKey); $this->listId = $listId; diff --git a/tests/Behat/Fake/AlwaysSuccessMailChimpClient.php b/tests/Behat/Fake/AlwaysSuccessMailChimpClient.php index 0d979b9..74d91d3 100644 --- a/tests/Behat/Fake/AlwaysSuccessMailChimpClient.php +++ b/tests/Behat/Fake/AlwaysSuccessMailChimpClient.php @@ -14,17 +14,23 @@ final class AlwaysSuccessMailChimpClient extends MailChimp { - public function post($method, $args = [], $timeout = self::TIMEOUT) - { + public function post( + $method, + $args = [], + $timeout = self::TIMEOUT + ) { return ['status' => 'subscribed']; } - public function get($method, $args = [], $timeout = self::TIMEOUT) - { + public function get( + $method, + $args = [], + $timeout = self::TIMEOUT + ) { return ['status' => 'subscribed']; } - public function getLastError():bool + public function getLastError(): bool { return false; }