From 6aeaea4dae83efd2e991602cfbffcdb783cd7af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Mon, 15 Jul 2024 14:55:21 +0200 Subject: [PATCH 01/18] OP-374 Added Sylius 1.13 support --- composer.json | 11 +--- .../sylius/1.11/packages/swiftmailer.yaml | 2 - .../1.11/packages/test/swiftmailer.yaml | 6 -- .../packages/test_cached/swiftmailer.yaml | 6 -- .../config/sylius/{1.11 => 1.13}/bundles.php | 3 +- .../1.13/packages/dev/jms_serializer.yaml | 12 ++++ .../packages/jms_serializer.yaml | 0 .../1.13/packages/prod/jms_serializer.yaml | 10 +++ .../{1.11 => 1.13}/packages/security.yaml | 66 +++++++++---------- .../sylius/1.13/packages/test/mailer.yaml | 7 ++ .../sylius/1.13/packages/test/security.yaml | 3 + 11 files changed, 67 insertions(+), 59 deletions(-) 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.11 => 1.13}/bundles.php (77%) create mode 100644 tests/Application/config/sylius/1.13/packages/dev/jms_serializer.yaml rename tests/Application/config/sylius/{1.11 => 1.13}/packages/jms_serializer.yaml (100%) create mode 100644 tests/Application/config/sylius/1.13/packages/prod/jms_serializer.yaml rename tests/Application/config/sylius/{1.11 => 1.13}/packages/security.yaml (65%) create mode 100644 tests/Application/config/sylius/1.13/packages/test/mailer.yaml create mode 100644 tests/Application/config/sylius/1.13/packages/test/security.yaml diff --git a/composer.json b/composer.json index a9e534e..ffcca6e 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,11 @@ "require": { "php": "^8.0", "bitbag/shipping-export-plugin": "^3.0", - "sylius/sylius": "~1.11.0 || ~1.12.0" + "sylius/sylius": "~1.12.0 || ~1.13.0" }, "require-dev": { - "behat/behat": "^3.6.1", - "behat/mink-selenium2-driver": "^1.4", + "behat/behat": "^3.7", + "behat/mink-selenium2-driver": "~1.6", "bitbag/coding-standard": "^1.0.0 || ^2.0.0 ", "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", @@ -46,11 +46,6 @@ "twig/twig": "^2.10.0" }, "conflict": { - "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", "behat/mink-selenium2-driver": ">=1.7.0" }, "config": { 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 73bba27..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 aaac242..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 aaac242..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.11/bundles.php b/tests/Application/config/sylius/1.13/bundles.php similarity index 77% rename from tests/Application/config/sylius/1.11/bundles.php rename to tests/Application/config/sylius/1.13/bundles.php index 70ca608..561ed0d 100644 --- a/tests/Application/config/sylius/1.11/bundles.php +++ b/tests/Application/config/sylius/1.13/bundles.php @@ -11,6 +11,7 @@ return [ BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], - Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::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.13/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.13/packages/dev/jms_serializer.yaml new file mode 100644 index 0000000..9bdda24 --- /dev/null +++ b/tests/Application/config/sylius/1.13/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/jms_serializer.yaml b/tests/Application/config/sylius/1.13/packages/jms_serializer.yaml similarity index 100% rename from tests/Application/config/sylius/1.11/packages/jms_serializer.yaml rename to tests/Application/config/sylius/1.13/packages/jms_serializer.yaml diff --git a/tests/Application/config/sylius/1.13/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.13/packages/prod/jms_serializer.yaml new file mode 100644 index 0000000..0cc8d8f --- /dev/null +++ b/tests/Application/config/sylius/1.13/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.13/packages/security.yaml similarity index 65% rename from tests/Application/config/sylius/1.11/packages/security.yaml rename to tests/Application/config/sylius/1.13/packages/security.yaml index d0f96b1..842b093 100644 --- a/tests/Application/config/sylius/1.11/packages/security.yaml +++ b/tests/Application/config/sylius/1.13/packages/security.yaml @@ -1,16 +1,5 @@ -parameters: - sylius.security.admin_regex: "^/%sylius_admin.path_name%" - sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|api/.*|api$|media/.*)[^/]++" - sylius.security.new_api_route: "/api/v2" - 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%" - sylius.security.new_api_user_account_route: "%sylius.security.new_api_shop_route%/account" - sylius.security.new_api_user_account_regex: "^%sylius.security.new_api_user_account_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 @@ -20,7 +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 - encoders: + + password_hashers: Sylius\Component\User\Model\UserInterface: argon2i firewalls: admin: @@ -36,7 +26,7 @@ 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: @@ -48,35 +38,33 @@ security: logout: path: sylius_admin_logout target: sylius_admin_login - anonymous: true + new_api_admin_user: 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_admin_route%/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 + jwt: true + new_api_shop_user: 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_shop_route%/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 + jwt: true + shop: switch_user: { role: ROLE_ALLOWED_TO_SWITCH } context: shop @@ -92,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: @@ -102,29 +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)/ 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.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: "%sylius.security.shop_regex%/verify", 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: 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%/reset-password-requests", role: PUBLIC_ACCESS } - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } - - { path: "%sylius.security.new_api_admin_route%/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.new_api_admin_route%/authentication-token", role: PUBLIC_ACCESS } - { path: "%sylius.security.new_api_user_account_regex%/.*", role: ROLE_USER } - - { path: "%sylius.security.new_api_shop_route%/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.new_api_shop_route%/authentication-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.13/packages/test/security.yaml b/tests/Application/config/sylius/1.13/packages/test/security.yaml new file mode 100644 index 0000000..a6f2ff7 --- /dev/null +++ b/tests/Application/config/sylius/1.13/packages/test/security.yaml @@ -0,0 +1,3 @@ +security: + password_hashers: + sha512: sha512 From 25f24674105f7ea6f6a93e19c056449a72b16cae Mon Sep 17 00:00:00 2001 From: Szymon Kostrubiec Date: Mon, 15 Jul 2024 15:10:10 +0200 Subject: [PATCH 02/18] OP-374 - Update readme, add webpack configuration --- doc/installation.md | 74 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/doc/installation.md b/doc/installation.md index 6c78e97..0750f7d 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -128,6 +128,80 @@ $ bin/console assets:install --symlink $ bin/console sylius:theme:assets:install --symlink ``` +### Webpack configuration +#### Installing Webpack package + +1. Before Webpack installation, please create the `config/packages/webpack_encore.yaml` file with a content of: + + ```yaml + webpack_encore: + output_path: '%kernel.project_dir%/public/build/default' + builds: + shop: '%kernel.project_dir%/public/build/shop' + admin: '%kernel.project_dir%/public/build/admin' + inpost_shop: '%kernel.project_dir%/public/build/bitbag/inpost/shop' + inpost_admin: '%kernel.project_dir%/public/build/bitbag/inpost/admin' + ``` + +2. To install Webpack in your application, please run the command below: + + ```bash + $ composer require "symfony/webpack-encore-bundle" + ``` + +3. After installation, please add the line below into `config/bundles.php` file: + + ```php + return [ + ... + Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + ]; + ``` +#### Configuring Webpack + +By a standard, the `webpack.config.js` file should be available in your repository. If not, please use [the Sylius-Standard one](https://github.com/Sylius/Sylius-Standard/blob/1.12/webpack.config.js). + +1. Please setup your `webpack.config.js` file to require the plugin's webpack configuration. To do so, please put the line below somewhere on top of your `webpack.config.js` file: + + ```javascript + const [bitbagInPostShop, bitbagInPostAdmin] = require('./vendor/bitbag/inpost-plugin/webpack.config.js'); + ``` + +2. As next step, please add the imported consts into final module exports: + + ```javascripts + module.exports = [shopConfig, adminConfig, appShopConfig, appAdminConfig, bitbagInPostShop, bitbagInPostAdmin]; + ``` + +3. Next thing is to add the asset configuration into `config/packages/framework.yaml`: + + ```yaml + framework: + assets: + packages: + admin: + json_manifest_path: '%kernel.project_dir%/public/build/admin/manifest.json' + shop: + json_manifest_path: '%kernel.project_dir%/public/build/shop/manifest.json' + app.admin: + json_manifest_path: '%kernel.project_dir%/public/build/app/admin/manifest.json' + app.shop: + json_manifest_path: '%kernel.project_dir%/public/build/app/shop/manifest.json' + inpost_shop: + json_manifest_path: '%kernel.project_dir%/public/build/bitbag/inpost/shop/manifest.json' + inpost_admin: + json_manifest_path: '%kernel.project_dir%/public/build/bitbag/inpost/admin/manifest.json' + ``` +4. Additionally, please add the `"@symfony/webpack-encore": "^1.5.0",` dependency into your `package.json` file. + +5. Now you can run the commands: + + ```bash + $ yarn install + $ yarn encore dev # or prod, depends on your environment + ``` + + ## Testing & running the plugin ```bash From 4162fcc0534cc3f83b6ea512840d017a2a6535ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Mon, 15 Jul 2024 15:48:41 +0200 Subject: [PATCH 03/18] OP-374 - Applied PHPStan config fixes --- composer.json | 8 ++++---- phpstan.neon | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index ffcca6e..9dbc8bc 100644 --- a/composer.json +++ b/composer.json @@ -29,10 +29,10 @@ "friends-of-behat/variadic-extension": "^1.3", "phpspec/phpspec": "^7.0", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "0.12.85", - "phpstan/phpstan-doctrine": "0.12.33", - "phpstan/phpstan-strict-rules": "^0.12.0", - "phpstan/phpstan-webmozart-assert": "0.12.12", + "phpstan/phpstan": "^1.8.1", + "phpstan/phpstan-doctrine": "1.3.69", + "phpstan/phpstan-strict-rules": "^1.3.0", + "phpstan/phpstan-webmozart-assert": "^1.2.0", "phpunit/phpunit": "^9.5", "polishsymfonycommunity/symfony-mocker-container": "^1.0", "symfony/browser-kit": "^5.4 || ^6.0", diff --git a/phpstan.neon b/phpstan.neon index b9cae1f..82e343c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,8 @@ parameters: - reportUnmatchedIgnoredErrors: false - checkMissingIterableValueType: false + level: 8 + + paths: + - src excludePaths: # Makes PHPStan crash @@ -11,4 +13,5 @@ parameters: - 'tests/Application/src/**.php' ignoreErrors: - - '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./' + - identifier: missingType.iterableValue + - identifier: missingType.generics From 432b79dfbff6648d43724a549d3b0bb24b978c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Mon, 15 Jul 2024 16:09:33 +0200 Subject: [PATCH 04/18] OP-374 - Applied ECS fixes --- composer.json | 3 ++- ecs.php | 12 ++++++------ tests/Application/config/bundles.php | 8 ++++++++ tests/Application/public/index.php | 2 +- tests/Behat/Context/Setup/ShippingGatewayContext.php | 1 - .../Behat/Context/Ui/Admin/ShippingMethodContext.php | 1 - tests/Spec/Builder/AddressBuilder.php | 6 +++--- tests/Spec/Builder/OrderBuilder.php | 6 +++--- tests/Spec/Builder/PaymentBuilder.php | 8 ++------ tests/Spec/Builder/PaymentMethodBuilder.php | 7 ++----- tests/Spec/Builder/ShipmentBuilder.php | 6 +++--- tests/Spec/Builder/ShippingExportBuilder.php | 8 ++++---- tests/Spec/Builder/ShippingGatewayBuilder.php | 6 +++--- tests/Spec/Builder/ShippingMethodBuilder.php | 6 ++---- 14 files changed, 39 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index 9dbc8bc..5af3a32 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,8 @@ "twig/twig": "^2.10.0" }, "conflict": { - "behat/mink-selenium2-driver": ">=1.7.0" + "behat/mink-selenium2-driver": ">=1.7.0", + "symplify/easy-coding-standard": ">10.2.10" }, "config": { "sort-packages": true, diff --git a/ecs.php b/ecs.php index 34cb6c5..343e9d9 100644 --- a/ecs.php +++ b/ecs.php @@ -1,13 +1,13 @@ import('vendor/bitbag/coding-standard/ecs.php'); +use Symplify\EasyCodingStandard\Config\ECSConfig; - $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::PATHS, [ +return static function (ECSConfig $ecsConfig): void { + $ecsConfig->import('vendor/bitbag/coding-standard/ecs.php'); + + $ecsConfig->paths([ __DIR__ . '/src', __DIR__ . '/tests', ]); diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 7bcb596..c18c999 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -1,5 +1,13 @@ ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], diff --git a/tests/Application/public/index.php b/tests/Application/public/index.php index 14af8ba..40a1b8e 100644 --- a/tests/Application/public/index.php +++ b/tests/Application/public/index.php @@ -2,9 +2,9 @@ declare(strict_types=1); -use Tests\BitBag\SyliusInPostPlugin\Application\Kernel; use Symfony\Component\ErrorHandler\Debug; use Symfony\Component\HttpFoundation\Request; +use Tests\BitBag\SyliusInPostPlugin\Application\Kernel; require dirname(__DIR__) . '/config/bootstrap.php'; diff --git a/tests/Behat/Context/Setup/ShippingGatewayContext.php b/tests/Behat/Context/Setup/ShippingGatewayContext.php index a204427..1decb8b 100644 --- a/tests/Behat/Context/Setup/ShippingGatewayContext.php +++ b/tests/Behat/Context/Setup/ShippingGatewayContext.php @@ -22,7 +22,6 @@ use Sylius\Component\Product\Resolver\ProductVariantResolverInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\Component\Shipping\Model\ShipmentUnitInterface; -use Webmozart\Assert\Assert; final class ShippingGatewayContext implements Context { diff --git a/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php b/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php index 4b73514..63f335c 100644 --- a/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php +++ b/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php @@ -15,7 +15,6 @@ class ShippingMethodContext implements Context { - private UpdatePageInterface $updatePage; public function __construct( diff --git a/tests/Spec/Builder/AddressBuilder.php b/tests/Spec/Builder/AddressBuilder.php index eeb68e5..eb126d6 100644 --- a/tests/Spec/Builder/AddressBuilder.php +++ b/tests/Spec/Builder/AddressBuilder.php @@ -17,7 +17,7 @@ class AddressBuilder { private AddressInterface $address; - public static function create(): AddressBuilder + public static function create(): self { return new self(); } @@ -27,14 +27,14 @@ private function __construct() $this->address = new Address(); } - public function withPhoneNumber(string $phoneNumber): AddressBuilder + public function withPhoneNumber(string $phoneNumber): self { $this->address->setPhoneNumber($phoneNumber); return $this; } - public function build():AddressInterface + public function build(): AddressInterface { return $this->address; } diff --git a/tests/Spec/Builder/OrderBuilder.php b/tests/Spec/Builder/OrderBuilder.php index fa52ab5..b95b40e 100644 --- a/tests/Spec/Builder/OrderBuilder.php +++ b/tests/Spec/Builder/OrderBuilder.php @@ -18,7 +18,7 @@ class OrderBuilder { private OrderInterface $order; - public static function create(): OrderBuilder + public static function create(): self { return new self(); } @@ -28,14 +28,14 @@ private function __construct() $this->order = new Order(); } - public function withShipment(ShipmentInterface $shipment):OrderBuilder + public function withShipment(ShipmentInterface $shipment): self { $this->order->addShipment($shipment); return $this; } - public function withNumber(string $number): OrderBuilder + public function withNumber(string $number): self { $this->order->setNumber($number); diff --git a/tests/Spec/Builder/PaymentBuilder.php b/tests/Spec/Builder/PaymentBuilder.php index eea6ac8..74f5e34 100644 --- a/tests/Spec/Builder/PaymentBuilder.php +++ b/tests/Spec/Builder/PaymentBuilder.php @@ -10,19 +10,15 @@ namespace Tests\BitBag\SyliusInPostPlugin\Spec\Builder; -use Sylius\Component\Core\Model\Order; -use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\Payment; use Sylius\Component\Core\Model\PaymentInterface; -use Sylius\Component\Core\Model\PaymentMethod; use Sylius\Component\Core\Model\PaymentMethodInterface; -use Sylius\Component\Core\Model\ShipmentInterface; class PaymentBuilder { private PaymentInterface $payment; - public static function create(): PaymentBuilder + public static function create(): self { return new self(); } @@ -32,7 +28,7 @@ private function __construct() $this->payment = new Payment(); } - public function withPaymentMethod(PaymentMethodInterface $paymentMethod): PaymentBuilder + public function withPaymentMethod(PaymentMethodInterface $paymentMethod): self { $this->payment->setMethod($paymentMethod); diff --git a/tests/Spec/Builder/PaymentMethodBuilder.php b/tests/Spec/Builder/PaymentMethodBuilder.php index 5c4e0fd..22b73db 100644 --- a/tests/Spec/Builder/PaymentMethodBuilder.php +++ b/tests/Spec/Builder/PaymentMethodBuilder.php @@ -10,17 +10,14 @@ namespace Tests\BitBag\SyliusInPostPlugin\Spec\Builder; -use Sylius\Component\Core\Model\Order; -use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentMethod; use Sylius\Component\Core\Model\PaymentMethodInterface; -use Sylius\Component\Core\Model\ShipmentInterface; class PaymentMethodBuilder { private PaymentMethodInterface $paymentMethod; - public static function create(): PaymentMethodBuilder + public static function create(): self { return new self(); } @@ -30,7 +27,7 @@ private function __construct() $this->paymentMethod = new PaymentMethod(); } - public function withCode(string $code): PaymentMethodBuilder + public function withCode(string $code): self { $this->paymentMethod->setCode($code); diff --git a/tests/Spec/Builder/ShipmentBuilder.php b/tests/Spec/Builder/ShipmentBuilder.php index 6bded39..1c53774 100644 --- a/tests/Spec/Builder/ShipmentBuilder.php +++ b/tests/Spec/Builder/ShipmentBuilder.php @@ -19,7 +19,7 @@ class ShipmentBuilder { private ShipmentInterface $shipment; - public static function create(): ShipmentBuilder + public static function create(): self { return new self(); } @@ -29,14 +29,14 @@ private function __construct() $this->shipment = new Shipment(); } - public function withShippingMethod(ShippingMethodInterface $shippingMethod): ShipmentBuilder + public function withShippingMethod(ShippingMethodInterface $shippingMethod): self { $this->shipment->setMethod($shippingMethod); return $this; } - public function withOrder(OrderInterface $order): ShipmentBuilder + public function withOrder(OrderInterface $order): self { $this->shipment->setOrder($order); diff --git a/tests/Spec/Builder/ShippingExportBuilder.php b/tests/Spec/Builder/ShippingExportBuilder.php index cad72cd..4293b6a 100644 --- a/tests/Spec/Builder/ShippingExportBuilder.php +++ b/tests/Spec/Builder/ShippingExportBuilder.php @@ -19,7 +19,7 @@ class ShippingExportBuilder { private ShippingExportInterface $shippingExport; - public static function create(): ShippingExportBuilder + public static function create(): self { return new self(); } @@ -29,21 +29,21 @@ private function __construct() $this->shippingExport = new ShippingExport(); } - public function withShipment(ShipmentInterface $shipment): ShippingExportBuilder + public function withShipment(ShipmentInterface $shipment): self { $this->shippingExport->setShipment($shipment); return $this; } - public function withExternalId(string $id): ShippingExportBuilder + public function withExternalId(string $id): self { $this->shippingExport->setExternalId($id); return $this; } - public function withShippingGateway(ShippingGatewayInterface $shippingGateway): ShippingExportBuilder + public function withShippingGateway(ShippingGatewayInterface $shippingGateway): self { $this->shippingExport->setShippingGateway($shippingGateway); diff --git a/tests/Spec/Builder/ShippingGatewayBuilder.php b/tests/Spec/Builder/ShippingGatewayBuilder.php index bba228e..d1b425a 100644 --- a/tests/Spec/Builder/ShippingGatewayBuilder.php +++ b/tests/Spec/Builder/ShippingGatewayBuilder.php @@ -17,7 +17,7 @@ class ShippingGatewayBuilder { private ShippingGatewayInterface $shippingGateway; - public static function create(): ShippingGatewayBuilder + public static function create(): self { return new self(); } @@ -27,14 +27,14 @@ private function __construct() $this->shippingGateway = new ShippingGateway(); } - public function withCode(string $code): ShippingGatewayBuilder + public function withCode(string $code): self { $this->shippingGateway->setCode($code); return $this; } - public function build():ShippingGatewayInterface + public function build(): ShippingGatewayInterface { return $this->shippingGateway; } diff --git a/tests/Spec/Builder/ShippingMethodBuilder.php b/tests/Spec/Builder/ShippingMethodBuilder.php index b72f57e..1cfca40 100644 --- a/tests/Spec/Builder/ShippingMethodBuilder.php +++ b/tests/Spec/Builder/ShippingMethodBuilder.php @@ -10,8 +10,6 @@ namespace Tests\BitBag\SyliusInPostPlugin\Spec\Builder; -use Sylius\Component\Core\Model\Shipment; -use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\Component\Core\Model\ShippingMethod; use Sylius\Component\Core\Model\ShippingMethodInterface; @@ -19,7 +17,7 @@ class ShippingMethodBuilder { private ShippingMethodInterface $shippingMethod; - public static function create(): ShippingMethodBuilder + public static function create(): self { return new self(); } @@ -29,7 +27,7 @@ private function __construct() $this->shippingMethod = new ShippingMethod(); } - public function withCode(string $code): ShippingMethodBuilder + public function withCode(string $code): self { $this->shippingMethod->setCode($code); From 16e9ba4a0eb09e276f28ae78caa212893eef3597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 16 Jul 2024 08:39:11 +0200 Subject: [PATCH 05/18] OP-374 - installation.md updated --- doc/installation.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/installation.md b/doc/installation.md index 0750f7d..1a8b6df 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -139,6 +139,8 @@ $ bin/console sylius:theme:assets:install --symlink builds: shop: '%kernel.project_dir%/public/build/shop' admin: '%kernel.project_dir%/public/build/admin' + app.admin: '%kernel.project_dir%/public/build/app/admin' + app.shop: '%kernel.project_dir%/public/build/app/shop' inpost_shop: '%kernel.project_dir%/public/build/bitbag/inpost/shop' inpost_admin: '%kernel.project_dir%/public/build/bitbag/inpost/admin' ``` From 84dedb73bf7fe18bf5e93c4b20723091b7277ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 16 Jul 2024 08:39:35 +0200 Subject: [PATCH 06/18] OP-374 - build.yml has been updated --- .github/workflows/build.yml | 18 +++++++----------- composer.json | 3 ++- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9b32ddc..86e3336 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,23 +21,19 @@ jobs: strategy: fail-fast: false matrix: - php: [ "8.0" ] + php: [ "8.1", "8.2", "8.3" ] symfony: [ "^5.4", "^6.0" ] - sylius: [ "~1.11.0", "~1.12.0" ] - node: [ "^14.17.x" ] + sylius: [ "~1.12.0", "~1.13.0" ] + node: [ "^18.x", "20.x" ] mysql: [ "8.0" ] - exclude: - - sylius: ~1.11.0 - symfony: "^6.0" - env: APP_ENV: test DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}" steps: - - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP @@ -50,14 +46,14 @@ jobs: - name: Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: "${{ matrix.node }}" - name: Shutdown default MySQL run: sudo service mysql stop - + - name: Setup MySQL uses: mirromutth/mysql-action@v1.1 @@ -180,7 +176,7 @@ jobs: path: etc/build/ if-no-files-found: ignore - - + - name: Failed build Slack notification uses: rtCamp/action-slack-notify@v2 if: ${{ failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }} diff --git a/composer.json b/composer.json index 5af3a32..6008670 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,8 @@ }, "conflict": { "behat/mink-selenium2-driver": ">=1.7.0", - "symplify/easy-coding-standard": ">10.2.10" + "symplify/easy-coding-standard": ">10.2.10", + "doctrine/persistence": "<3.0" }, "config": { "sort-packages": true, From 5495edae229e59083e32fa9a5f8b2e36852a4b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 16 Jul 2024 12:27:56 +0200 Subject: [PATCH 07/18] OP-374 - build.yml has been updated --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 86e3336..7dcbe76 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,11 @@ jobs: sylius: [ "~1.12.0", "~1.13.0" ] node: [ "^18.x", "20.x" ] mysql: [ "8.0" ] - + + exclude: + - sylius: "~1.13.0" + php: "8.0" + env: APP_ENV: test DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}" From 2a22506392f02c2c86306ed109eb8b5b286362b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 16 Jul 2024 12:29:46 +0200 Subject: [PATCH 08/18] OP-374 - installation.md has been updated --- doc/installation.md | 191 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 167 insertions(+), 24 deletions(-) diff --git a/doc/installation.md b/doc/installation.md index 1a8b6df..c901df3 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -37,8 +37,34 @@ bitbag_sylius_inpost_plugin: ``` This plugin was made on top -of [SyliusShippingExportPlugin](https://github.com/BitBagCommerce/SyliusShippingExportPlugin), so please remember to do -the same for it's configuration. +of [SyliusShippingExportPlugin](https://github.com/BitBagCommerce/SyliusShippingExportPlugin). +Typically, Symfony Flex, if you agree, automatically adds the configuration files: +bitbag_shipping_export_plugin.yaml to the config/packages and config/routes directories. +It also adding the appropriate entry to config/bundles.php. +If it doesn't, so please remember to do the same as above for SyliusShippingExportPlugin configuration. + +### Extend entities with parameters + +You can implement this using xml-mapping or attributes. Instructions for both settings are described below. + +#### For doctrine XML-MAPPING: +If you are using doctrine xml-mapping, you have probably already removed the entries +for the entity in config/_sylius.yaml and all entity extensions are in src/Entity. +Add the following entries to config/_sylius.yaml: +``` +sylius_order: + resources: + order: + classes: + model: App\Entity\Order + +sylius_shipping: + resources: + shipping_method: + classes: + model: App\Entity\ShippingMethod + +``` Add trait and interface to your Order and ShippingMethod entity classes: @@ -47,7 +73,7 @@ Add trait and interface to your Order and ShippingMethod entity classes: declare(strict_types=1); -namespace App\Entity\Order; +namespace App\Entity; use BitBag\SyliusInPostPlugin\Model\InPostPointsAwareInterface; use Sylius\Component\Core\Model\Order as BaseOrder; @@ -64,7 +90,7 @@ class Order extends BaseOrder implements InPostPointsAwareInterface declare(strict_types=1); -namespace App\Entity\Shipping; +namespace App\Entity; use BitBag\SyliusInPostPlugin\Model\ShippingMethodImageTrait; use Sylius\Component\Core\Model\ImageAwareInterface; @@ -75,9 +101,19 @@ class ShippingMethod extends BaseShippingMethod implements ImageAwareInterface use ShippingMethodImageTrait; } ``` - -Define new Entity mapping inside your src/Resources/config/doctrine directory. (You can do it with annotations if you -prefer) +Remember to mark it appropriately in the config/doctrine.yaml configuration file. +``` +doctrine: + ... + orm: + ... + mappings: + App: + ... + type: xml + dir: '%kernel.project_dir%/src/Resources/config/doctrine' +``` +Define new Entity mapping inside your src/Resources/config/doctrine directory. ```xml @@ -88,13 +124,13 @@ prefer) xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > - + - - - + + + @@ -105,19 +141,113 @@ prefer) ```xml - - - - + + + + + + + + - +``` +#### You can do it with attributes if you prefer. Remember to mark it appropriately in the config/doctrine.yaml configuration file. +``` +doctrine: + ... + orm: + ... + mappings: + App: + ... + type: attribute + +``` +```php +point; + } + + public function setPoint(?InPostPointInterface $point): void + { + $this->point = $point; + } +} + +``` + +```php +image; + } + + public function setImage(?ImageInterface $image): void + { + $this->image = $image; + } + protected function createTranslation(): ShippingMethodTranslationInterface + { + return new ShippingMethodTranslation(); + } +} + ``` Finish the installation by updating the database schema: @@ -127,6 +257,19 @@ $ bin/console doctrine:migrations:migrate $ bin/console assets:install --symlink $ bin/console sylius:theme:assets:install --symlink ``` +### TWIG configuration +#### Adding files to the template +Copy the files below to the appropriate directories in your template. + +``` +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusAdminBundle/Order/Show/_addresses.html.twig +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusAdminBundle/ShippingMethod/_form.html.twig +``` +``` +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusShopBundle/Checkout/SelectShipping/_choice.html.twig +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusShopBundle/Grid/Action/quickReturn.html.twig +``` ### Webpack configuration #### Installing Webpack package @@ -137,12 +280,12 @@ $ bin/console sylius:theme:assets:install --symlink webpack_encore: output_path: '%kernel.project_dir%/public/build/default' builds: - shop: '%kernel.project_dir%/public/build/shop' admin: '%kernel.project_dir%/public/build/admin' + shop: '%kernel.project_dir%/public/build/shop' app.admin: '%kernel.project_dir%/public/build/app/admin' app.shop: '%kernel.project_dir%/public/build/app/shop' - inpost_shop: '%kernel.project_dir%/public/build/bitbag/inpost/shop' inpost_admin: '%kernel.project_dir%/public/build/bitbag/inpost/admin' + inpost_shop: '%kernel.project_dir%/public/build/bitbag/inpost/shop' ``` 2. To install Webpack in your application, please run the command below: @@ -175,7 +318,7 @@ By a standard, the `webpack.config.js` file should be available in your reposito module.exports = [shopConfig, adminConfig, appShopConfig, appAdminConfig, bitbagInPostShop, bitbagInPostAdmin]; ``` -3. Next thing is to add the asset configuration into `config/packages/framework.yaml`: +3. Next thing is to add the asset configuration into `config/packages/assets.yaml`: ```yaml framework: From bb2baab9a9c6176eabd54e8cf71f972b0953442f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 23 Jul 2024 15:10:57 +0200 Subject: [PATCH 09/18] OP-374 - Sylius 1.13 / Changing Guzzle to HttpClient --- src/Api/WebClient.php | 67 ++++++++++++------- src/Api/WebClientInterface.php | 6 -- src/Controller/AddPointToOrderAction.php | 6 +- .../ShippingExportEventListener.php | 6 +- .../InPostShippingExportConfirmedAction.php | 4 +- src/Exception/InPostException.php | 15 +++++ .../InvalidInPostResponseException.php | 24 +++++++ src/Resources/config/services.xml | 2 + tests/Application/config/packages/mailer.yaml | 3 + 9 files changed, 96 insertions(+), 37 deletions(-) create mode 100644 src/Exception/InPostException.php create mode 100644 src/Exception/InvalidInPostResponseException.php create mode 100644 tests/Application/config/packages/mailer.yaml diff --git a/src/Api/WebClient.php b/src/Api/WebClient.php index 5450e43..f506bbb 100644 --- a/src/Api/WebClient.php +++ b/src/Api/WebClient.php @@ -11,12 +11,13 @@ namespace BitBag\SyliusInPostPlugin\Api; use BitBag\SyliusInPostPlugin\Entity\InPostPoint; +use BitBag\SyliusInPostPlugin\Exception\InvalidInPostResponseException; use BitBag\SyliusInPostPlugin\Model\InPostPointsAwareInterface; use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\ClientException; -use GuzzleHttp\Exception\GuzzleException; -use Psr\Http\Message\ResponseInterface; +use Psr\Http\Client\ClientExceptionInterface; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; use Sylius\Component\Core\Model\AddressInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; @@ -25,7 +26,11 @@ final class WebClient implements WebClientInterface { - private Client $apiClient; + private ClientInterface $apiClient; + + private RequestFactoryInterface $requestFactory; + + private StreamFactoryInterface $streamFactory; private ?string $organizationId = null; @@ -37,9 +42,15 @@ final class WebClient implements WebClientInterface private string $labelType = 'normal'; - public function __construct(Client $client, string $labelType) - { + public function __construct( + ClientInterface $client, + RequestFactoryInterface $requestFactory, + StreamFactoryInterface $streamFactory, + string $labelType + ) { $this->apiClient = $client; + $this->requestFactory = $requestFactory; + $this->streamFactory = $streamFactory; $this->labelType = $labelType; } @@ -188,9 +199,8 @@ public function getAuthorizedHeaderWithContentType(): array } /** - * @return mixed - * - * @throws GuzzleException + * @throws InvalidInPostResponseException + * @throws ClientExceptionInterface */ public function request( string $method, @@ -198,20 +208,31 @@ public function request( array $data = [], bool $returnJson = true ) { - $options = [ - 'json' => $data, - 'headers' => $this->getAuthorizedHeaderWithContentType(), - ]; + $header = $this->getAuthorizedHeaderWithContentType(); try { - $result = $this->apiClient->request($method, $url, $options); - } catch (ClientException $exception) { - /** @var ?ResponseInterface $result */ - $result = $exception->getResponse(); - - throw new ClientException( - null !== $result ? (string) $result->getBody() : 'Request failed for url' . $url, - $exception->getRequest() + $request = $this->requestFactory + ->createRequest($method, $url) + ->withHeader('Content-Type', $header['Content-Type']) + ->withHeader('Authorization', $header['Authorization']) + ->withBody($this->streamFactory->createStream(json_encode($data))); + + $result = $this->apiClient->sendRequest($request); + $response = json_decode((string) $result->getBody(), true); + + if (201 < $result->getStatusCode()) { + throw new InvalidInPostResponseException(); + } + } catch (InvalidInPostResponseException $e) { + $error_details = $response['details'] ?? '[]'; + + throw new InvalidInPostResponseException( + sprintf( + '%s %s; details: %s', + $e->getMessage(), + $e->getErrorMessage(), + print_r($error_details, true) + ) ); } @@ -219,7 +240,7 @@ public function request( return (string) $result->getBody(); } - return \GuzzleHttp\json_decode((string) $result->getBody(), true); + return $response; } private function getAdditionalServices(): array diff --git a/src/Api/WebClientInterface.php b/src/Api/WebClientInterface.php index 9e9c06d..60e398d 100644 --- a/src/Api/WebClientInterface.php +++ b/src/Api/WebClientInterface.php @@ -11,7 +11,6 @@ namespace BitBag\SyliusInPostPlugin\Api; use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface; -use GuzzleHttp\Exception\GuzzleException; use Sylius\Component\Core\Model\ShipmentInterface; interface WebClientInterface @@ -80,11 +79,6 @@ public function getAuthorizedHeaderWithContentType(): array; public function createShipment(ShipmentInterface $shipment): array; - /** - * @return mixed|string - * - * @throws GuzzleException - */ public function request( string $method, string $url, diff --git a/src/Controller/AddPointToOrderAction.php b/src/Controller/AddPointToOrderAction.php index 2f86c75..fd27623 100644 --- a/src/Controller/AddPointToOrderAction.php +++ b/src/Controller/AddPointToOrderAction.php @@ -12,9 +12,9 @@ use BitBag\SyliusInPostPlugin\Api\WebClientInterface; use BitBag\SyliusInPostPlugin\Entity\InPostPointInterface; +use BitBag\SyliusInPostPlugin\Exception\InPostException; use BitBag\SyliusInPostPlugin\Model\InPostPointsAwareInterface; use Doctrine\ORM\EntityManagerInterface; -use GuzzleHttp\Exception\ClientException; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Sylius\Component\Order\Context\CartContextInterface; @@ -84,8 +84,8 @@ private function addPoint(Request $request, InPostPointsAwareInterface $order): try { $pointData = $this->client->getPointByName($name); - } catch (ClientException $exception) { - $data = \GuzzleHttp\json_decode($exception->getMessage(), true); + } catch (InPostException $exception) { + $data = json_decode($exception->getMessage(), true); return new JsonResponse($data['message'], Response::HTTP_BAD_REQUEST); } diff --git a/src/EventListener/ShippingExportEventListener.php b/src/EventListener/ShippingExportEventListener.php index 090c990..d53785a 100644 --- a/src/EventListener/ShippingExportEventListener.php +++ b/src/EventListener/ShippingExportEventListener.php @@ -12,9 +12,9 @@ use BitBag\SyliusInPostPlugin\Api\WebClientInterface; use BitBag\SyliusInPostPlugin\EventListener\ShippingExportEventListener\InPostShippingExportActionProviderInterface; +use BitBag\SyliusInPostPlugin\Exception\InPostException; use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface; use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface; -use GuzzleHttp\Exception\ClientException; use Psr\Log\LoggerInterface; use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; use Sylius\Component\Core\Model\ShipmentInterface; @@ -73,7 +73,7 @@ public function exportShipment(ResourceControllerEvent $exportShipmentEvent): vo if (null === $shippingExport->getExternalId()) { try { $createShipmentResponse = $this->webClient->createShipment($shipment); - } catch (ClientException $exception) { + } catch (InPostException $exception) { $this->requestStack->getSession()->getBag('flashes')->add('error', 'bitbag.ui.shipping_export_error'); $this->logError($exception, $shipment); @@ -85,7 +85,7 @@ public function exportShipment(ResourceControllerEvent $exportShipmentEvent): vo try { $shipmentData = $this->webClient->getShipmentById((int) ($shippingExport->getExternalId())); - } catch (ClientException $exception) { + } catch (InPostException $exception) { $this->requestStack->getSession()->getBag('flashes')->add('error', 'bitbag.ui.shipping_export_error'); $this->logError($exception, $shipment); diff --git a/src/EventListener/ShippingExportEventListener/InPostShippingExportConfirmedAction.php b/src/EventListener/ShippingExportEventListener/InPostShippingExportConfirmedAction.php index 44d286a..1377fd9 100644 --- a/src/EventListener/ShippingExportEventListener/InPostShippingExportConfirmedAction.php +++ b/src/EventListener/ShippingExportEventListener/InPostShippingExportConfirmedAction.php @@ -11,9 +11,9 @@ namespace BitBag\SyliusInPostPlugin\EventListener\ShippingExportEventListener; use BitBag\SyliusInPostPlugin\Api\WebClientInterface; +use BitBag\SyliusInPostPlugin\Exception\InPostException; use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface; use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepositoryInterface; -use GuzzleHttp\Exception\ClientException; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\ShipmentInterface; use Symfony\Component\Filesystem\Filesystem; @@ -55,7 +55,7 @@ public function __construct( } /** - * @throws ClientException + * @throws InPostException */ public function execute(ShippingExportInterface $shippingExport): void { diff --git a/src/Exception/InPostException.php b/src/Exception/InPostException.php new file mode 100644 index 0000000..3e54d86 --- /dev/null +++ b/src/Exception/InPostException.php @@ -0,0 +1,15 @@ +getFile(), + $this->getCode(), + $this->getLine(), + ); + } +} diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index cfbd832..5ae2a2d 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -38,6 +38,8 @@ class="BitBag\SyliusInPostPlugin\Api\WebClient" id="bitbag.sylius_inpost_plugin.api.web_client" > + + %bitbag.inpost.label_type% diff --git a/tests/Application/config/packages/mailer.yaml b/tests/Application/config/packages/mailer.yaml new file mode 100644 index 0000000..0a0697c --- /dev/null +++ b/tests/Application/config/packages/mailer.yaml @@ -0,0 +1,3 @@ +framework: + mailer: + dsn: '%env(MAILER_DSN)%' From 4b0bfb566a7998d375920d5e219c3496aa16f2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 23 Jul 2024 16:15:52 +0200 Subject: [PATCH 10/18] OP-374 - PHPSpec fixes --- spec/Api/WebClientSpec.php | 12 +++++++++--- .../ShippingExportEventListenerSpec.php | 6 +++--- src/Resources/config/services.xml | 6 ++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/spec/Api/WebClientSpec.php b/spec/Api/WebClientSpec.php index d3cb8c5..e93737a 100644 --- a/spec/Api/WebClientSpec.php +++ b/spec/Api/WebClientSpec.php @@ -13,8 +13,10 @@ use BitBag\SyliusInPostPlugin\Api\WebClient; use BitBag\SyliusInPostPlugin\Api\WebClientInterface; use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface; -use GuzzleHttp\Client; +use Psr\Http\Client\ClientInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; final class WebClientSpec extends ObjectBehavior { @@ -26,9 +28,13 @@ final class WebClientSpec extends ObjectBehavior public const LABEL_TYPE = "normal"; - public function let(Client $client): void + public function let( + ClientInterface $client, + RequestFactoryInterface $requestFactory, + StreamFactoryInterface $streamFactory, + ): void { - $this->beConstructedWith($client,self::LABEL_TYPE); + $this->beConstructedWith($client, $requestFactory, $streamFactory, self::LABEL_TYPE); } public function it_is_initializable(): void diff --git a/spec/EventListener/ShippingExportEventListenerSpec.php b/spec/EventListener/ShippingExportEventListenerSpec.php index c5c8494..6476d99 100644 --- a/spec/EventListener/ShippingExportEventListenerSpec.php +++ b/spec/EventListener/ShippingExportEventListenerSpec.php @@ -14,7 +14,7 @@ use BitBag\SyliusInPostPlugin\EventListener\ShippingExportEventListener; use BitBag\SyliusInPostPlugin\EventListener\ShippingExportEventListener\InPostShippingExportActionInterface; use BitBag\SyliusInPostPlugin\EventListener\ShippingExportEventListener\InPostShippingExportActionProviderInterface; -use GuzzleHttp\Exception\ClientException; +use BitBag\SyliusInPostPlugin\Exception\InvalidInPostResponseException; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Psr\Log\LoggerInterface; @@ -128,7 +128,7 @@ public function it_should_handle_when_create_shipment_throws_exception( $event->getSubject()->willReturn($shippingExport); $webClient->setShippingGateway($shippingGateway); - $webClient->createShipment($shipment)->willThrow(ClientException::class); + $webClient->createShipment($shipment)->willThrow(InvalidInPostResponseException::class); $requestStack->getSession()->willReturn($session); $session->getBag('flashes')->willReturn($flashBag); $flashBag->add(self::ERROR, self::SHIPPING_EXPORT_ERROR_MESSAGE)->shouldBeCalled(); @@ -156,7 +156,7 @@ public function it_should_handle_when_get_shipment_by_id_throws_exception( $webClient->setShippingGateway($shippingGateway); $webClient->createShipment($shipment)->willReturn(self::EXPECTED_CREATE_SHIPMENT_RESPONSE); - $webClient->getShipmentById(self::SHIPMENT_ID)->willThrow(ClientException::class); + $webClient->getShipmentById(self::SHIPMENT_ID)->willThrow(InvalidInPostResponseException::class); $requestStack->getSession()->willReturn($session); $session->getBag('flashes')->willReturn($flashBag); $flashBag->add(self::ERROR, self::SHIPPING_EXPORT_ERROR_MESSAGE)->shouldBeCalled(); diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 5ae2a2d..e122c86 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -6,6 +6,8 @@ + + - - + + %bitbag.inpost.label_type% From ebe8672a0685fb1990e169fdb4f5643ac83ada96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 23 Jul 2024 16:15:59 +0200 Subject: [PATCH 11/18] OP-374 - Behat fixes --- features/exporting_shipping_data_to_api_inpost.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/exporting_shipping_data_to_api_inpost.feature b/features/exporting_shipping_data_to_api_inpost.feature index ab03cd7..6679f79 100644 --- a/features/exporting_shipping_data_to_api_inpost.feature +++ b/features/exporting_shipping_data_to_api_inpost.feature @@ -13,7 +13,7 @@ Feature: Managing shipping gateway And it has "Organization ID" field set to "123" And it has "Environment" field set to "sandbox" And it has "Service" field set to "inpost_courier_standard" - And the store has a product "Chicken" priced at "$2" in "Web-US" channel + And the store has a product "Chicken" priced at "$2.00" in "Web-US" channel And customer "user@bitbag.pl" has placed 5 orders on the "Web-US" channel in each buying 5 "Chicken" products And the customer set the shipping address "Mike Ross" addressed it to "350 5th Ave", "10118" "New York" in the "United States" to orders And those orders were placed with "Inpost" shipping method From 512f3f6330cf26a6466239d0816e090e0f764fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Tue, 23 Jul 2024 16:16:15 +0200 Subject: [PATCH 12/18] OP-374 - PHPStan fixes --- phpstan.neon | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 82e343c..dbde899 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,6 +4,9 @@ parameters: paths: - src + reportUnmatchedIgnoredErrors: false + treatPhpDocTypesAsCertain: false + excludePaths: # Makes PHPStan crash - 'src/DependencyInjection/Configuration.php' From d231d27b08c28295ba929ed89829a109cff88003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Wed, 24 Jul 2024 08:12:43 +0200 Subject: [PATCH 13/18] OP-374 - Services / bundles fixed --- composer.json | 2 ++ src/Resources/config/services.xml | 1 + tests/Application/config/bundles.php | 1 - 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6008670..9f2c276 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,8 @@ "phpstan/phpstan-webmozart-assert": "^1.2.0", "phpunit/phpunit": "^9.5", "polishsymfonycommunity/symfony-mocker-container": "^1.0", + "nyholm/psr7": "^1.8", + "symfony/http-client": "^5.4 || ^6.0", "symfony/browser-kit": "^5.4 || ^6.0", "symfony/debug-bundle": "^5.4 || ^6.0", "symfony/dotenv": "^5.4 || ^6.0", diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index e122c86..3faab35 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -6,6 +6,7 @@ + ['all' => true], SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], - Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true], ]; From 658815d10172eb0b6422b46924e02b6f3f80b93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Wed, 24 Jul 2024 09:12:44 +0200 Subject: [PATCH 14/18] OP-374 - ECS has been upgraded / ECS fixes --- composer.json | 3 +-- ecs.php | 11 +++++------ src/Api/WebClient.php | 19 ++++++++++--------- src/Api/WebClientInterface.php | 11 ++++++----- src/BitBagSyliusInPostPlugin.php | 7 +++++++ src/Checker/ShippingMethodChecker.php | 7 ++++--- .../ShippingMethodCheckerInterface.php | 7 ++++--- src/Controller/AddPointToOrderAction.php | 11 ++++++----- .../BitBagSyliusInPostPluginExtension.php | 7 +++++++ src/DependencyInjection/Configuration.php | 7 +++++++ src/Entity/InPostPoint.php | 9 +++++---- src/Entity/InPostPointInterface.php | 9 +++++---- src/Entity/ShippingMethodImage.php | 7 ++++--- src/Entity/ShippingMethodImageInterface.php | 7 ++++--- src/EventListener/ImageUploadListener.php | 7 ++++--- .../ShippingExportEventListener.php | 13 +++++++------ .../InPostShippingExportActionInterface.php | 7 ++++--- .../InPostShippingExportActionProvider.php | 7 ++++--- ...tShippingExportActionProviderInterface.php | 7 ++++--- .../InPostShippingExportConfirmedAction.php | 11 ++++++----- .../InPostShippingExportDefaultAction.php | 7 ++++--- src/Exception/InPostException.php | 9 +++++---- .../InvalidInPostResponseException.php | 9 +++++---- .../Extension/SelectPaymentTypeExtension.php | 7 ++++--- .../Extension/SelectShippingTypeExtension.php | 7 ++++--- .../Extension/ShippingMethodTypeExtension.php | 7 ++++--- src/Form/Type/ShippingGatewayType.php | 9 +++++---- src/Form/Type/ShippingMethodImageType.php | 7 ++++--- src/Model/InPostPointsAwareInterface.php | 7 +++++++ src/Model/OrderPointTrait.php | 9 +++++---- src/Model/ShippingMethodImageTrait.php | 7 ++++--- src/Resolver/IsQuickReturnResolver.php | 7 ++++--- .../IsQuickReturnResolverInterface.php | 7 +++++++ src/Resolver/OrganizationIdResolver.php | 7 ++++--- .../OrganizationIdResolverInterface.php | 7 +++++++ .../ShippingInpostCodeExtension.php | 9 +++++---- .../HasAllowedPaymentMethodInPostOrder.php | 7 ++++--- .../Constraint/HasPhoneNumberInPostOrder.php | 7 ++++--- .../HasValidPhoneNumberInPostOrder.php | 7 ++++--- ...lowedPaymentMethodInPostOrderValidator.php | 7 ++++--- .../HasPhoneNumberInPostOrderValidator.php | 7 ++++--- ...asValidPhoneNumberInPostOrderValidator.php | 7 ++++--- tests/Application/config/bootstrap.php | 7 +++++++ tests/Application/config/bundles.php | 7 ++++--- .../config/sylius/1.12/bundles.php | 9 +++++---- .../config/sylius/1.13/bundles.php | 9 +++++---- tests/Application/public/index.php | 7 +++++++ tests/Application/src/Entity/Order.php | 9 +++++---- .../Application/src/Entity/ShippingMethod.php | 7 ++++--- .../Context/Setup/ShippingGatewayContext.php | 11 ++++++----- .../Ui/Admin/ShippingExportContext.php | 11 ++++++----- .../Ui/Admin/ShippingGatewayContext.php | 13 +++++++------ .../Ui/Admin/ShippingMethodContext.php | 9 +++++---- tests/Behat/Mocker/InPostApiMocker.php | 11 ++++++----- .../Page/Admin/ShippingGateway/CreatePage.php | 9 +++++---- .../ShippingGateway/CreatePageInterface.php | 9 +++++---- .../Page/Admin/ShippingMethod/UpdatePage.php | 11 ++++++----- .../ShippingMethod/UpdatePageInterface.php | 9 +++++---- tests/Spec/Builder/AddressBuilder.php | 7 ++++--- tests/Spec/Builder/OrderBuilder.php | 7 ++++--- tests/Spec/Builder/PaymentBuilder.php | 7 ++++--- tests/Spec/Builder/PaymentMethodBuilder.php | 7 ++++--- tests/Spec/Builder/ShipmentBuilder.php | 7 ++++--- tests/Spec/Builder/ShippingExportBuilder.php | 7 ++++--- tests/Spec/Builder/ShippingGatewayBuilder.php | 7 ++++--- tests/Spec/Builder/ShippingMethodBuilder.php | 7 ++++--- 66 files changed, 326 insertions(+), 216 deletions(-) diff --git a/composer.json b/composer.json index 9f2c276..1fced54 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require-dev": { "behat/behat": "^3.7", "behat/mink-selenium2-driver": "~1.6", - "bitbag/coding-standard": "^1.0.0 || ^2.0.0 ", + "bitbag/coding-standard": "^3.0.0", "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", "friends-of-behat/mink": "^1.8", @@ -49,7 +49,6 @@ }, "conflict": { "behat/mink-selenium2-driver": ">=1.7.0", - "symplify/easy-coding-standard": ">10.2.10", "doctrine/persistence": "<3.0" }, "config": { diff --git a/ecs.php b/ecs.php index 343e9d9..abcfbcf 100644 --- a/ecs.php +++ b/ecs.php @@ -4,11 +4,10 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; -return static function (ECSConfig $ecsConfig): void { - $ecsConfig->import('vendor/bitbag/coding-standard/ecs.php'); +return static function (ECSConfig $config): void { - $ecsConfig->paths([ - __DIR__ . '/src', - __DIR__ . '/tests', - ]); + putenv('ALLOW_BITBAG_OS_HEADER=1'); + + $config->import('vendor/bitbag/coding-standard/ecs.php'); + $config->paths(['src', 'tests']); }; diff --git a/src/Api/WebClient.php b/src/Api/WebClient.php index f506bbb..1874ed6 100644 --- a/src/Api/WebClient.php +++ b/src/Api/WebClient.php @@ -1,10 +1,11 @@ apiClient = $client; $this->requestFactory = $requestFactory; @@ -206,7 +207,7 @@ public function request( string $method, string $url, array $data = [], - bool $returnJson = true + bool $returnJson = true, ) { $header = $this->getAuthorizedHeaderWithContentType(); @@ -231,8 +232,8 @@ public function request( '%s %s; details: %s', $e->getMessage(), $e->getErrorMessage(), - print_r($error_details, true) - ) + print_r($error_details, true), + ), ); } @@ -351,7 +352,7 @@ private function resolveHouseNumber(AddressInterface $address): string 'Street "%s" is invalid. The street format must be something like %s, where %d is the house number.', $street, '"Opolska 45"', - 45 + 45, )); return end($streetParts); diff --git a/src/Api/WebClientInterface.php b/src/Api/WebClientInterface.php index 60e398d..0c6e25c 100644 --- a/src/Api/WebClientInterface.php +++ b/src/Api/WebClientInterface.php @@ -1,10 +1,11 @@ orderRepository = $orderRepository; $this->inPostPointFactory = $inPostPointFactory; diff --git a/src/DependencyInjection/BitBagSyliusInPostPluginExtension.php b/src/DependencyInjection/BitBagSyliusInPostPluginExtension.php index 272d89a..79d75a7 100644 --- a/src/DependencyInjection/BitBagSyliusInPostPluginExtension.php +++ b/src/DependencyInjection/BitBagSyliusInPostPluginExtension.php @@ -1,5 +1,12 @@ webClient = $webClient; $this->shippingExportActionProvider = $shippingExportActionProvider; @@ -118,7 +119,7 @@ private function logError(\Exception $exception, ShipmentInterface $shipment): v '%s %s: %s', '[InPostPlugin] Error while exporting shipment for order number', $order->getNumber(), - $exception->getMessage() + $exception->getMessage(), ); $this->logger->error($message); diff --git a/src/EventListener/ShippingExportEventListener/InPostShippingExportActionInterface.php b/src/EventListener/ShippingExportEventListener/InPostShippingExportActionInterface.php index 32e129e..b8ff9da 100644 --- a/src/EventListener/ShippingExportEventListener/InPostShippingExportActionInterface.php +++ b/src/EventListener/ShippingExportEventListener/InPostShippingExportActionInterface.php @@ -1,9 +1,10 @@ shippingExportRepository = $shippingExportRepository; $this->webClient = $webClient; @@ -100,7 +101,7 @@ private function getFilename(ShippingExportInterface $shippingExport): string [ $shipment->getId(), $order->getNumber(), - ] + ], ); } diff --git a/src/EventListener/ShippingExportEventListener/InPostShippingExportDefaultAction.php b/src/EventListener/ShippingExportEventListener/InPostShippingExportDefaultAction.php index 933b77a..1cc95c4 100644 --- a/src/EventListener/ShippingExportEventListener/InPostShippingExportDefaultAction.php +++ b/src/EventListener/ShippingExportEventListener/InPostShippingExportDefaultAction.php @@ -1,9 +1,10 @@ isQuickReturnResolver = $isQuickReturnResolver; $this->organizationIdResolver = $organizationIdResolver; diff --git a/src/Validator/Constraint/HasAllowedPaymentMethodInPostOrder.php b/src/Validator/Constraint/HasAllowedPaymentMethodInPostOrder.php index 54e2bcd..6819446 100644 --- a/src/Validator/Constraint/HasAllowedPaymentMethodInPostOrder.php +++ b/src/Validator/Constraint/HasAllowedPaymentMethodInPostOrder.php @@ -1,9 +1,10 @@ defaultVariantResolver = $productVariantResolver; $this->shipmentRepository = $shipmentRepository; diff --git a/tests/Behat/Context/Ui/Admin/ShippingExportContext.php b/tests/Behat/Context/Ui/Admin/ShippingExportContext.php index 00d2557..0b0e852 100644 --- a/tests/Behat/Context/Ui/Admin/ShippingExportContext.php +++ b/tests/Behat/Context/Ui/Admin/ShippingExportContext.php @@ -1,10 +1,11 @@ inPostApiMocker = $inPostApiMocker; $this->indexPage = $indexPage; diff --git a/tests/Behat/Context/Ui/Admin/ShippingGatewayContext.php b/tests/Behat/Context/Ui/Admin/ShippingGatewayContext.php index b5f73ec..1950a74 100644 --- a/tests/Behat/Context/Ui/Admin/ShippingGatewayContext.php +++ b/tests/Behat/Context/Ui/Admin/ShippingGatewayContext.php @@ -1,10 +1,11 @@ createPage = $createPage; $this->currentPageResolver = $currentPageResolver; @@ -94,7 +95,7 @@ public function iShouldBeNotifiedThatTheShippingGatewayWasCreated(): void { $this->notificationChecker->checkNotification( 'Shipping gateway has been successfully', - NotificationType::success() + NotificationType::success(), ); } diff --git a/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php b/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php index 63f335c..83ad0fa 100644 --- a/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php +++ b/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php @@ -1,9 +1,10 @@ updatePage = $updatePage; } diff --git a/tests/Behat/Mocker/InPostApiMocker.php b/tests/Behat/Mocker/InPostApiMocker.php index 2f664c6..e011fba 100644 --- a/tests/Behat/Mocker/InPostApiMocker.php +++ b/tests/Behat/Mocker/InPostApiMocker.php @@ -1,10 +1,11 @@ mocker ->mockService( 'bitbag.sylius_inpost_plugin.api.web_client', - WebClientInterface::class + WebClientInterface::class, ) ->shouldReceive('createShipment') ->andReturn($createShipmentResult) diff --git a/tests/Behat/Page/Admin/ShippingGateway/CreatePage.php b/tests/Behat/Page/Admin/ShippingGateway/CreatePage.php index fcfaf78..2c49add 100644 --- a/tests/Behat/Page/Admin/ShippingGateway/CreatePage.php +++ b/tests/Behat/Page/Admin/ShippingGateway/CreatePage.php @@ -1,10 +1,11 @@ getDocument()->attachFileToField( 'sylius_shipping_method_image_file', - $filesPath . $path + $filesPath . $path, ); } } diff --git a/tests/Behat/Page/Admin/ShippingMethod/UpdatePageInterface.php b/tests/Behat/Page/Admin/ShippingMethod/UpdatePageInterface.php index 3fb9b00..53dc1fd 100644 --- a/tests/Behat/Page/Admin/ShippingMethod/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/ShippingMethod/UpdatePageInterface.php @@ -1,10 +1,11 @@ Date: Wed, 24 Jul 2024 09:18:53 +0200 Subject: [PATCH 15/18] OP-374 - Installation.md has been updated --- doc/installation.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/doc/installation.md b/doc/installation.md index c901df3..3ed4773 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -180,7 +180,6 @@ use BitBag\SyliusInPostPlugin\Entity\InPostPointInterface; use BitBag\SyliusInPostPlugin\Model\InPostPointsAwareInterface; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Order as BaseOrder; -use Sylius\Component\Order\Model\OrderInterface; /** * @ORM\Entity @@ -219,8 +218,6 @@ use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\ImageAwareInterface; use Sylius\Component\Core\Model\ImageInterface; use Sylius\Component\Core\Model\ShippingMethod as BaseShippingMethod; -use Sylius\Component\Shipping\Model\ShippingMethodInterface; -use Sylius\Component\Shipping\Model\ShippingMethodTranslationInterface; /** * @ORM\Entity @@ -242,14 +239,10 @@ class ShippingMethod extends BaseShippingMethod implements ImageAwareInterface { $this->image = $image; } - protected function createTranslation(): ShippingMethodTranslationInterface - { - return new ShippingMethodTranslation(); - } } ``` -Finish the installation by updating the database schema: +Finish the installation by updating the database schema (check in advance: [Known Issues](known_issues.md)): ``` $ bin/console doctrine:migrations:diff From 665682412d695ebff8a5d6860dc7d556783dd278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Fri, 26 Jul 2024 09:06:01 +0200 Subject: [PATCH 16/18] OP-374 - WebClient / Exception and return type - fixed --- src/Api/WebClient.php | 5 ++--- src/Api/WebClientInterface.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Api/WebClient.php b/src/Api/WebClient.php index 1874ed6..03d236e 100644 --- a/src/Api/WebClient.php +++ b/src/Api/WebClient.php @@ -208,7 +208,7 @@ public function request( string $url, array $data = [], bool $returnJson = true, - ) { + ): array|string { $header = $this->getAuthorizedHeaderWithContentType(); try { @@ -220,8 +220,7 @@ public function request( $result = $this->apiClient->sendRequest($request); $response = json_decode((string) $result->getBody(), true); - - if (201 < $result->getStatusCode()) { + if (200 !== $result->getStatusCode() && 201 !== $result->getStatusCode()) { throw new InvalidInPostResponseException(); } } catch (InvalidInPostResponseException $e) { diff --git a/src/Api/WebClientInterface.php b/src/Api/WebClientInterface.php index 0c6e25c..49cc2ce 100644 --- a/src/Api/WebClientInterface.php +++ b/src/Api/WebClientInterface.php @@ -85,5 +85,5 @@ public function request( string $url, array $data = [], bool $returnJson = true, - ); + ): array|string; } From cce5039e8838b04fdecd9fcd27e35817fbac7f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Fri, 26 Jul 2024 09:21:02 +0200 Subject: [PATCH 17/18] OP-374 - OrganizationIdResolverInterface OS_Header double appearance - fixed --- src/Resolver/OrganizationIdResolverInterface.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Resolver/OrganizationIdResolverInterface.php b/src/Resolver/OrganizationIdResolverInterface.php index 5760f04..cc9db6b 100644 --- a/src/Resolver/OrganizationIdResolverInterface.php +++ b/src/Resolver/OrganizationIdResolverInterface.php @@ -9,12 +9,6 @@ declare(strict_types=1); -/* - * This file was created by developers working at BitBag - * Do you need more information about us and what we do? Visit our https://bitbag.io website! - * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career - */ - namespace BitBag\SyliusInPostPlugin\Resolver; interface OrganizationIdResolverInterface From 2d2bb39ff670b3889c990bfe454a935f30e13564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kali=C5=84ski?= Date: Fri, 26 Jul 2024 09:25:59 +0200 Subject: [PATCH 18/18] OP-374 - Build has been updated --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7dcbe76..b4d570f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ "8.1", "8.2", "8.3" ] + 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" ]