From 256c979deeae483fb132e3535e047636b525aac6 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Thu, 13 Aug 2026 08:53:58 +0200 Subject: [PATCH 1/6] Prepare plugin for Sylius 2.3 and Symfony 8 --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index fb82ed0a5..8ed44f8aa 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "sylius/resource-bundle": "^1.12", "sylius/sylius": "^2.0", "sylius/telemetry": "^1.0", - "symfony/messenger": "^6.4 || ^7.4", + "symfony/messenger": "^6.4 || ^7.4 || ^8.0", "php-http/discovery": "^1.20" }, "require-dev": { @@ -41,18 +41,18 @@ "friends-of-behat/suite-settings-extension": "^1.0", "friends-of-behat/symfony-extension": "^2.1", "friends-of-behat/variadic-extension": "^1.3", - "matthiasnoback/symfony-config-test": "^5.1", - "matthiasnoback/symfony-dependency-injection-test": "^5.1", + "matthiasnoback/symfony-config-test": "^6.1", + "matthiasnoback/symfony-dependency-injection-test": "^6.2", "phpstan/phpstan": "^1.6", "phpstan/phpstan-webmozart-assert": "^1.1", "phpunit/phpunit": "^10.5", "sylius-labs/coding-standard": "^4.2", "sylius/test-application": "^2.0.0@alpha", - "symfony/browser-kit": "^6.4 || ^7.4", - "symfony/debug-bundle": "^6.4 || ^7.4", - "symfony/dotenv": "^6.4 || ^7.4", - "symfony/intl": "^6.4 || ^7.4", - "symfony/web-profiler-bundle": "^6.4 || ^7.4", + "symfony/browser-kit": "^6.4 || ^7.4 || ^8.0", + "symfony/debug-bundle": "^6.4 || ^7.4 || ^8.0", + "symfony/dotenv": "^6.4 || ^7.4 || ^8.0", + "symfony/intl": "^6.4 || ^7.4 || ^8.0", + "symfony/web-profiler-bundle": "^6.4 || ^7.4 || ^8.0", "symfony/webpack-encore-bundle": "^2.2" }, "autoload": { From cac1d3cbe75307a7d1a3074429ebb0cbc2a316b6 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Thu, 13 Aug 2026 14:50:08 +0200 Subject: [PATCH 2/6] Make the plugin's DI config independent of removed Symfony bundles --- .github/workflows/build.yaml | 58 +++++++ composer.json | 10 +- config/services.php | 91 ++++++++++ config/services.xml | 87 ---------- config/services/actions.php | 70 ++++++++ config/services/actions.xml | 68 -------- config/services/checkers.php | 47 +++++ config/services/checkers.xml | 46 ----- config/services/command_bus.php | 39 +++++ config/services/command_bus.xml | 44 ----- config/services/converters.php | 67 ++++++++ config/services/converters.xml | 69 -------- config/services/creators.php | 28 +++ config/services/creators.xml | 33 ---- config/services/event_bus.php | 48 ++++++ config/services/event_bus.xml | 56 ------ config/services/factories.php | 50 ++++++ config/services/factories.xml | 63 ------- config/services/filters.php | 15 ++ config/services/filters.xml | 23 --- config/services/generators.php | 89 ++++++++++ config/services/generators.xml | 74 -------- config/services/listeners.php | 16 ++ config/services/listeners.xml | 26 --- config/services/providers.php | 92 ++++++++++ config/services/providers.xml | 88 ---------- config/services/queries.php | 17 ++ config/services/queries.xml | 34 ---- config/services/resolvers.php | 29 ++++ config/services/resolvers.xml | 34 ---- config/services/state_resolvers.php | 42 +++++ config/services/state_resolvers.xml | 41 ----- config/services/twig_components.php | 15 ++ config/services/twig_components.xml | 32 ---- config/services/validators.php | 43 +++++ config/services/validators.xml | 44 ----- phpstan-baseline.neon | 157 +++++++++++++++++ phpstan.neon | 1 + src/Action/Admin/SendCreditMemoAction.php | 2 +- .../SyliusRefundExtension.php | 6 +- src/Entity/Type/RefundEnumType.php | 5 +- tests/Behat/Resources/services.php | 160 ++++++++++++++++++ tests/Behat/Resources/services.xml | 129 -------------- .../TestApplication/config/services_test.php | 4 +- 44 files changed, 1189 insertions(+), 1003 deletions(-) create mode 100644 config/services.php delete mode 100644 config/services.xml create mode 100644 config/services/actions.php delete mode 100644 config/services/actions.xml create mode 100644 config/services/checkers.php delete mode 100644 config/services/checkers.xml create mode 100644 config/services/command_bus.php delete mode 100644 config/services/command_bus.xml create mode 100644 config/services/converters.php delete mode 100644 config/services/converters.xml create mode 100644 config/services/creators.php delete mode 100644 config/services/creators.xml create mode 100644 config/services/event_bus.php delete mode 100644 config/services/event_bus.xml create mode 100644 config/services/factories.php delete mode 100644 config/services/factories.xml create mode 100644 config/services/filters.php delete mode 100644 config/services/filters.xml create mode 100644 config/services/generators.php delete mode 100644 config/services/generators.xml create mode 100644 config/services/listeners.php delete mode 100644 config/services/listeners.xml create mode 100644 config/services/providers.php delete mode 100644 config/services/providers.xml create mode 100644 config/services/queries.php delete mode 100644 config/services/queries.xml create mode 100644 config/services/resolvers.php delete mode 100644 config/services/resolvers.xml create mode 100644 config/services/state_resolvers.php delete mode 100644 config/services/state_resolvers.xml create mode 100644 config/services/twig_components.php delete mode 100644 config/services/twig_components.xml create mode 100644 config/services/validators.php delete mode 100644 config/services/validators.xml create mode 100644 phpstan-baseline.neon create mode 100644 tests/Behat/Resources/services.php delete mode 100644 tests/Behat/Resources/services.xml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c726237de..8748d504c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -36,6 +36,7 @@ jobs: wkhtmltopdf: ["0.12.6.1-2"] state_machine_adapter: ["symfony_workflow"] legacy_pdf_generation: [true, false] + composer_minimum_stability: [""] include: - @@ -48,6 +49,7 @@ jobs: wkhtmltopdf: "0.12.6.1-2" state_machine_adapter: "winzou_state_machine" legacy_pdf_generation: true + composer_minimum_stability: "" - php: "8.3" @@ -59,6 +61,7 @@ jobs: wkhtmltopdf: "0.12.6.1-2" state_machine_adapter: "winzou_state_machine" legacy_pdf_generation: false + composer_minimum_stability: "" - php: "8.3" @@ -70,6 +73,7 @@ jobs: wkhtmltopdf: false state_machine_adapter: "symfony_workflow" legacy_pdf_generation: true + composer_minimum_stability: "" - php: "8.3" @@ -81,6 +85,7 @@ jobs: wkhtmltopdf: false state_machine_adapter: "symfony_workflow" legacy_pdf_generation: false + composer_minimum_stability: "" - php: "8.3" @@ -92,6 +97,7 @@ jobs: wkhtmltopdf: "0.12.6.1-2" state_machine_adapter: "symfony_workflow" legacy_pdf_generation: true + composer_minimum_stability: "" - php: "8.3" @@ -103,6 +109,34 @@ jobs: wkhtmltopdf: "0.12.6.1-2" state_machine_adapter: "symfony_workflow" legacy_pdf_generation: false + composer_minimum_stability: "" + + # TODO: drop the "~2.3.0" restriction to a plain matrix entry (instead of an + # include row) once sylius/sylius 2.3 has a stable release and + # sylius/test-application ships matching support on Packagist. + - + php: "8.4" + symfony: "^8.0" + sylius: "~2.3.0" + node: "24.x" + database: "mysql" + database_version: "8.4" + wkhtmltopdf: "0.12.6.1-2" + state_machine_adapter: "symfony_workflow" + legacy_pdf_generation: true + composer_minimum_stability: "alpha" + + - + php: "8.4" + symfony: "^8.0" + sylius: "~2.3.0" + node: "24.x" + database: "mysql" + database_version: "8.4" + wkhtmltopdf: "0.12.6.1-2" + state_machine_adapter: "symfony_workflow" + legacy_pdf_generation: false + composer_minimum_stability: "alpha" env: APP_ENV: test @@ -110,6 +144,8 @@ jobs: TEST_SYLIUS_STATE_MACHINE_ADAPTER: "${{ matrix.state_machine_adapter }}" TEST_SYLIUS_REFUND_PDF_GENERATION_DISABLED: ${{ matrix.wkhtmltopdf == false }} TEST_SYLIUS_REFUND_PDF_LEGACY: "${{ matrix.legacy_pdf_generation }}" + # TODO: drop once the Behat/Mink ecosystem supports Behat 4 (see the "Run Behat" step). + TEST_SYLIUS_REFUND_BEHAT_ENABLED: ${{ matrix.sylius != '~2.3.0' }} steps: - @@ -170,6 +206,22 @@ jobs: composer require winzou/state-machine:^0.4 --no-update composer require winzou/state-machine-bundle:^0.6 --no-update + - + # TODO: remove this whole step once https://github.com/Sylius/TestApplication/pull/48 + # merges and a real Sylius-2.3-compatible sylius/test-application release/branch + # exists on Packagist (drops the fork pointer), AND the Behat/Mink ecosystem + # supports Behat 4 / Symfony 8 (drops the package removals — none of behat/behat, + # behat/mink, or the friends-of-behat/* packages have a stable release supporting + # symfony/console ^8.0 yet; dmore/behat-chrome-extension has no Behat-4-compatible + # release at all). At that point the "Restrict Sylius version" step above is + # enough, and Behat can run for this row too (see the "Run Behat" step below). + name: Point sylius/test-application at the Sylius 2.3 prep fork, drop the Behat toolchain + if: matrix.sylius == '~2.3.0' + run: | + composer config repositories.sylius-test-application-fork vcs https://github.com/rust-le/TestApplication.git + composer require sylius/test-application:dev-sylius-2.3-symfony-8 --no-update --no-scripts --no-interaction + composer remove behat/behat behat/mink dmore/behat-chrome-extension dmore/chrome-mink-driver friends-of-behat/mink-browserkit-driver friends-of-behat/mink-debug-extension friends-of-behat/mink-extension friends-of-behat/page-object-extension friends-of-behat/suite-settings-extension friends-of-behat/symfony-extension friends-of-behat/variadic-extension --dev --no-update --no-interaction + - name: Build Sylius Test Application uses: SyliusLabs/BuildTestAppAction@v3.2.0 @@ -183,6 +235,8 @@ jobs: php_version: "${{ matrix.php }}" sylius_version: "${{ matrix.sylius }}" symfony_version: "${{ matrix.symfony }}" + composer_minimum_stability: "${{ matrix.composer_minimum_stability }}" + composer_prefer_stable: "yes" - name: Run security check @@ -209,7 +263,11 @@ jobs: run: vendor/bin/phpunit --colors=always - + # TODO: drop this condition once dmore/behat-chrome-extension (or a replacement + # Chrome driver) supports Behat 4 — until then there's no JS/e2e driver available + # for the Sylius 2.3 / Symfony 8 row (see the dmore/* removal step above). name: Run Behat + if: matrix.sylius != '~2.3.0' run: | if [ "${{ matrix.wkhtmltopdf }}" != "false" ]; then vendor/bin/behat --colors --strict -vvv --no-interaction -f progress --tags="~@pdf_disabled" || vendor/bin/behat --colors --strict -vvv --no-interaction -f progress --tags="~@pdf_disabled" --rerun || vendor/bin/behat --colors --strict -vvv --no-interaction -f progress --tags="~@pdf_disabled" --rerun diff --git a/composer.json b/composer.json index 8ed44f8aa..e8a5b5032 100644 --- a/composer.json +++ b/composer.json @@ -22,18 +22,18 @@ "php": "^8.2", "knplabs/knp-snappy-bundle": "^1.10", "myclabs/php-enum": "^1.8", + "php-http/discovery": "^1.20", "sylius/pdf-generation-bundle": "^1.0", "sylius/resource-bundle": "^1.12", "sylius/sylius": "^2.0", "sylius/telemetry": "^1.0", - "symfony/messenger": "^6.4 || ^7.4 || ^8.0", - "php-http/discovery": "^1.20" + "symfony/messenger": "^6.4 || ^7.4 || ^8.0" }, "require-dev": { "behat/behat": "^3.6.1", + "behat/mink": "^1.10 || ^1.13", "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", - "friends-of-behat/mink": "^1.8", "friends-of-behat/mink-browserkit-driver": "^1.4", "friends-of-behat/mink-debug-extension": "^2.0", "friends-of-behat/mink-extension": "^2.4", @@ -43,8 +43,8 @@ "friends-of-behat/variadic-extension": "^1.3", "matthiasnoback/symfony-config-test": "^6.1", "matthiasnoback/symfony-dependency-injection-test": "^6.2", - "phpstan/phpstan": "^1.6", - "phpstan/phpstan-webmozart-assert": "^1.1", + "phpstan/phpstan": "^2.2", + "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^10.5", "sylius-labs/coding-standard": "^4.2", "sylius/test-application": "^2.0.0@alpha", diff --git a/config/services.php b/config/services.php new file mode 100644 index 000000000..af51cd089 --- /dev/null +++ b/config/services.php @@ -0,0 +1,91 @@ +services(); + $parameters = $container->parameters(); + $container->import('services/**/*.php'); + + $parameters->set('sylius_refund.default_logo_file', '@SyliusRefundPlugin/assets/sylius-logo.png'); + $parameters->set('sylius_refund.template.logo_file', '%env(default:sylius_refund.default_logo_file:resolve:SYLIUS_REFUND_LOGO_FILE)%'); + + $services->defaults() + ->public(); + + $services->set('sylius_refund.calculator.unit_refund_total', UnitRefundTotalCalculator::class) + ->args([service('sylius_refund.provider.remaining_total')]); + + $services->alias(UnitRefundTotalCalculatorInterface::class, 'sylius_refund.calculator.unit_refund_total'); + + $services->set('sylius_refund.refunder.order_item_units', OrderItemUnitsRefunder::class) + ->args([ + service('sylius_refund.creator.refund'), + service('sylius.event_bus'), + service('sylius_refund.filter.unit_refund'), + ]) + ->tag('sylius_refund.refunder'); + + $services->set('sylius_refund.refunder.order_shipments', OrderShipmentsRefunder::class) + ->args([ + service('sylius_refund.creator.refund'), + service('sylius.event_bus'), + service('sylius_refund.filter.unit_refund'), + ]) + ->tag('sylius_refund.refunder'); + + $services->set('sylius_refund.twig.extension.order_refunds', OrderRefundsExtension::class) + ->args([ + service('sylius_refund.provider.order_refunded_total'), + service(UnitRefundedTotalProviderInterface::class), + service('sylius_refund.checker.unit_refunding_availability'), + service('sylius.repository.order'), + service('sylius_refund.repository.refund_payment'), + service('sylius_refund.factory.refund_type'), + ]) + ->tag('twig.extension'); + + $services->set('sylius_refund.twig.extension.order_refund_availability', OrderRefundAvailabilityExtension::class) + ->args([service('sylius_refund.checker.order_refunds_list_availability')]) + ->tag('twig.extension'); + + $services->set('sylius_refund.repository.credit_memo_sequence', EntityRepository::class) + ->args([CreditMemoSequence::class]) + ->factory([service('doctrine.orm.entity_manager'), 'getRepository']); + + $services->set('sylius_refund.email_sender.credit_memo', CreditMemoEmailSender::class) + ->args([ + service('sylius.email_sender'), + '%sylius_refund.pdf_generator.enabled%', + service('sylius_refund.resolver.credit_memo_file'), + service('sylius_refund.resolver.credit_memo_file_path'), + ]); + + $services->alias(CreditMemoEmailSenderInterface::class, 'sylius_refund.email_sender.credit_memo'); + + $services->set('sylius_refund.response_builder.credit_memo_file', CreditMemoFileResponseBuilder::class); + + $services->alias(CreditMemoFileResponseBuilderInterface::class, 'sylius_refund.response_builder.credit_memo_file'); + + $services->set('sylius_refund.manager.credit_memo_file', CreditMemoFileManager::class) + ->args([service('gaufrette.sylius_refund_credit_memo_filesystem')]) + ->deprecate('sylius/refund-plugin', '2.1', 'The "%service_id%" service is deprecated. Use Sylius\PdfGenerationBundle\Core\Filesystem\Manager\PdfFileManagerInterface from sylius/pdf-generation-bundle instead.'); + + $services->alias(CreditMemoFileManagerInterface::class, 'sylius_refund.manager.credit_memo_file'); +}; diff --git a/config/services.xml b/config/services.xml deleted file mode 100644 index 0d9a8e1a7..000000000 --- a/config/services.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - @SyliusRefundPlugin/assets/sylius-logo.png - %env(default:sylius_refund.default_logo_file:resolve:SYLIUS_REFUND_LOGO_FILE)% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Sylius\RefundPlugin\Entity\CreditMemoSequence - - - - - %sylius_refund.pdf_generator.enabled% - - - - - - - - - - - The "%service_id%" service is deprecated. Use Sylius\PdfGenerationBundle\Core\Filesystem\Manager\PdfFileManagerInterface from sylius/pdf-generation-bundle instead. - - - - diff --git a/config/services/actions.php b/config/services/actions.php new file mode 100644 index 000000000..3bb2c5f6b --- /dev/null +++ b/config/services/actions.php @@ -0,0 +1,70 @@ +services(); + $parameters = $container->parameters(); + + $services->defaults() + ->public(); + + $services->set('sylius_refund.controller.admin.download_credit_memo', AdminDownloadCreditMemoAction::class) + ->args([ + service('sylius_refund.resolver.credit_memo_file'), + service('sylius_refund.response_builder.credit_memo_file'), + '%sylius_refund.pdf_generator.enabled%', + ]); + + $services->set('sylius_refund.controller.shop.download_credit_memo', ShopDownloadCreditMemoAction::class) + ->args([ + service('sylius_refund.resolver.credit_memo_file'), + service('sylius_refund.checker.credit_memo_customer_relation'), + service('sylius_refund.response_builder.credit_memo_file'), + '%sylius_refund.pdf_generator.enabled%', + ]); + + $services->set('sylius_refund.controller.admin.order_refunds_list', OrderRefundsListAction::class) + ->args([ + service('sylius.repository.order'), + service('sylius_refund.checker.order_refunds_list_availability'), + service('sylius_refund.provider.refund_payment_methods'), + service('twig'), + service('request_stack'), + service('router'), + ]); + + $services->set('sylius_refund.controller.admin.refund_units', RefundUnitsAction::class) + ->args([ + service('sylius.command_bus'), + service('request_stack'), + service('router'), + service('sylius_refund.creator.request_command'), + service('monolog.logger'), + service('security.csrf.token_manager'), + ]); + + $services->set('sylius_refund.controller.complete_refund_payment', CompleteRefundPaymentAction::class) + ->args([ + service('request_stack'), + service('sylius_refund.repository.refund_payment'), + service('sylius.repository.order'), + service('sylius_refund.state_resolver.refund_payment_completed_applier'), + service('router'), + ]); + + $services->set('sylius_refund.controller.admin.send_credit_memo', SendCreditMemoAction::class) + ->args([ + service('sylius.command_bus'), + service('sylius_refund.repository.credit_memo'), + service('request_stack'), + service('router'), + ]); +}; diff --git a/config/services/actions.xml b/config/services/actions.xml deleted file mode 100644 index 8c9745644..000000000 --- a/config/services/actions.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - %sylius_refund.pdf_generator.enabled% - - - - - - - %sylius_refund.pdf_generator.enabled% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/services/checkers.php b/config/services/checkers.php new file mode 100644 index 000000000..8a9d43623 --- /dev/null +++ b/config/services/checkers.php @@ -0,0 +1,47 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.checker.credit_memo_customer_relation', CreditMemoCustomerRelationChecker::class) + ->args([ + service('sylius.context.customer'), + service('sylius_refund.repository.credit_memo'), + ]); + + $services->alias(CreditMemoCustomerRelationCheckerInterface::class, 'sylius_refund.checker.credit_memo_customer_relation'); + + $services->set('sylius_refund.checker.order_refunding_availability', OrderRefundingAvailabilityChecker::class) + ->args([ + service('sylius.repository.order'), + service('sylius_abstraction.state_machine'), + ]); + + $services->set('sylius_refund.checker.order_refunds_list_availability', OrderRefundsListAvailabilityChecker::class) + ->args([ + service('sylius.repository.order'), + service('sylius_refund.checker.order_refunding_availability'), + ]); + + $services->set('sylius_refund.checker.order_fully_refunded_total', OrderFullyRefundedTotalChecker::class) + ->args([service('sylius_refund.provider.order_refunded_total')]); + + $services->alias(OrderFullyRefundedTotalCheckerInterface::class, 'sylius_refund.checker.order_fully_refunded_total'); + + $services->set('sylius_refund.checker.unit_refunding_availability', UnitRefundingAvailabilityChecker::class) + ->args([service('sylius_refund.provider.remaining_total')]); + + $services->alias(UnitRefundingAvailabilityCheckerInterface::class, 'sylius_refund.checker.unit_refunding_availability'); +}; diff --git a/config/services/checkers.xml b/config/services/checkers.xml deleted file mode 100644 index e2f4fe30a..000000000 --- a/config/services/checkers.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/services/command_bus.php b/config/services/command_bus.php new file mode 100644 index 000000000..865ded023 --- /dev/null +++ b/config/services/command_bus.php @@ -0,0 +1,39 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.command_handler.refund_units', RefundUnitsHandler::class) + ->args([ + tagged_iterator('sylius_refund.refunder'), + service('sylius.event_bus'), + service('sylius.repository.order'), + service('sylius_refund.validator.refund_units_command'), + ]) + ->tag('messenger.message_handler', ['bus' => 'sylius.command_bus']); + + $services->set('sylius_refund.command_handler.generate_credit_memo', GenerateCreditMemoHandler::class) + ->args([ + service('sylius_refund.generator.credit_memo'), + service('sylius_refund.manager.credit_memo'), + service('sylius.event_bus'), + service('sylius.repository.order'), + service('sylius_refund.resolver.credit_memo_file'), + '%sylius_refund.pdf_generator.enabled%', + ]) + ->tag('messenger.message_handler', ['bus' => 'sylius.command_bus']); + + $services->set('sylius_refund.command_handler.send_credit_memo', SendCreditMemoHandler::class) + ->args([ + service('sylius_refund.repository.credit_memo'), + service('sylius_refund.email_sender.credit_memo'), + ]) + ->tag('messenger.message_handler', ['bus' => 'sylius.command_bus']); +}; diff --git a/config/services/command_bus.xml b/config/services/command_bus.xml deleted file mode 100644 index 0c4941b22..000000000 --- a/config/services/command_bus.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - %sylius_refund.pdf_generator.enabled% - - - - - - - - - - diff --git a/config/services/converters.php b/config/services/converters.php new file mode 100644 index 000000000..6f6032c35 --- /dev/null +++ b/config/services/converters.php @@ -0,0 +1,67 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.converter.line_items', CompositeLineItemConverter::class) + ->args([ + tagged_iterator('sylius_refund.line_item_converter'), + service('sylius_refund.filter.unit_refund'), + ]); + + $services->alias(LineItemsConverterInterface::class, 'sylius_refund.converter.line_items'); + + $services->alias('sylius_refund.converter.line_items.composite', 'sylius_refund.converter.line_items'); + + $services->set('sylius_refund.converter.request_to_refund_units', RequestToRefundUnitsConverter::class) + ->args([tagged_iterator('sylius_refund.request_to_refund_units_converter')]); + + $services->alias(RequestToRefundUnitsConverterInterface::class, 'sylius_refund.converter.request_to_refund_units'); + + $services->set('sylius_refund.converter.request_to_shipment_refund', RequestToShipmentRefundConverter::class) + ->args([service('sylius_refund.converter.refund_units')]) + ->tag('sylius_refund.request_to_refund_units_converter'); + + $services->alias(RequestToShipmentRefundConverter::class, 'sylius_refund.converter.request_to_shipment_refund'); + + $services->set('sylius_refund.converter.request_to_order_item_unit_refund', RequestToOrderItemUnitRefundConverter::class) + ->args([service('sylius_refund.converter.refund_units')]) + ->tag('sylius_refund.request_to_refund_units_converter'); + + $services->alias(RequestToOrderItemUnitRefundConverter::class, 'sylius_refund.converter.request_to_order_item_unit_refund'); + + $services->set('sylius_refund.converter.line_items.order_item_unit', OrderItemUnitLineItemsConverter::class) + ->args([ + service('sylius.repository.order_item_unit'), + service('sylius_refund.provider.tax_rate'), + service('sylius_refund.factory.line_item'), + ]) + ->tag('sylius_refund.line_item_converter'); + + $services->set('sylius_refund.converter.line_items.shipment', ShipmentLineItemsConverter::class) + ->args([ + service('sylius.repository.adjustment'), + service('sylius_refund.provider.tax_rate'), + service('sylius_refund.factory.line_item'), + ]) + ->tag('sylius_refund.line_item_converter'); + + $services->set('sylius_refund.converter.refund_units', RefundUnitsConverter::class) + ->args([service('sylius_refund.calculator.unit_refund_total')]); + + $services->alias(RefundUnitsConverterInterface::class, 'sylius_refund.converter.refund_units'); +}; diff --git a/config/services/converters.xml b/config/services/converters.xml deleted file mode 100644 index 5be09f48c..000000000 --- a/config/services/converters.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/services/creators.php b/config/services/creators.php new file mode 100644 index 000000000..b7c5218c0 --- /dev/null +++ b/config/services/creators.php @@ -0,0 +1,28 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.creator.refund', RefundCreator::class) + ->args([ + service('sylius_refund.factory.refund'), + service('sylius_refund.provider.remaining_total'), + service('sylius.repository.order'), + service('sylius_refund.manager.refund'), + ]); + + $services->alias(RefundCreatorInterface::class, 'sylius_refund.creator.refund'); + + $services->set('sylius_refund.creator.request_command', RefundUnitsCommandCreator::class) + ->args([service('sylius_refund.converter.request_to_refund_units')]); + + $services->alias(RequestCommandCreatorInterface::class, 'sylius_refund.creator.request_command'); +}; diff --git a/config/services/creators.xml b/config/services/creators.xml deleted file mode 100644 index b325320bb..000000000 --- a/config/services/creators.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/config/services/event_bus.php b/config/services/event_bus.php new file mode 100644 index 000000000..40b4d110a --- /dev/null +++ b/config/services/event_bus.php @@ -0,0 +1,48 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.listener.credit_memo_generated', CreditMemoGeneratedEventListener::class) + ->public() + ->args([service('sylius.command_bus')]) + ->tag('messenger.message_handler', ['bus' => 'sylius.event_bus']); + + $services->set('sylius_refund.listener.unit_refunded', UnitRefundedEventListener::class) + ->public() + ->args([service('sylius_refund.state_resolver.order_partially_refunded')]) + ->tag('messenger.message_handler', ['bus' => 'sylius.event_bus']); + + $services->set('sylius_refund.process_manager.units_refunded', UnitsRefundedProcessManager::class) + ->public() + ->args([tagged_iterator('sylius_refund.units_refunded.process_step')]) + ->tag('messenger.message_handler', ['bus' => 'sylius.event_bus']); + + $services->alias(UnitsRefundedProcessManagerInterface::class, 'sylius_refund.process_manager.units_refunded'); + + $services->set('sylius_refund.process_manager.refund_payment', RefundPaymentProcessManager::class) + ->args([ + service('sylius_refund.state_resolver.order_fully_refunded'), + service('sylius_refund.provider.related_payment_id'), + service('sylius_refund.factory.refund_payment'), + service('sylius.repository.order'), + service('sylius.repository.payment_method'), + service('doctrine.orm.default_entity_manager'), + service('sylius.event_bus'), + ]) + ->tag('sylius_refund.units_refunded.process_step', ['priority' => 50]); + + $services->set('sylius_refund.process_manager.credit_memo', CreditMemoProcessManager::class) + ->args([service('sylius.command_bus')]) + ->tag('sylius_refund.units_refunded.process_step', ['priority' => 100]); +}; diff --git a/config/services/event_bus.xml b/config/services/event_bus.xml deleted file mode 100644 index f6aa78590..000000000 --- a/config/services/event_bus.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/services/factories.php b/config/services/factories.php new file mode 100644 index 000000000..69a1519cb --- /dev/null +++ b/config/services/factories.php @@ -0,0 +1,50 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.factory.credit_memo_sequence', CreditMemoSequenceFactory::class); + + $services->alias(CreditMemoSequenceFactoryInterface::class, 'sylius_refund.factory.credit_memo_sequence'); + + $services->set('sylius_refund.factory.refund_type', RefundTypeFactory::class) + ->args(['%sylius_refund.refund_type%']); + + $services->alias(RefundTypeFactoryInterface::class, 'sylius_refund.factory.refund_type'); + + $services->set('sylius_refund.factory.line_item', LineItemFactory::class) + ->args(['%sylius_refund.model.line_item.class%']); + + $services->alias(LineItemFactoryInterface::class, 'sylius_refund.factory.line_item'); + + $services->set('sylius_refund.custom_factory.credit_memo', CreditMemoFactory::class) + ->decorate('sylius_refund.factory.credit_memo', null, 256) + ->args([ + service('.inner'), + service('sylius_refund.generator.credit_memo_identifier'), + service('sylius_refund.generator.credit_memo_number'), + service(CurrentDateTimeImmutableProviderInterface::class), + ]); + + $services->set('sylius_refund.custom_factory.shop_billing_data', ShopBillingDataFactory::class) + ->decorate('sylius_refund.factory.shop_billing_data', null, 256) + ->args([service('.inner')]); + + $services->set('sylius_refund.custom_factory.customer_billing_data', CustomerBillingDataFactory::class) + ->decorate('sylius_refund.factory.customer_billing_data', null, 256) + ->args([service('.inner')]); +}; diff --git a/config/services/factories.xml b/config/services/factories.xml deleted file mode 100644 index aba719e7e..000000000 --- a/config/services/factories.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - %sylius_refund.refund_type% - - - - - %sylius_refund.model.line_item.class% - - - - - - - - - - - - - - - - - - - diff --git a/config/services/filters.php b/config/services/filters.php new file mode 100644 index 000000000..dfa6b53d6 --- /dev/null +++ b/config/services/filters.php @@ -0,0 +1,15 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.filter.unit_refund', UnitRefundFilter::class); + + $services->alias(UnitRefundFilterInterface::class, 'sylius_refund.filter.unit_refund'); +}; diff --git a/config/services/filters.xml b/config/services/filters.xml deleted file mode 100644 index ee832b969..000000000 --- a/config/services/filters.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - diff --git a/config/services/generators.php b/config/services/generators.php new file mode 100644 index 000000000..ed1f149e1 --- /dev/null +++ b/config/services/generators.php @@ -0,0 +1,89 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.generator.credit_memo_number', SequentialCreditMemoNumberGenerator::class) + ->args([ + service('sylius_refund.repository.credit_memo_sequence'), + service('sylius_refund.factory.credit_memo_sequence'), + service('doctrine.orm.entity_manager'), + ]); + + $services->alias(CreditMemoNumberGeneratorInterface::class, 'sylius_refund.generator.credit_memo_number'); + + $services->set('sylius_refund.generator.credit_memo', CreditMemoGenerator::class) + ->args([ + service('sylius_refund.converter.line_items'), + service('sylius_refund.generator.tax_items'), + service('sylius_refund.factory.credit_memo'), + service('sylius_refund.factory.customer_billing_data'), + service('sylius_refund.factory.shop_billing_data'), + ]); + + $services->alias(CreditMemoGeneratorInterface::class, 'sylius_refund.generator.credit_memo'); + + $services->set('sylius_refund.generator.credit_memo_file_name', CreditMemoFileNameGenerator::class); + + $services->alias(CreditMemoFileNameGeneratorInterface::class, 'sylius_refund.generator.credit_memo_file_name'); + + $services->set('sylius_refund.generator.credit_memo_pdf_file', CreditMemoPdfFileGenerator::class) + ->args([ + service('sylius_refund.repository.credit_memo'), + service('file_locator'), + '@SyliusRefundPlugin/download/credit_memo.html.twig', + '%sylius_refund.template.logo_file%', + service('sylius_refund.generator.twig_to_pdf'), + service('sylius_refund.generator.credit_memo_file_name'), + ]); + + $services->alias(CreditMemoPdfFileGeneratorInterface::class, 'sylius_refund.generator.credit_memo_pdf_file'); + + $services->set('sylius_refund.generator.tax_items', TaxItemsGenerator::class); + + $services->alias(TaxItemsGeneratorInterface::class, 'sylius_refund.generator.tax_items'); + + $services->set('sylius_refund.generator.credit_memo_identifier', UuidCreditMemoIdentifierGenerator::class); + + $services->alias(CreditMemoIdentifierGeneratorInterface::class, 'sylius_refund.generator.credit_memo_identifier'); + + $services->set('sylius_refund.generator.pdf_options', PdfOptionsGenerator::class) + ->args([ + service('file_locator'), + '%knp_snappy.pdf.options%', + '%sylius_refund.pdf_generator.allowed_files%', + ]) + ->deprecate('sylius/refund-plugin', '2.1', 'The "%service_id%" service is deprecated. PDF options are now handled by sylius/pdf-generation-bundle adapters.'); + + $services->alias(PdfOptionsGeneratorInterface::class, 'sylius_refund.generator.pdf_options'); + + $services->set('sylius_refund.generator.twig_to_pdf', TwigToPdfGenerator::class) + ->args([ + service('twig'), + service('knp_snappy.pdf'), + service('sylius_refund.generator.pdf_options'), + ]) + ->deprecate('sylius/refund-plugin', '2.1', 'The "%service_id%" service is deprecated. Use Sylius\PdfGenerationBundle\Core\Renderer\TwigToPdfRendererInterface from sylius/pdf-generation-bundle instead.'); + + $services->alias(TwigToPdfGeneratorInterface::class, 'sylius_refund.generator.twig_to_pdf'); +}; diff --git a/config/services/generators.xml b/config/services/generators.xml deleted file mode 100644 index df9ccc92d..000000000 --- a/config/services/generators.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @SyliusRefundPlugin/download/credit_memo.html.twig - %sylius_refund.template.logo_file% - - - - - - - - - - - - - - %knp_snappy.pdf.options% - %sylius_refund.pdf_generator.allowed_files% - The "%service_id%" service is deprecated. PDF options are now handled by sylius/pdf-generation-bundle adapters. - - - - - - - - The "%service_id%" service is deprecated. Use Sylius\PdfGenerationBundle\Core\Renderer\TwigToPdfRendererInterface from sylius/pdf-generation-bundle instead. - - - - diff --git a/config/services/listeners.php b/config/services/listeners.php new file mode 100644 index 000000000..d33e41079 --- /dev/null +++ b/config/services/listeners.php @@ -0,0 +1,16 @@ +services(); + $parameters = $container->parameters(); + + $services->defaults() + ->public(); + + $services->set('sylius_refund.listener.admin_main_menu', AdminMainMenuListener::class) + ->tag('kernel.event_listener', ['event' => 'sylius.menu.admin.main', 'method' => 'addCreditMemosSection']); +}; diff --git a/config/services/listeners.xml b/config/services/listeners.xml deleted file mode 100644 index 2b220e0f3..000000000 --- a/config/services/listeners.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - diff --git a/config/services/providers.php b/config/services/providers.php new file mode 100644 index 000000000..51d13172d --- /dev/null +++ b/config/services/providers.php @@ -0,0 +1,92 @@ +services(); + $parameters = $container->parameters(); + $parameters->set('sylius_refund.supported_gateways', ['offline']); + + $services->set('sylius_refund.provider.credit_memo_file', CreditMemoFileProvider::class) + ->args([ + service('sylius_refund.generator.credit_memo_file_name'), + service('sylius_refund.manager.credit_memo_file'), + ]); + + $services->alias(CreditMemoFileProviderInterface::class, 'sylius_refund.provider.credit_memo_file'); + + $services->set('sylius_refund.provider.refunded_shipment_fee', RefundedShipmentFeeProvider::class) + ->args([service('sylius.repository.adjustment')]); + + $services->alias(RefundedShipmentFeeProviderInterface::class, 'sylius_refund.provider.refunded_shipment_fee'); + + $services->set('sylius_refund.provider.order_refunded_total', OrderRefundedTotalProvider::class) + ->args([ + service('sylius_refund.repository.refund'), + service('sylius.repository.order_item_unit'), + ]); + + $services->alias(OrderRefundedTotalProviderInterface::class, 'sylius_refund.provider.order_refunded_total'); + + $services->set('sylius_refund.provider.current_date_time_immutable', CurrentDateTimeImmutableProvider::class); + + $services->alias(CurrentDateTimeImmutableProviderInterface::class, 'sylius_refund.provider.current_date_time_immutable'); + + $services->set('sylius_refund.provider.order_item_unit_total', OrderItemUnitTotalProvider::class) + ->args([service('sylius.repository.order_item_unit')]) + ->tag('sylius_refund.refund_unit_total_provider'); + + $services->set('sylius_refund.provider.shipment_total', ShipmentTotalProvider::class) + ->args([service('sylius.repository.adjustment')]) + ->tag('sylius_refund.refund_unit_total_provider'); + + $services->set('sylius_refund.provider.remaining_total', RemainingTotalProvider::class) + ->args([ + tagged_locator('sylius_refund.refund_unit_total_provider', indexAttribute: 'refund_type', defaultIndexMethod: 'refundType'), + service('sylius_refund.repository.refund'), + ]); + + $services->alias(RemainingTotalProviderInterface::class, 'sylius_refund.provider.remaining_total'); + + $services->set('sylius_refund.provider.unit_refunded_total', UnitRefundedTotalProvider::class) + ->args([service('sylius_refund.repository.refund')]); + + $services->alias(UnitRefundedTotalProviderInterface::class, 'sylius_refund.provider.unit_refunded_total'); + + $services->set('sylius_refund.provider.related_payment_id', DefaultRelatedPaymentIdProvider::class); + + $services->alias(RelatedPaymentIdProviderInterface::class, 'sylius_refund.provider.related_payment_id'); + + $services->set('sylius_refund.provider.refund_payment_methods', SupportedRefundPaymentMethodsProvider::class) + ->args([ + service('sylius.repository.payment_method'), + '%sylius_refund.supported_gateways%', + ]); + + $services->alias(RefundPaymentMethodsProviderInterface::class, 'sylius_refund.provider.refund_payment_methods'); + + $services->set('sylius_refund.provider.tax_rate', TaxRateProvider::class); + + $services->alias(TaxRateProviderInterface::class, 'sylius_refund.provider.tax_rate'); +}; diff --git a/config/services/providers.xml b/config/services/providers.xml deleted file mode 100644 index ac0d194d3..000000000 --- a/config/services/providers.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - offline - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %sylius_refund.supported_gateways% - - - - - - - diff --git a/config/services/queries.php b/config/services/queries.php new file mode 100644 index 000000000..729660e48 --- /dev/null +++ b/config/services/queries.php @@ -0,0 +1,17 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.doctrine.orm.query.count_order_item_unit_refunds_belonging_to_order', CountOrderItemUnitRefundsBelongingToOrderQuery::class) + ->args([service('sylius.repository.order_item_unit')]); + + $services->set('sylius_refund.doctrine.orm.query.count_shipment_refunds_belonging_to_order', CountShipmentRefundsBelongingToOrderQuery::class) + ->args([service('sylius.repository.adjustment')]); +}; diff --git a/config/services/queries.xml b/config/services/queries.xml deleted file mode 100644 index 1377e7538..000000000 --- a/config/services/queries.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/config/services/resolvers.php b/config/services/resolvers.php new file mode 100644 index 000000000..001d5edf7 --- /dev/null +++ b/config/services/resolvers.php @@ -0,0 +1,29 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.resolver.credit_memo_file', CreditMemoFileResolver::class) + ->args([ + service('sylius_refund.repository.credit_memo'), + service('sylius_refund.provider.credit_memo_file'), + service('sylius_refund.generator.credit_memo_pdf_file'), + service('sylius_refund.manager.credit_memo_file'), + service('sylius_refund.generator.credit_memo_file_name'), + ]); + + $services->alias(CreditMemoFileResolverInterface::class, 'sylius_refund.resolver.credit_memo_file'); + + $services->set('sylius_refund.resolver.credit_memo_file_path', CreditMemoFilePathResolver::class) + ->args(['%sylius_refund.credit_memo_save_path%']); + + $services->alias(CreditMemoFilePathResolverInterface::class, 'sylius_refund.resolver.credit_memo_file_path'); +}; diff --git a/config/services/resolvers.xml b/config/services/resolvers.xml deleted file mode 100644 index ba7258121..000000000 --- a/config/services/resolvers.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - %sylius_refund.credit_memo_save_path% - - - - diff --git a/config/services/state_resolvers.php b/config/services/state_resolvers.php new file mode 100644 index 000000000..552334297 --- /dev/null +++ b/config/services/state_resolvers.php @@ -0,0 +1,42 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.state_resolver.order_fully_refunded', OrderFullyRefundedStateResolver::class) + ->args([ + service('sylius_abstraction.state_machine'), + service('sylius.manager.order'), + service('sylius_refund.checker.order_fully_refunded_total'), + service('sylius.repository.order'), + ]); + + $services->alias(OrderFullyRefundedStateResolverInterface::class, 'sylius_refund.state_resolver.order_fully_refunded'); + + $services->set('sylius_refund.state_resolver.order_partially_refunded', OrderPartiallyRefundedStateResolver::class) + ->args([ + service('sylius.repository.order'), + service('sylius_abstraction.state_machine'), + service('sylius.manager.order'), + ]); + + $services->alias(OrderPartiallyRefundedStateResolverInterface::class, 'sylius_refund.state_resolver.order_partially_refunded'); + + $services->set('sylius_refund.state_resolver.refund_payment_completed_applier', RefundPaymentCompletedStateApplier::class) + ->args([ + service('sylius_abstraction.state_machine'), + service('sylius_refund.manager.refund_payment'), + ]); + + $services->alias(RefundPaymentCompletedStateApplierInterface::class, 'sylius_refund.state_resolver.refund_payment_completed_applier'); +}; diff --git a/config/services/state_resolvers.xml b/config/services/state_resolvers.xml deleted file mode 100644 index a28186272..000000000 --- a/config/services/state_resolvers.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/services/twig_components.php b/config/services/twig_components.php new file mode 100644 index 000000000..215195b3c --- /dev/null +++ b/config/services/twig_components.php @@ -0,0 +1,15 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.twig_component.customer_credit_memos', OrderCreditMemosComponent::class) + ->args([service('sylius_refund.repository.credit_memo')]) + ->tag('sylius.twig_component', ['key' => 'sylius_refund:shop:account:credit_memos']) + ->tag('sylius.twig_component', ['key' => 'sylius_refund:admin:credit_memos']); +}; diff --git a/config/services/twig_components.xml b/config/services/twig_components.xml deleted file mode 100644 index 2554c076b..000000000 --- a/config/services/twig_components.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - diff --git a/config/services/validators.php b/config/services/validators.php new file mode 100644 index 000000000..1d3544b06 --- /dev/null +++ b/config/services/validators.php @@ -0,0 +1,43 @@ +services(); + $parameters = $container->parameters(); + + $services->set('sylius_refund.validator.refund_units_command', RefundUnitsCommandValidator::class) + ->args([ + service('sylius_refund.checker.order_refunding_availability'), + service('sylius_refund.validator.refund_amount'), + tagged_iterator('sylius_refund.validator.unit_refunds_belonging_to_order'), + ]); + + $services->alias(RefundUnitsCommandValidatorInterface::class, 'sylius_refund.validator.refund_units_command'); + + $services->set('sylius_refund.validator.order_item_unit_refunds_belonging_to_order', OrderItemUnitRefundsBelongingToOrderValidator::class) + ->args([ + service('sylius_refund.filter.unit_refund'), + service('sylius_refund.doctrine.orm.query.count_order_item_unit_refunds_belonging_to_order'), + ]) + ->tag('sylius_refund.validator.unit_refunds_belonging_to_order'); + + $services->set('sylius_refund.validator.shipment_refunds_belonging_to_order', ShipmentRefundsBelongingToOrderValidator::class) + ->args([ + service('sylius_refund.filter.unit_refund'), + service('sylius_refund.doctrine.orm.query.count_shipment_refunds_belonging_to_order'), + ]) + ->tag('sylius_refund.validator.unit_refunds_belonging_to_order'); + + $services->set('sylius_refund.validator.refund_amount', RefundAmountValidator::class) + ->args([service('sylius_refund.provider.remaining_total')]); + + $services->alias(RefundAmountValidatorInterface::class, 'sylius_refund.validator.refund_amount'); +}; diff --git a/config/services/validators.xml b/config/services/validators.xml deleted file mode 100644 index a4f146649..000000000 --- a/config/services/validators.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 000000000..6b701b937 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,157 @@ +parameters: + ignoreErrors: + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:allIsInstanceOf\(\) with array\ and ''Sylius\\\\RefundPlugin\\\\Model\\\\UnitRefundInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Command/GenerateCreditMemo.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:string\(\) with string will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Command/GenerateCreditMemo.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:allIsInstanceOf\(\) with array\ and ''Sylius\\\\RefundPlugin\\\\Model\\\\UnitRefundInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Command/RefundUnits.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:integer\(\) with int will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Command/RefundUnits.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:isInstanceOf\(\) with Sylius\\RefundPlugin\\Refunder\\RefunderInterface and ''Sylius\\\\RefundPlugin\\\\Refunder\\\\RefunderInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/CommandHandler/RefundUnitsHandler.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:isIterable\(\) with iterable\ will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/CommandHandler/RefundUnitsHandler.php + + - + message: '#^Property Sylius\\RefundPlugin\\CommandHandler\\RefundUnitsHandler\:\:\$orderShipmentsRefunder \(Sylius\\RefundPlugin\\Refunder\\RefunderInterface\|null\) is never assigned Sylius\\RefundPlugin\\Refunder\\RefunderInterface so it can be removed from the property type\.$#' + identifier: property.unusedType + count: 1 + path: src/CommandHandler/RefundUnitsHandler.php + + - + message: '#^Property Sylius\\RefundPlugin\\CommandHandler\\RefundUnitsHandler\:\:\$orderUnitsRefunder \(Sylius\\RefundPlugin\\Refunder\\RefunderInterface\|null\) is never assigned Sylius\\RefundPlugin\\Refunder\\RefunderInterface so it can be removed from the property type\.$#' + identifier: property.unusedType + count: 1 + path: src/CommandHandler/RefundUnitsHandler.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:notNull\(\) with string will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/CommandHandler/SendCreditMemoHandler.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:isInstanceOf\(\) with Sylius\\RefundPlugin\\Converter\\LineItem\\LineItemsConverterUnitRefundAwareInterface and ''Sylius\\\\RefundPlugin\\\\Converter\\\\LineItem\\\\LineItemsConverterUnitRefundAwareInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Converter/LineItem/CompositeLineItemConverter.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:allIsInstanceOf\(\) with array\ and class\-string\ will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Converter/LineItem/OrderItemUnitLineItemsConverter.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:allIsInstanceOf\(\) with array\ and class\-string\ will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Converter/LineItem/ShipmentLineItemsConverter.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:isInstanceOf\(\) with Sylius\\Component\\Core\\Model\\ShipmentInterface and ''Sylius\\\\Component\\\\Order\\\\Model\\\\AdjustableInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Converter/LineItem/ShipmentLineItemsConverter.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:notNull\(\) with Sylius\\Component\\Core\\Model\\ShipmentInterface will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Converter/LineItem/ShipmentLineItemsConverter.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:isInstanceOf\(\) with Sylius\\RefundPlugin\\Model\\UnitRefundInterface and ''Sylius\\\\RefundPlugin\\\\Model\\\\UnitRefundInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Converter/RefundUnitsConverter.php + + - + message: '#^Interface Sylius\\RefundPlugin\\Converter\\RefundUnitsConverterInterface has PHPDoc tag @method for method convert\(\) parameter \#1 \$units with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/Converter/RefundUnitsConverterInterface.php + + - + message: '#^Interface Sylius\\RefundPlugin\\Converter\\RefundUnitsConverterInterface has PHPDoc tag @method for method convert\(\) return type with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/Converter/RefundUnitsConverterInterface.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:isInstanceOf\(\) with Sylius\\RefundPlugin\\Converter\\Request\\RequestToRefundUnitsConverterInterface and ''Sylius\\\\RefundPlugin\\\\Converter\\\\Request\\\\RequestToRefundUnitsConverterInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Converter/Request/RequestToRefundUnitsConverter.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:allIsInstanceOf\(\) with array\ and ''Sylius\\\\RefundPlugin\\\\Model\\\\UnitRefundInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Event/UnitsRefunded.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:integer\(\) with int will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Event/UnitsRefunded.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:notNull\(\) with Sylius\\Component\\Core\\Model\\OrderItemUnitInterface will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Provider/OrderItemUnitTotalProvider.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:notNull\(\) with Sylius\\Component\\Core\\Model\\AdjustmentInterface will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Provider/RefundedShipmentFeeProvider.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:notNull\(\) with string will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Sender/CreditMemoEmailSender.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:notNull\(\) with Sylius\\Component\\Core\\Model\\OrderInterface will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/StateResolver/OrderFullyRefundedStateResolver.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:allIsInstanceOf\(\) with array\ and ''Sylius\\\\RefundPlugin\\\\Model\\\\UnitRefundInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Validator/RefundAmountValidator.php + + - + message: '#^Property Sylius\\RefundPlugin\\Validator\\RefundUnitsCommandValidator\:\:\$refundUnitsBelongingToOrderValidators on left side of \?\? is not nullable nor uninitialized\.$#' + identifier: nullCoalesce.initializedProperty + count: 1 + path: src/Validator/RefundUnitsCommandValidator.php diff --git a/phpstan.neon b/phpstan.neon index dd1b4c50e..65e641671 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ includes: - vendor/phpstan/phpstan-webmozart-assert/extension.neon + - phpstan-baseline.neon parameters: level: 8 diff --git a/src/Action/Admin/SendCreditMemoAction.php b/src/Action/Admin/SendCreditMemoAction.php index 90055e2e3..b7cf9fad5 100644 --- a/src/Action/Admin/SendCreditMemoAction.php +++ b/src/Action/Admin/SendCreditMemoAction.php @@ -38,7 +38,7 @@ public function __construct( public function __invoke(Request $request): Response { /** @var CreditMemoInterface|null $creditMemo */ - $creditMemo = $this->creditMemoRepository->find($request->get('id')); + $creditMemo = $this->creditMemoRepository->find($request->attributes->get('id')); if ($creditMemo !== null) { $number = $creditMemo->getNumber(); diff --git a/src/DependencyInjection/SyliusRefundExtension.php b/src/DependencyInjection/SyliusRefundExtension.php index 719b5c221..1091ea207 100644 --- a/src/DependencyInjection/SyliusRefundExtension.php +++ b/src/DependencyInjection/SyliusRefundExtension.php @@ -28,7 +28,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Reference; final class SyliusRefundExtension extends AbstractResourceExtension implements PrependExtensionInterface @@ -43,8 +43,8 @@ public function load(array $configs, ContainerBuilder $container): void $configs = $this->processConfiguration($configuration, $configs); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../config')); - $loader->load('services.xml'); + $loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../../config')); + $loader->load('services.php'); $this->tagsAutoconfiguration($container, [ 'sylius_refund.units_refunded.process_step' => UnitsRefundedProcessStepInterface::class, diff --git a/src/Entity/Type/RefundEnumType.php b/src/Entity/Type/RefundEnumType.php index 22cf8072b..828fac2b8 100644 --- a/src/Entity/Type/RefundEnumType.php +++ b/src/Entity/Type/RefundEnumType.php @@ -57,7 +57,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str return (string) $value->getValue(); } - throw ConversionException::conversionFailed((string) $value, 'sylius_refund_refund_type'); + $stringValue = (string) $value; + $stringValue = strlen($stringValue) > 32 ? substr($stringValue, 0, 20) . '...' : $stringValue; + + throw new ConversionException(sprintf('Could not convert database value "%s" to Doctrine Type sylius_refund_refund_type', $stringValue)); } protected function createType(string $value): RefundTypeInterface diff --git a/tests/Behat/Resources/services.php b/tests/Behat/Resources/services.php new file mode 100644 index 000000000..a3862aadb --- /dev/null +++ b/tests/Behat/Resources/services.php @@ -0,0 +1,160 @@ +services(); + $parameters = $container->parameters(); + $parameters->set('sylius.behat.page.admin.order.show.class', AdminOrderShowPage::class); + $parameters->set('sylius.behat.page.shop.order.show.class', ShopOrderShowPage::class); + + $services->defaults() + ->public(); + + $services->set(OrderRefundsPage::class) + ->parent('sylius.behat.symfony_page'); + + $services->set(CreditMemoDetailsPage::class) + ->parent('sylius.behat.symfony_page') + ->args([service('sylius.behat.table_accessor')]); + + $services->set(CreditMemoIndexPage::class) + ->parent('sylius.behat.page.admin.crud.index') + ->args(['sylius_refund_admin_credit_memo_index']); + + $services->set(Element::class) + ->private() + ->abstract() + ->args([ + service('behat.mink.default_session'), + service('behat.mink.parameters'), + ]); + + $services->set(PdfDownloadElement::class) + ->private() + ->parent(Element::class); + + $services->set(ApplicationRefundingContext::class) + ->args([ + service('sylius.repository.order'), + service('sylius_refund.repository.refund'), + service('sylius_refund.provider.remaining_total'), + service('sylius.command_bus'), + service('sylius.behat.email_checker'), + ]); + + $services->set(ApplicationCreditMemoContext::class) + ->args([ + service('sylius_refund.repository.credit_memo'), + service('sylius_refund.provider.current_date_time_immutable'), + '%sylius_refund.credit_memo_save_path%', + ]); + + $services->set(ManagingOrdersContext::class) + ->args([ + service('sylius.behat.page.admin.order.show'), + service('sylius.behat.page.admin.order.index'), + service('sylius.behat.notification_checker.shop'), + ]); + + $services->set(UiRefundingContext::class) + ->args([ + service(OrderRefundsPage::class), + service('sylius.behat.notification_checker.admin'), + service('sylius.behat.email_checker'), + ]); + + $services->set(UiCreditMemoContext::class) + ->args([ + service('sylius.behat.page.admin.order.show'), + service(CreditMemoIndexPage::class), + service(CreditMemoDetailsPage::class), + service(PdfDownloadElement::class), + service('sylius_refund.repository.credit_memo'), + service('sylius_refund.provider.current_date_time_immutable'), + ]); + + $services->set(SetupRefundingContext::class) + ->args([ + service('sylius.repository.order'), + service('sylius.command_bus'), + service(FailedCreditMemoGenerator::class), + service(FailedRefundPaymentFactory::class), + ]); + + $services->set(SetupOrderContext::class) + ->args([ + service('sylius.manager.order'), + service('sylius.behat.shared_storage'), + service('sylius_abstraction.state_machine'), + ]); + + $services->set(PaymentContext::class) + ->args([ + service('sylius_abstraction.state_machine'), + service('sylius.behat.shared_storage'), + ]); + + $services->set(TransformOrderContext::class) + ->args([service('sylius.repository.order')]); + + $services->set(PriceContext::class); + + $services->set(ShopCustomerCreditMemoContext::class) + ->args([ + service('sylius.behat.page.shop.order.show'), + service(PdfDownloadElement::class), + ]); + + $services->set(ChannelContext::class) + ->args([ + service('sylius.behat.shared_storage'), + service('sylius.behat.factory.default_united_states_channel'), + service('sylius.behat.factory.default_channel'), + service('sylius.manager.channel'), + ]); + + $services->set(EmailsContext::class) + ->args([service('sylius.behat.email_checker')]); + + $services->set(ProductContext::class) + ->args([service('sylius.behat.context.setup.product')]); + + $services->set(CreditMemosContext::class) + ->args(['%sylius_refund.credit_memo_save_path%']); + + $services->set(FailedRefundPaymentFactory::class) + ->private() + ->decorate('sylius_refund.factory.refund_payment') + ->args([service('.inner')]); + + $services->set(FailedCreditMemoGenerator::class) + ->private() + ->decorate('sylius_refund.generator.credit_memo') + ->args([service('.inner')]); +}; diff --git a/tests/Behat/Resources/services.xml b/tests/Behat/Resources/services.xml deleted file mode 100644 index 579220efe..000000000 --- a/tests/Behat/Resources/services.xml +++ /dev/null @@ -1,129 +0,0 @@ - - - - - Tests\Sylius\RefundPlugin\Behat\Page\Admin\Order\ShowPage - Tests\Sylius\RefundPlugin\Behat\Page\Shop\Order\ShowPage - - - - - - - - - - - sylius_refund_admin_credit_memo_index - - - - - - - - - - - - - - - - - - - - %sylius_refund.credit_memo_save_path% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %sylius_refund.credit_memo_save_path% - - - - - - - - - - - diff --git a/tests/TestApplication/config/services_test.php b/tests/TestApplication/config/services_test.php index c4c8cbb16..11320ed86 100644 --- a/tests/TestApplication/config/services_test.php +++ b/tests/TestApplication/config/services_test.php @@ -7,9 +7,9 @@ return function (ContainerConfigurator $container) { $env = $_ENV['APP_ENV'] ?? 'dev'; - if (str_starts_with($env, 'test')) { + if (str_starts_with($env, 'test') && filter_var(getenv('TEST_SYLIUS_REFUND_BEHAT_ENABLED') ?: 'true', FILTER_VALIDATE_BOOLEAN)) { $container->import('../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml'); - $container->import('@SyliusRefundPlugin/tests/Behat/Resources/services.xml'); + $container->import('@SyliusRefundPlugin/tests/Behat/Resources/services.php'); } if (filter_var($_ENV['TEST_SYLIUS_REFUND_PDF_GENERATION_DISABLED'], FILTER_VALIDATE_BOOLEAN)) { From 75d07d1c955f48e1a9520f2db93c12e0cd0f39ac Mon Sep 17 00:00:00 2001 From: TheMilek Date: Fri, 18 Sep 2026 11:40:52 +0200 Subject: [PATCH 3/6] Use released Sylius 2.3 packages and run Behat on that row --- .github/workflows/build.yaml | 25 +-- .gitignore | 1 + behat.dist.php | 59 +++++++ behat.yml.dist | 40 ----- composer.json | 15 +- .../Context/Application/CreditMemoContext.php | 56 ++----- .../Context/Application/EmailsContext.php | 5 +- .../Context/Application/RefundingContext.php | 81 +++------- .../Behat/Context/Hook/CreditMemosContext.php | 5 +- tests/Behat/Context/Setup/ChannelContext.php | 9 +- tests/Behat/Context/Setup/OrderContext.php | 4 +- tests/Behat/Context/Setup/PaymentContext.php | 13 +- tests/Behat/Context/Setup/ProductContext.php | 5 +- .../Behat/Context/Setup/RefundingContext.php | 42 ++--- .../Behat/Context/Transform/OrderContext.php | 5 +- .../Behat/Context/Transform/PriceContext.php | 5 +- tests/Behat/Context/Ui/CreditMemoContext.php | 128 ++++------------ .../Context/Ui/ManagingOrdersContext.php | 45 ++---- tests/Behat/Context/Ui/RefundingContext.php | 145 +++++------------- .../Ui/Shop/Customer/CreditMemoContext.php | 18 +-- tests/Behat/Resources/suites.php | 13 ++ tests/Behat/Resources/suites.yml | 4 - .../Resources/suites/application/refunds.php | 64 ++++++++ .../Resources/suites/application/refunds.yaml | 41 ----- .../suites/ui/customer_credit_memos.php | 60 ++++++++ .../suites/ui/customer_credit_memos.yaml | 38 ----- tests/Behat/Resources/suites/ui/refunds.php | 78 ++++++++++ tests/Behat/Resources/suites/ui/refunds.yaml | 50 ------ .../TestApplication/config/services_test.php | 2 +- 29 files changed, 449 insertions(+), 607 deletions(-) create mode 100644 behat.dist.php delete mode 100644 behat.yml.dist create mode 100644 tests/Behat/Resources/suites.php delete mode 100644 tests/Behat/Resources/suites.yml create mode 100644 tests/Behat/Resources/suites/application/refunds.php delete mode 100644 tests/Behat/Resources/suites/application/refunds.yaml create mode 100644 tests/Behat/Resources/suites/ui/customer_credit_memos.php delete mode 100644 tests/Behat/Resources/suites/ui/customer_credit_memos.yaml create mode 100644 tests/Behat/Resources/suites/ui/refunds.php delete mode 100644 tests/Behat/Resources/suites/ui/refunds.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8748d504c..1e30fde28 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -112,8 +112,7 @@ jobs: composer_minimum_stability: "" # TODO: drop the "~2.3.0" restriction to a plain matrix entry (instead of an - # include row) once sylius/sylius 2.3 has a stable release and - # sylius/test-application ships matching support on Packagist. + # include row) once sylius/sylius 2.3 has a stable release. - php: "8.4" symfony: "^8.0" @@ -144,8 +143,6 @@ jobs: TEST_SYLIUS_STATE_MACHINE_ADAPTER: "${{ matrix.state_machine_adapter }}" TEST_SYLIUS_REFUND_PDF_GENERATION_DISABLED: ${{ matrix.wkhtmltopdf == false }} TEST_SYLIUS_REFUND_PDF_LEGACY: "${{ matrix.legacy_pdf_generation }}" - # TODO: drop once the Behat/Mink ecosystem supports Behat 4 (see the "Run Behat" step). - TEST_SYLIUS_REFUND_BEHAT_ENABLED: ${{ matrix.sylius != '~2.3.0' }} steps: - @@ -206,22 +203,6 @@ jobs: composer require winzou/state-machine:^0.4 --no-update composer require winzou/state-machine-bundle:^0.6 --no-update - - - # TODO: remove this whole step once https://github.com/Sylius/TestApplication/pull/48 - # merges and a real Sylius-2.3-compatible sylius/test-application release/branch - # exists on Packagist (drops the fork pointer), AND the Behat/Mink ecosystem - # supports Behat 4 / Symfony 8 (drops the package removals — none of behat/behat, - # behat/mink, or the friends-of-behat/* packages have a stable release supporting - # symfony/console ^8.0 yet; dmore/behat-chrome-extension has no Behat-4-compatible - # release at all). At that point the "Restrict Sylius version" step above is - # enough, and Behat can run for this row too (see the "Run Behat" step below). - name: Point sylius/test-application at the Sylius 2.3 prep fork, drop the Behat toolchain - if: matrix.sylius == '~2.3.0' - run: | - composer config repositories.sylius-test-application-fork vcs https://github.com/rust-le/TestApplication.git - composer require sylius/test-application:dev-sylius-2.3-symfony-8 --no-update --no-scripts --no-interaction - composer remove behat/behat behat/mink dmore/behat-chrome-extension dmore/chrome-mink-driver friends-of-behat/mink-browserkit-driver friends-of-behat/mink-debug-extension friends-of-behat/mink-extension friends-of-behat/page-object-extension friends-of-behat/suite-settings-extension friends-of-behat/symfony-extension friends-of-behat/variadic-extension --dev --no-update --no-interaction - - name: Build Sylius Test Application uses: SyliusLabs/BuildTestAppAction@v3.2.0 @@ -263,11 +244,7 @@ jobs: run: vendor/bin/phpunit --colors=always - - # TODO: drop this condition once dmore/behat-chrome-extension (or a replacement - # Chrome driver) supports Behat 4 — until then there's no JS/e2e driver available - # for the Sylius 2.3 / Symfony 8 row (see the dmore/* removal step above). name: Run Behat - if: matrix.sylius != '~2.3.0' run: | if [ "${{ matrix.wkhtmltopdf }}" != "false" ]; then vendor/bin/behat --colors --strict -vvv --no-interaction -f progress --tags="~@pdf_disabled" || vendor/bin/behat --colors --strict -vvv --no-interaction -f progress --tags="~@pdf_disabled" --rerun || vendor/bin/behat --colors --strict -vvv --no-interaction -f progress --tags="~@pdf_disabled" --rerun diff --git a/.gitignore b/.gitignore index 9117e715e..a42f11f99 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ phpspec.yml /.phpunit.result.cache +/behat.php /behat.yml diff --git a/behat.dist.php b/behat.dist.php new file mode 100644 index 000000000..34811eb66 --- /dev/null +++ b/behat.dist.php @@ -0,0 +1,59 @@ +import([ + // Sylius 2.3 ships its suites as a PHP config, earlier versions ship YAML. + is_file(__DIR__ . '/' . $syliusSuitesPath . '.php') ? $syliusSuitesPath . '.php' : $syliusSuitesPath . '.yml', + 'tests/Behat/Resources/suites.php', + ]) + ->withProfile( + (new Profile('default')) + ->withExtension(new Extension(ChromeExtension::class)) + ->withExtension(new Extension(MinkDebugExtension::class, [ + 'directory' => 'etc/build', + 'clean_start' => false, + 'screenshot' => true, + ])) + ->withExtension(new Extension(MinkExtension::class, [ + 'files_path' => '%paths.base%/vendor/sylius/sylius/src/Sylius/Behat/Resources/fixtures/', + 'base_url' => 'http://127.0.0.1:8080/', + 'default_session' => 'symfony', + 'javascript_session' => 'chrome', + 'sessions' => [ + 'symfony' => [ + 'symfony' => null, + ], + 'chrome' => [ + 'chrome' => [ + 'api_url' => 'http://127.0.0.1:9222', + 'validate_certificate' => false, + ], + ], + ], + 'show_auto' => false, + ])) + ->withExtension(new Extension(SymfonyExtension::class, [ + 'bootstrap' => 'vendor/sylius/test-application/config/bootstrap.php', + 'kernel' => [ + 'class' => 'Sylius\TestApplication\Kernel', + ], + ])) + ->withExtension(new Extension(VariadicExtension::class)), + ) +; diff --git a/behat.yml.dist b/behat.yml.dist deleted file mode 100644 index 1aa28cd6b..000000000 --- a/behat.yml.dist +++ /dev/null @@ -1,40 +0,0 @@ -# This file is part of the Sylius package. -# (c) Sylius Sp. z o.o. - -imports: - - vendor/sylius/sylius/src/Sylius/Behat/Resources/config/suites.yml - - tests/Behat/Resources/suites.yml - -default: - extensions: - DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~ - - FriendsOfBehat\MinkDebugExtension: - directory: etc/build - clean_start: false - screenshot: true - - Behat\MinkExtension: - files_path: "%paths.base%/vendor/sylius/sylius/src/Sylius/Behat/Resources/fixtures/" - base_url: "http://127.0.0.1:8080/" - default_session: symfony - javascript_session: chrome - sessions: - symfony: - symfony: ~ - chrome: - chrome: - api_url: http://127.0.0.1:9222 - validate_certificate: false - show_auto: false - - FriendsOfBehat\SymfonyExtension: - bootstrap: vendor/sylius/test-application/config/bootstrap.php - kernel: - class: Sylius\TestApplication\Kernel - - FriendsOfBehat\VariadicExtension: ~ - - FriendsOfBehat\SuiteSettingsExtension: - paths: - - features diff --git a/composer.json b/composer.json index e8a5b5032..d15e38ba2 100644 --- a/composer.json +++ b/composer.json @@ -30,22 +30,21 @@ "symfony/messenger": "^6.4 || ^7.4 || ^8.0" }, "require-dev": { - "behat/behat": "^3.6.1", + "behat/behat": "^3.22 || 4.0.0-alpha1", "behat/mink": "^1.10 || ^1.13", - "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", - "friends-of-behat/mink-browserkit-driver": "^1.4", - "friends-of-behat/mink-debug-extension": "^2.0", - "friends-of-behat/mink-extension": "^2.4", + "friends-of-behat/mink-browserkit-driver": "^1.6.3", + "friends-of-behat/mink-debug-extension": "^2.2", + "friends-of-behat/mink-extension": "^2.7 || 3.0.0-alpha1", "friends-of-behat/page-object-extension": "^0.3", - "friends-of-behat/suite-settings-extension": "^1.0", - "friends-of-behat/symfony-extension": "^2.1", - "friends-of-behat/variadic-extension": "^1.3", + "friends-of-behat/symfony-extension": "^2.6.2", + "friends-of-behat/variadic-extension": "^1.6", "matthiasnoback/symfony-config-test": "^6.1", "matthiasnoback/symfony-dependency-injection-test": "^6.2", "phpstan/phpstan": "^2.2", "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^10.5", + "sylius-labs/behat-chrome-extension": "^1.5", "sylius-labs/coding-standard": "^4.2", "sylius/test-application": "^2.0.0@alpha", "symfony/browser-kit": "^6.4 || ^7.4 || ^8.0", diff --git a/tests/Behat/Context/Application/CreditMemoContext.php b/tests/Behat/Context/Application/CreditMemoContext.php index cd903a834..54bef046b 100644 --- a/tests/Behat/Context/Application/CreditMemoContext.php +++ b/tests/Behat/Context/Application/CreditMemoContext.php @@ -5,6 +5,8 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Application; use Behat\Behat\Context\Context; +use Behat\Step\Then; +use Behat\Step\When; use Doctrine\Persistence\ObjectRepository; use Sylius\Component\Addressing\Model\CountryInterface; use Sylius\Component\Core\Model\ChannelInterface; @@ -30,9 +32,7 @@ public function __construct( ) { } - /** - * @When I browse the details of the only credit memo generated for order :order - */ + #[When('I browse the details of the only credit memo generated for order :order')] public function browseTheDetailsOfTheOnlyCreditMemoGeneratedForOrder(OrderInterface $order): void { $creditMemos = $this->creditMemoRepository->findBy(['order' => $order]); @@ -40,9 +40,7 @@ public function browseTheDetailsOfTheOnlyCreditMemoGeneratedForOrder(OrderInterf $this->creditMemo = $creditMemos[0]; } - /** - * @Then I should have :count credit memo generated for order :order - */ + #[Then('I should have :count credit memo generated for order :order')] public function shouldHaveCountCreditMemoGeneratedForThisOrder(int $count, OrderInterface $order): void { $creditMemos = $this->creditMemoRepository->findBy(['order' => $order]); @@ -50,9 +48,7 @@ public function shouldHaveCountCreditMemoGeneratedForThisOrder(int $count, Order Assert::count($creditMemos, $count); } - /** - * @Then it should have sequential number generated from current date - */ + #[Then('it should have sequential number generated from current date')] public function shouldHaveSequentialNumberGeneratedFromCurrentDate(): void { Assert::same( @@ -61,10 +57,8 @@ public function shouldHaveSequentialNumberGeneratedFromCurrentDate(): void ); } - /** - * @Then /^it should contain (\d+) "([^"]+)" product(?:|s) with ("[^"]+") net value, ("[^"]+") tax amount and ("[^"]+") gross value in "([^"]+)" currency$/ - * @Then /^it should contain (\d+) "([^"]+)" shipment(?:|s) with ("[^"]+") net value, ("[^"]+") tax amount and ("[^"]+") gross value in "([^"]+)" currency$/ - */ + #[Then('/^it should contain (\d+) "([^"]+)" product(?:|s) with ("[^"]+") net value, ("[^"]+") tax amount and ("[^"]+") gross value in "([^"]+)" currency$/')] + #[Then('/^it should contain (\d+) "([^"]+)" shipment(?:|s) with ("[^"]+") net value, ("[^"]+") tax amount and ("[^"]+") gross value in "([^"]+)" currency$/')] public function itShouldContainProductWithNetValueTaxAmountAndGrossValueInCurrency( int $quantity, string $productName, @@ -89,9 +83,7 @@ public function itShouldContainProductWithNetValueTaxAmountAndGrossValueInCurren throw new \InvalidArgumentException('There is no item with given data.'); } - /** - * @Then /^it should contain a tax item "([^"]+)" with amount ("[^"]+") in "([^"]+)" currency$/ - */ + #[Then('/^it should contain a tax item "([^"]+)" with amount ("[^"]+") in "([^"]+)" currency$/')] public function itShouldContainATaxItemWithAmountInCurrency(string $label, int $amount, string $currencyCode): void { /** @var TaxItemInterface $taxItem */ @@ -104,51 +96,39 @@ public function itShouldContainATaxItemWithAmountInCurrency(string $label, int $ throw new \InvalidArgumentException(sprintf('There is no tax item %s with given amount.', $label)); } - /** - * @Then it should be issued in :channelName channel - */ + #[Then('it should be issued in :channelName channel')] public function creditMemoShouldBeIssuedInChannel(string $channelName): void { Assert::implementsInterface($this->creditMemo->getChannel(), ChannelInterface::class); Assert::same($this->creditMemo->getChannel()->getName(), $channelName); } - /** - * @Then /^its total should be ("[^"]+") in "([^"]+)" currency$/ - */ + #[Then('/^its total should be ("[^"]+") in "([^"]+)" currency$/')] public function creditMemoTotalShouldBe(int $total, string $currencyCode): void { Assert::same($this->creditMemo->getTotal(), $total); Assert::same($this->creditMemo->getCurrencyCode(), $currencyCode); } - /** - * @Then /^its net total should be ("[^"]+")$/ - */ + #[Then('/^its net total should be ("[^"]+")$/')] public function itsNetTotalShouldBe(int $total): void { Assert::same($this->creditMemo->getNetValueTotal(), $total); } - /** - * @Then /^its tax total should be ("[^"]+")$/ - */ + #[Then('/^its tax total should be ("[^"]+")$/')] public function itsTaxTotalShouldBe(int $total): void { Assert::same($this->creditMemo->getTaxTotal(), $total); } - /** - * @Then it should be commented with :comment - */ + #[Then('it should be commented with :comment')] public function itShouldBeCommentedWith(string $comment): void { Assert::same($this->creditMemo->getComment(), $comment); } - /** - * @Then it should be issued from :customerName, :street, :postcode :city in the :country - */ + #[Then('it should be issued from :customerName, :street, :postcode :city in the :country')] public function itShouldBeIssuedFrom( string $customerName, string $street, @@ -166,9 +146,7 @@ public function itShouldBeIssuedFrom( Assert::same($customerBillingData->getCountryCode(), $country->getCode()); } - /** - * @Then it should be issued to :company, :street, :postcode :city in the :country with :taxId tax ID - */ + #[Then('it should be issued to :company, :street, :postcode :city in the :country with :taxId tax ID')] public function itShouldBeIssuedTo( string $company, string $street, @@ -188,9 +166,7 @@ public function itShouldBeIssuedTo( Assert::same($taxId, $shopBillingData->getTaxId()); } - /** - * @Then the credit memo for :order order should be saved on the server - */ + #[Then('the credit memo for :order order should be saved on the server')] public function theCreditMemoForOrderShouldBeSavedOnTheServer(OrderInterface $order): void { $creditMemo = $this->creditMemoRepository->findOneBy(['order' => $order]); diff --git a/tests/Behat/Context/Application/EmailsContext.php b/tests/Behat/Context/Application/EmailsContext.php index f119bc0b6..c1a1b060a 100644 --- a/tests/Behat/Context/Application/EmailsContext.php +++ b/tests/Behat/Context/Application/EmailsContext.php @@ -5,6 +5,7 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Application; use Behat\Behat\Context\Context; +use Behat\Step\Then; use Sylius\Behat\Service\Checker\EmailCheckerInterface as BehatEmailCheckerInterface; use Webmozart\Assert\Assert; @@ -14,9 +15,7 @@ public function __construct(private readonly BehatEmailCheckerInterface $emailCh { } - /** - * @Then an email with credit memo should be sent again to :email - */ + #[Then('an email with credit memo should be sent again to :email')] public function quantityOfEmailsForCustomerWithCreditMemo(string $email): void { Assert::same($this->emailChecker->countMessagesTo($email), 2); diff --git a/tests/Behat/Context/Application/RefundingContext.php b/tests/Behat/Context/Application/RefundingContext.php index 67fd22799..30e603361 100644 --- a/tests/Behat/Context/Application/RefundingContext.php +++ b/tests/Behat/Context/Application/RefundingContext.php @@ -5,12 +5,15 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Application; use Behat\Behat\Context\Context; +use Behat\Step\Given; +use Behat\Step\Then; +use Behat\Step\When; +use Sylius\Behat\Service\Checker\EmailCheckerInterface as BehatEmailCheckerInterface; use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\OrderItemUnitInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; -use Sylius\Behat\Service\Checker\EmailCheckerInterface as BehatEmailCheckerInterface; use Sylius\Component\Order\Model\OrderInterface as CoreOrderInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\RefundPlugin\Command\RefundUnits; @@ -39,18 +42,14 @@ public function __construct( ) { } - /** - * @When I want to refund some units of order :orderNumber - */ + #[When('I want to refund some units of order :orderNumber')] public function wantToRefundSomeUnitsOfOrder(string $orderNumber): void { $this->order = $this->orderRepository->findOneByNumber($orderNumber); } - /** - * @When /^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment)$/ - * @When /^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment) and "([^"]+)" comment$/ - */ + #[When('/^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment)$/')] + #[When('/^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment) and "([^"]+)" comment$/')] public function decideToRefundProduct( int $unitNumber, string $productName, @@ -67,9 +66,7 @@ public function decideToRefundProduct( )); } - /** - * @Given /^I decide to refund ("[^"]+") from (\d)st "([^"]+)" product with ("[^"]+" payment)$/ - */ + #[Given('/^I decide to refund ("[^"]+") from (\d)st "([^"]+)" product with ("[^"]+" payment)$/')] public function decideToRefundPartFromProductWithPayment( int $partialPrice, int $unitNumber, @@ -90,9 +87,7 @@ public function decideToRefundPartFromProductWithPayment( } } - /** - * @When /^I decide to refund order shipment with ("[^"]+" payment)$/ - */ + #[When('/^I decide to refund order shipment with ("[^"]+" payment)$/')] public function decideToRefundOrderShipment(PaymentMethodInterface $paymentMethod): void { $shippingAdjustment = $this->order->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->first(); @@ -103,9 +98,7 @@ public function decideToRefundOrderShipment(PaymentMethodInterface $paymentMetho )); } - /** - * @When I decide to refund :shippingMethodName order shipment with :paymentMethod payment - */ + #[When('I decide to refund :shippingMethodName order shipment with :paymentMethod payment')] public function iDecideToRefundOrderShipmentWithPayment( string $shippingMethodName, PaymentMethodInterface $paymentMethod @@ -118,9 +111,7 @@ public function iDecideToRefundOrderShipmentWithPayment( )); } - /** - * @When /^I decide to refund ("[^"]+") from order shipment with ("[^"]+" payment)$/ - */ + #[When('/^I decide to refund ("[^"]+") from order shipment with ("[^"]+" payment)$/')] public function decideToRefundPartOfOrderShipment(int $amount, PaymentMethodInterface $paymentMethod): void { $shippingAdjustment = $this->order->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->first(); @@ -130,9 +121,7 @@ public function decideToRefundPartOfOrderShipment(int $amount, PaymentMethodInte )); } - /** - * @When /^I try to refund ("[^"]+") from order shipment with ("[^"]+" payment)$/ - */ + #[When('/^I try to refund ("[^"]+") from order shipment with ("[^"]+" payment)$/')] public function tryToRefundPartOfOrderShipment(int $amount, PaymentMethodInterface $paymentMethod): void { $shippingAdjustment = $this->order->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->first(); @@ -146,9 +135,7 @@ public function tryToRefundPartOfOrderShipment(int $amount, PaymentMethodInterfa } } - /** - * @When /^I decide to refund order shipment and (\d)st "([^"]+)" product with ("[^"]+" payment)$/ - */ + #[When('/^I decide to refund order shipment and (\d)st "([^"]+)" product with ("[^"]+" payment)$/')] public function decideToRefundProductAndShipment( int $unitNumber, string $productName, @@ -171,9 +158,7 @@ public function decideToRefundProductAndShipment( ); } - /** - * @When I refund all units of :order order with :paymentMethod payment method - */ + #[When('I refund all units of :order order with :paymentMethod payment method')] public function iRefundAllUnitsOfOrderWithPaymentMethod( OrderInterface $order, PaymentMethodInterface $paymentMethod, @@ -195,9 +180,7 @@ public function iRefundAllUnitsOfOrderWithPaymentMethod( )); } - /** - * @Then /^this order refunded total should(?:| still) be ("[^"]+")$/ - */ + #[Then('/^this order refunded total should(?:| still) be ("[^"]+")$/')] public function refundedTotalShouldBe(int $refundedTotal): void { $orderRefunds = $this->refundRepository->findBy(['order' => $this->order]); @@ -209,9 +192,7 @@ public function refundedTotalShouldBe(int $refundedTotal): void Assert::same($orderRefundedTotal, $refundedTotal); } - /** - * @Then /^(\d+)st "([^"]+)" product should have ("[^"]+") refunded$/ - */ + #[Then('/^(\d+)st "([^"]+)" product should have ("[^"]+") refunded$/')] public function productShouldHaveSomeAmountRefunded(int $unitNumber, string $productName, int $amount): void { $unit = $this->getOrderUnit($unitNumber, $productName); @@ -229,9 +210,7 @@ public function productShouldHaveSomeAmountRefunded(int $unitNumber, string $pro Assert::eq($amount, $refundedTotal); } - /** - * @Then /^I should not be able to refund (\d)st unit with product "([^"]+)"$/ - */ + #[Then('/^I should not be able to refund (\d)st unit with product "([^"]+)"$/')] public function shouldNotBeAbleToRefundUnitWithProduct(int $unitNumber, string $productName): void { $unit = $this->getOrderUnit($unitNumber, $productName); @@ -250,9 +229,7 @@ public function shouldNotBeAbleToRefundUnitWithProduct(int $unitNumber, string $ throw new \Exception('RefundUnits command should fail'); } - /** - * @Then I should not be able to refund order shipment - */ + #[Then('I should not be able to refund order shipment')] public function shouldNotBeAbleToRefundOrderShipment(): void { /** @var AdjustmentInterface $shippingAdjustment */ @@ -272,9 +249,7 @@ public function shouldNotBeAbleToRefundOrderShipment(): void throw new \Exception('RefundUnits command should fail'); } - /** - * @Then /^I should still be able to refund order shipment with ("[^"]+" payment)$/ - */ + #[Then('/^I should still be able to refund order shipment with ("[^"]+" payment)$/')] public function shouldStillBeAbleToRefundOrderShipment(PaymentMethodInterface $paymentMethod): void { /** @var AdjustmentInterface $shippingAdjustment */ @@ -290,9 +265,7 @@ public function shouldStillBeAbleToRefundOrderShipment(PaymentMethodInterface $p } } - /** - * @Then /^I should(?:| still) be able to refund (\d)(?:|st|nd|rd) unit with product "([^"]+)" with ("[^"]+" payment)$/ - */ + #[Then('/^I should(?:| still) be able to refund (\d)(?:|st|nd|rd) unit with product "([^"]+)" with ("[^"]+" payment)$/')] public function shouldBeAbleToRefundUnitWithProduct( int $unitNumber, string $productName, @@ -308,20 +281,16 @@ public function shouldBeAbleToRefundUnitWithProduct( )); } - /** - * @Then email to :email with credit memo should be sent - */ + #[Then('email to :email with credit memo should be sent')] public function emailToWithCreditMemoShouldBeSent(string $email): void { Assert::true($this->emailChecker->hasMessageTo('Some of the units from your order have been refunded.', $email)); } - /** - * @Then I should be notified that selected order units have been successfully refunded - * @Then I should be notified that I cannot refund more money than the order unit total - * @Then I should be notified that I cannot refund more money than the shipment total - * @Then I should be notified that refunded amount should be greater than 0 - */ + #[Then('I should be notified that selected order units have been successfully refunded')] + #[Then('I should be notified that I cannot refund more money than the order unit total')] + #[Then('I should be notified that I cannot refund more money than the shipment total')] + #[Then('I should be notified that refunded amount should be greater than 0')] public function notificationSteps(): void { // intentionally left blank - not relevant in application scope diff --git a/tests/Behat/Context/Hook/CreditMemosContext.php b/tests/Behat/Context/Hook/CreditMemosContext.php index 7cbbd9ca4..f68d66b28 100644 --- a/tests/Behat/Context/Hook/CreditMemosContext.php +++ b/tests/Behat/Context/Hook/CreditMemosContext.php @@ -14,6 +14,7 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Hook; use Behat\Behat\Context\Context; +use Behat\Hook\BeforeScenario; final class CreditMemosContext implements Context { @@ -21,9 +22,7 @@ public function __construct(private readonly string $creditMemosPath) { } - /** - * @BeforeScenario - */ + #[BeforeScenario] public function clearCreditMemosPath(): void { if (!is_dir($this->creditMemosPath)) { diff --git a/tests/Behat/Context/Setup/ChannelContext.php b/tests/Behat/Context/Setup/ChannelContext.php index e7c6fecbb..8f9a11c7a 100644 --- a/tests/Behat/Context/Setup/ChannelContext.php +++ b/tests/Behat/Context/Setup/ChannelContext.php @@ -5,6 +5,7 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Setup; use Behat\Behat\Context\Context; +use Behat\Step\Given; use Doctrine\ORM\EntityManagerInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Formatter\StringInflector; @@ -20,9 +21,7 @@ public function __construct( ) { } - /** - * @Given the store operates on a single :color channel in "United States" - */ + #[Given('the store operates on a single :color channel in "United States"')] public function storeOperatesOnASingleColorChannelInUnitedStates(string $color): void { $defaultData = $this->unitedStatesChannelFactory->create(); @@ -33,9 +32,7 @@ public function storeOperatesOnASingleColorChannelInUnitedStates(string $color): $this->channelManager->flush(); } - /** - * @Given the store operates on a channel named :channelName in :currencyCode currency with :color color - */ + #[Given('the store operates on a channel named :channelName in :currencyCode currency with :color color')] public function theStoreOperatesOnAColorChannelNamed(string $channelName, string $currencyCode, string $color): void { $channelCode = StringInflector::nameToLowercaseCode($channelName); diff --git a/tests/Behat/Context/Setup/OrderContext.php b/tests/Behat/Context/Setup/OrderContext.php index fdd5724ca..827591e8f 100644 --- a/tests/Behat/Context/Setup/OrderContext.php +++ b/tests/Behat/Context/Setup/OrderContext.php @@ -24,9 +24,7 @@ public function __construct( ) { } - /** - * @Given /^(this order) has been placed in ("[^"]+" channel)$/ - */ + #[Given('/^(this order) has been placed in ("[^"]+" channel)$/')] public function orderHasBeenPlacedInChannel(OrderInterface $order, ChannelInterface $channel): void { $order->setChannel($channel); diff --git a/tests/Behat/Context/Setup/PaymentContext.php b/tests/Behat/Context/Setup/PaymentContext.php index db8c0528a..cab062819 100644 --- a/tests/Behat/Context/Setup/PaymentContext.php +++ b/tests/Behat/Context/Setup/PaymentContext.php @@ -14,6 +14,7 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Setup; use Behat\Behat\Context\Context; +use Behat\Step\Given; use Sylius\Abstraction\StateMachine\StateMachineInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\OrderInterface; @@ -29,18 +30,14 @@ public function __construct( ) { } - /** - * @Given the payment of order :order failed - */ + #[Given('the payment of order :order failed')] public function paymentOfOrderFailed(OrderInterface $order): void { $payment = $order->getLastPayment(); $this->stateMachineFactory->apply($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_FAIL); } - /** - * @Given /^the customer chose ("[^"]+" payment) method$/ - */ + #[Given('/^the customer chose ("[^"]+" payment) method$/')] public function theCustomerChosePaymentMethod(PaymentMethodInterface $paymentMethod): void { /** @var OrderInterface $order */ @@ -52,9 +49,7 @@ public function theCustomerChosePaymentMethod(PaymentMethodInterface $paymentMet $this->sharedStorage->set('payment', $lastPayment); } - /** - * @Given /^(this payment) has been paid$/ - */ + #[Given('/^(this payment) has been paid$/')] public function andThisPaymentHasBeenPaid(PaymentInterface $payment): void { $this->stateMachineFactory->apply($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_COMPLETE); diff --git a/tests/Behat/Context/Setup/ProductContext.php b/tests/Behat/Context/Setup/ProductContext.php index dd2e15954..7d4c9f257 100644 --- a/tests/Behat/Context/Setup/ProductContext.php +++ b/tests/Behat/Context/Setup/ProductContext.php @@ -14,6 +14,7 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Setup; use Behat\Behat\Context\Context; +use Behat\Step\Given; use Sylius\Behat\Context\Setup\ProductContext as BaseProductContext; final class ProductContext implements Context @@ -22,9 +23,7 @@ public function __construct(private readonly BaseProductContext $baseProductCont { } - /** - * @Given the store has a free product :productName - */ + #[Given('the store has a free product :productName')] public function theStoreHasAFreeProduct(string $productName): void { $this->baseProductContext->storeHasAProductPricedAt($productName, 0, null); diff --git a/tests/Behat/Context/Setup/RefundingContext.php b/tests/Behat/Context/Setup/RefundingContext.php index 29def3363..f1a6224c9 100644 --- a/tests/Behat/Context/Setup/RefundingContext.php +++ b/tests/Behat/Context/Setup/RefundingContext.php @@ -5,6 +5,8 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Setup; use Behat\Behat\Context\Context; +use Behat\Hook\AfterScenario; +use Behat\Step\Given; use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\OrderItemUnitInterface; @@ -30,10 +32,8 @@ public function __construct( ) { } - /** - * @Given /^(\d)(?:|st|nd|rd) "([^"]+)" product from order "#([^"]+)" has already been refunded with ("[^"]+" payment)$/ - * @Given :productName product from order :orderNumber has already been refunded with :paymentMethod payment - */ + #[Given('/^(\d)(?:|st|nd|rd) "([^"]+)" product from order "#([^"]+)" has already been refunded with ("[^"]+" payment)$/')] + #[Given(':productName product from order :orderNumber has already been refunded with :paymentMethod payment')] public function productFromOrderHasAlreadyBeenRefunded( ?int $unitNumber, string $productName, @@ -56,9 +56,7 @@ public function productFromOrderHasAlreadyBeenRefunded( )); } - /** - * @Given /^the (\d)(?:|st|nd|rd) "([^"]+)" product from order "#([^"]+)" has a refund of ("[^"]+") with ("[^"]+" payment)$/ - */ + #[Given('/^the (\d)(?:|st|nd|rd) "([^"]+)" product from order "#([^"]+)" has a refund of ("[^"]+") with ("[^"]+" payment)$/')] public function theProductFromOrderHasARefundOfWith( int $unitNumber, string $productName, @@ -79,9 +77,7 @@ public function theProductFromOrderHasARefundOfWith( )); } - /** - * @Given /^the (\d)(?:|st|nd|rd) "([^"]+)" product from order "#([^"]+)" has a refund of ("[^"]+") with ("[^"]+" payment) done later$/ - */ + #[Given('/^the (\d)(?:|st|nd|rd) "([^"]+)" product from order "#([^"]+)" has a refund of ("[^"]+") with ("[^"]+" payment) done later$/')] public function theProductFromOrderHasARefundOfWithPaymentDoneLater( int $unitNumber, string $productName, @@ -93,9 +89,7 @@ public function theProductFromOrderHasARefundOfWithPaymentDoneLater( $this->theProductFromOrderHasARefundOfWith($unitNumber, $productName, $orderNumber, $partialTotal, $paymentMethod); } - /** - * @Given /^all units from the order "#([^"]+)" are refunded with ("[^"]+" payment)$/ - */ + #[Given('/^all units from the order "#([^"]+)" are refunded with ("[^"]+" payment)$/')] public function allUnitsFromOrderAreRefunded( string $orderNumber, PaymentMethodInterface $paymentMethod @@ -116,10 +110,8 @@ public function allUnitsFromOrderAreRefunded( )); } - /** - * @Given /^all units and shipment from the order "#([^"]+)" are refunded with ("[^"]+" payment)$/ - * @Given /^all units and shipment from the order "#([^"]+)" have been refunded with ("[^"]+" payment)$/ - */ + #[Given('/^all units and shipment from the order "#([^"]+)" are refunded with ("[^"]+" payment)$/')] + #[Given('/^all units and shipment from the order "#([^"]+)" have been refunded with ("[^"]+" payment)$/')] public function allUnitsAndShipmentFromOrderAreRefunded( string $orderNumber, PaymentMethodInterface $paymentMethod @@ -141,9 +133,7 @@ public function allUnitsAndShipmentFromOrderAreRefunded( $this->commandBus->dispatch(new RefundUnits($orderNumber, array_merge($units, $shipments), $paymentMethod->getId(), '')); } - /** - * @Given /^the "#([^"]+)" order's shipping cost already has a refund of ("[^"]+") with ("[^"]+" payment)$/ - */ + #[Given('/^the "#([^"]+)" order\'s shipping cost already has a refund of ("[^"]+") with ("[^"]+" payment)$/')] public function shipmentFromOrderHasAlreadyRefundedWithPayment( string $orderNumber, int $amount, @@ -163,25 +153,19 @@ public function shipmentFromOrderHasAlreadyRefundedWithPayment( )); } - /** - * @Given the credit memo generation is broken - */ + #[Given('the credit memo generation is broken')] public function theCreditMemoGenerationIsBroken(): void { $this->failedCreditMemoGenerator->failCreditMemoGeneration(); } - /** - * @Given the refund payment generation is broken - */ + #[Given('the refund payment generation is broken')] public function theRefundPaymentGenerationIsBroken(): void { $this->failedRefundPaymentFactory->failRefundPaymentCreation(); } - /** - * @AfterScenario - */ + #[AfterScenario] public function removeFailedGenerationFiles(): void { if (file_exists(FailedCreditMemoGenerator::FAILED_FILE)) { diff --git a/tests/Behat/Context/Transform/OrderContext.php b/tests/Behat/Context/Transform/OrderContext.php index a91f0143c..6f8e8331e 100644 --- a/tests/Behat/Context/Transform/OrderContext.php +++ b/tests/Behat/Context/Transform/OrderContext.php @@ -5,6 +5,7 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Transform; use Behat\Behat\Context\Context; +use Behat\Transformation\Transform; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Webmozart\Assert\Assert; @@ -16,9 +17,7 @@ public function __construct(private readonly OrderRepositoryInterface $orderRepo { } - /** - * @Transform /^order "([^"]+)"$/ - */ + #[Transform('/^order "([^"]+)"$/')] public function getOrderByNumber(string $orderNumber): OrderInterface { /** @var OrderInterface|null $order */ diff --git a/tests/Behat/Context/Transform/PriceContext.php b/tests/Behat/Context/Transform/PriceContext.php index 075588f4b..3e3d72054 100644 --- a/tests/Behat/Context/Transform/PriceContext.php +++ b/tests/Behat/Context/Transform/PriceContext.php @@ -5,12 +5,11 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Transform; use Behat\Behat\Context\Context; +use Behat\Transformation\Transform; final class PriceContext implements Context { - /** - * @Transform /^"(\-)?(\d+(?:\.\d{1,2})?)"$/ - */ + #[Transform('/^"(\-)?(\d+(?:\.\d{1,2})?)"$/')] public function getPriceFromString(string $sign, string $price): int { $price = (int) round((float) $price * 100, 2); diff --git a/tests/Behat/Context/Ui/CreditMemoContext.php b/tests/Behat/Context/Ui/CreditMemoContext.php index a92833301..a8f5f3812 100644 --- a/tests/Behat/Context/Ui/CreditMemoContext.php +++ b/tests/Behat/Context/Ui/CreditMemoContext.php @@ -5,15 +5,17 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Ui; use Behat\Behat\Context\Context; +use Behat\Step\Then; +use Behat\Step\When; use Doctrine\Persistence\ObjectRepository; use Sylius\Behat\Page\Admin\Order\ShowPageInterface; use Sylius\Component\Addressing\Model\CountryInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\RefundPlugin\Entity\CreditMemoInterface; use Sylius\RefundPlugin\Provider\CurrentDateTimeImmutableProviderInterface; +use Tests\Sylius\RefundPlugin\Behat\Element\PdfDownloadElementInterface; use Tests\Sylius\RefundPlugin\Behat\Page\Admin\CreditMemoDetailsPageInterface; use Tests\Sylius\RefundPlugin\Behat\Page\Admin\CreditMemoIndexPageInterface; -use Tests\Sylius\RefundPlugin\Behat\Element\PdfDownloadElementInterface; use Webmozart\Assert\Assert; final class CreditMemoContext implements Context @@ -29,76 +31,58 @@ public function __construct( ) { } - /** - * @When I browse the details of the only credit memo generated for order :order - */ + #[When('I browse the details of the only credit memo generated for order :order')] public function browseTheDetailsOfTheOnlyCreditMemoGeneratedForOrder(OrderInterface $order): void { $creditMemo = $this->creditMemoRepository->findBy(['order' => $order])[0]; $this->creditMemoDetailsPage->open(['orderNumber' => $order->getNumber(), 'id' => $creditMemo->getId()]); } - /** - * @When I browse credit memos - */ + #[When('I browse credit memos')] public function browseCreditMemos(): void { $this->creditMemoIndexPage->open(); } - /** - * @When /^I download (\d+)(?:|st|nd|rd) credit memo$/ - */ + #[When('/^I download (\d+)(?:|st|nd|rd) credit memo$/')] public function downloadCreditMemoFromIndex(int $index): void { $this->creditMemoIndexPage->downloadCreditMemo($index); } - /** - * @When I filter credit memos by :channelName channel - */ + #[When('I filter credit memos by :channelName channel')] public function filterCreditMemosByChannel(string $channelName): void { $this->creditMemoIndexPage->filterByChannel($channelName); $this->creditMemoIndexPage->filter(); } - /** - * @When /^I download (\d+)(?:|st|nd|rd) order's credit memo$/ - */ + #[When('/^I download (\d+)(?:|st|nd|rd) order\'s credit memo$/')] public function downloadCreditMemoFromOrderShow(int $index): void { $this->orderShowPage->downloadCreditMemo($index); } - /** - * @When I download it - */ + #[When('I download it')] public function downloadCreditMemo(): void { $this->creditMemoDetailsPage->download(); } - /** - * @When I resend credit memo from order :orderNumber - */ + #[When('I resend credit memo from order :orderNumber')] public function resendCreditMemoToCustomer(string $orderNumber): void { $this->creditMemoIndexPage->resendCreditMemo($orderNumber); } - /** - * @Then I should have :count credit memo generated for order :order - */ + #[Then('I should have :count credit memo generated for order :order')] public function shouldHaveCountCreditMemoGeneratedForOrder(int $count, OrderInterface $order): void { $this->orderShowPage->open(['id' => $order->getId()]); Assert::same($this->orderShowPage->countCreditMemos(), $count); } - /** - * @Then it should contain :quantity :productName product(s) with :netValue net value, :taxAmount tax amount and :grossValue gross value in :currencyCode currency - */ + #[Then('it should contain :quantity :productName product(s) with :netValue net value, :taxAmount tax amount and :grossValue gross value in :currencyCode currency')] public function itShouldContainProductWithNetValueTaxAmountAndGrossValueInCurrency( int $quantity, string $productName, @@ -112,9 +96,7 @@ public function itShouldContainProductWithNetValueTaxAmountAndGrossValueInCurren ); } - /** - * @Then it should contain :quantity :shipmentName shipment(s) with :netValue net value, :taxAmount tax amount and :grossValue gross value in :currencyCode currency - */ + #[Then('it should contain :quantity :shipmentName shipment(s) with :netValue net value, :taxAmount tax amount and :grossValue gross value in :currencyCode currency')] public function itShouldContainShipmentWithNetValueTaxAmountAndGrossValueInCurrency( int $quantity, string $shipmentName, @@ -128,17 +110,13 @@ public function itShouldContainShipmentWithNetValueTaxAmountAndGrossValueInCurre ); } - /** - * @Then it should contain a tax item :label with amount :amount in :currencyCode currency - */ + #[Then('it should contain a tax item :label with amount :amount in :currencyCode currency')] public function itShouldContainATaxItemWithAmountInCurrency(string $label, string $amount, string $currencyCode): void { Assert::true($this->creditMemoDetailsPage->hasTaxItem($label, $amount, $currencyCode)); } - /** - * @Then it should have sequential number generated from current date - */ + #[Then('it should have sequential number generated from current date')] public function shouldHaveSequentialNumberGeneratedFromCurrentDate(): void { Assert::contains( @@ -147,17 +125,13 @@ public function shouldHaveSequentialNumberGeneratedFromCurrentDate(): void ); } - /** - * @Then it should be issued in :channelName channel - */ + #[Then('it should be issued in :channelName channel')] public function creditMemoShouldBeIssuedInChannel(string $channelName): void { Assert::same($this->creditMemoDetailsPage->getChannelName(), $channelName); } - /** - * @Then it should be issued from :customerName, :street, :postcode :city in the :country - */ + #[Then('it should be issued from :customerName, :street, :postcode :city in the :country')] public function itShouldBeIssuedFrom( string $customerName, string $street, @@ -171,9 +145,7 @@ public function itShouldBeIssuedFrom( ); } - /** - * @Then it should be issued to :company, :street, :postcode :city in the :country with :taxId tax ID - */ + #[Then('it should be issued to :company, :street, :postcode :city in the :country with :taxId tax ID')] public function itShouldBeIssuedTo( string $company, string $street, @@ -188,50 +160,38 @@ public function itShouldBeIssuedTo( ); } - /** - * @Then its total should be :total in :currencyCode currency - */ + #[Then('its total should be :total in :currencyCode currency')] public function itsTotalShouldBeInCurrency(string $total, string $currencyCode): void { Assert::same($this->creditMemoDetailsPage->getTotal(), $total); Assert::same($this->creditMemoDetailsPage->getTotalCurrencyCode(), $currencyCode); } - /** - * @Then its net total should be :total - */ + #[Then('its net total should be :total')] public function itsNetTotalShouldBe(string $total): void { Assert::same($this->creditMemoDetailsPage->getNetTotal(), $total); } - /** - * @Then its tax total should be :total - */ + #[Then('its tax total should be :total')] public function itsTaxTotalShouldBe(string $total): void { Assert::same($this->creditMemoDetailsPage->getTaxTotal(), $total); } - /** - * @Then it should be commented with :comment - */ + #[Then('it should be commented with :comment')] public function itShouldBeCommentedWith(string $comment): void { Assert::same($this->creditMemoDetailsPage->getComment(), $comment); } - /** - * @Then there should be :count credit memo(s) generated - */ + #[Then('there should be :count credit memo(s) generated')] public function thereShouldBeCreditMemosGenerated(int $count): void { Assert::same($this->creditMemoIndexPage->countItems(), $count); } - /** - * @Then /^(\d+)(?:st|nd|rd) credit memo should be generated for the (order "[^"]+"), have total "([^"]+)" and date of being issued$/ - */ + #[Then('/^(\d+)(?:st|nd|rd) credit memo should be generated for the (order "[^"]+"), have total "([^"]+)" and date of being issued$/')] public function creditMemoShouldBeGeneratedForOrderHasTotalAndDateOfBeingIssued( int $index, OrderInterface $order, @@ -257,82 +217,62 @@ public function creditMemoShouldBeGeneratedForOrderHasTotalAndDateOfBeingIssued( ); } - /** - * @Then /^the only credit memo should be generated for order "#([^"]+)"$/ - */ + #[Then('/^the only credit memo should be generated for order "#([^"]+)"$/')] public function theOnlyCreditMemoShouldBeGeneratedForOrder(string $orderNumber): void { Assert::true($this->creditMemoIndexPage->hasSingleCreditMemoForOrder($orderNumber)); } - /** - * @Then /^(\d+)(?:st|nd|rd) credit memo should be issued in "([^"]+)" channel$/ - */ + #[Then('/^(\d+)(?:st|nd|rd) credit memo should be issued in "([^"]+)" channel$/')] public function specificCreditMemoShouldBeIssuedInChannel(int $index, string $channelName): void { Assert::true($this->creditMemoIndexPage->hasCreditMemoWithChannel($index, $channelName)); } - /** - * @Then a pdf file should be successfully downloaded - */ + #[Then('a pdf file should be successfully downloaded')] public function pdfFileShouldBeSuccessfullyDownloaded(): void { Assert::true($this->pdfDownloadElement->isPdfFileDownloaded()); } - /** - * @Then /^I should see the credit memo with "([^"]+)" total as (\d+)(?:|st|nd|rd|th) in the list$/ - */ + #[Then('/^I should see the credit memo with "([^"]+)" total as (\d+)(?:|st|nd|rd|th) in the list$/')] public function iShouldCreditMemoOrderByAscInTheList(string $creditMemoTotal, int $position): void { Assert::true($this->creditMemoDetailsPage->isCreditMemoInPosition($creditMemoTotal, $position)); } - /** - * @Then the first credit memo should have order number :number - */ + #[Then('the first credit memo should have order number :number')] public function theFirstCreditMemoShouldHaveOrderNumber(string $orderNumber): void { Assert::eq($this->creditMemoIndexPage->getColumnFields('order')[0], $orderNumber); } - /** - * @When I sort credit memos by order number in ascending order - */ + #[When('I sort credit memos by order number in ascending order')] public function iSortCreditMemosByOrderNumberInAscOrder(): void { $this->creditMemoIndexPage->sortBy('order'); } - /** - * @When I sort credit memos by order number in descending order - */ + #[When('I sort credit memos by order number in descending order')] public function iSortCreditMemosByOrderNumberInDescOrder(): void { $this->creditMemoIndexPage->sortBy('order'); $this->creditMemoIndexPage->sortBy('order'); } - /** - * @Then /^I should not be able to download the (\d+)(?:|st|nd|rd) credit memo$/ - */ + #[Then('/^I should not be able to download the (\d+)(?:|st|nd|rd) credit memo$/')] public function iShouldNotBeAbleToDownloadTheNthCreditMemo(int $index): void { Assert::false($this->creditMemoIndexPage->hasDownloadButton($index)); } - /** - * @Then I should not be able to download the credit memo - */ + #[Then('I should not be able to download the credit memo')] public function iShouldNotBeAbleToDownloadTheCreditMemo(): void { Assert::false($this->creditMemoDetailsPage->hasDownloadButton()); } - /** - * @Then /^I should not be able to download the (\d+)(?:|st|nd|rd) order's credit memo$/ - */ + #[Then('/^I should not be able to download the (\d+)(?:|st|nd|rd) order\'s credit memo$/')] public function iShouldNotBeAbleToDownloadTheNthOrdersCreditMemo(int $index): void { Assert::false($this->orderShowPage->hasDownloadCreditMemoButton($index)); diff --git a/tests/Behat/Context/Ui/ManagingOrdersContext.php b/tests/Behat/Context/Ui/ManagingOrdersContext.php index a5033c882..b216948e6 100644 --- a/tests/Behat/Context/Ui/ManagingOrdersContext.php +++ b/tests/Behat/Context/Ui/ManagingOrdersContext.php @@ -6,6 +6,7 @@ use Behat\Behat\Context\Context; use Behat\Step\Then; +use Behat\Step\When; use Sylius\Behat\NotificationType; use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; use Sylius\Behat\Service\NotificationCheckerInterface; @@ -22,9 +23,7 @@ public function __construct( ) { } - /** - * @Then I should be notified that the order should be paid - */ + #[Then('I should be notified that the order should be paid')] public function shouldBeNotifiedThatTheOrderShouldBePaid(): void { $this->notificationChecker->checkNotification( @@ -33,9 +32,7 @@ public function shouldBeNotifiedThatTheOrderShouldBePaid(): void ); } - /** - * @Then I should not see refunds button - */ + #[Then('I should not see refunds button')] public function iShouldNotSeeRefundsButton(): void { Assert::false($this->showPage->hasRefundsButton()); @@ -47,41 +44,31 @@ public function iShouldSeeDisabledRefundsButton(): void Assert::true($this->showPage->hasDisabledRefundsButton()); } - /** - * @Then I should see :count refund payment(s) with status :status - */ + #[Then('I should see :count refund payment(s) with status :status')] public function shouldSeeRefundPaymentWithStatus(int $count, string $status): void { Assert::true($this->showPage->hasRefundPaymentsWithStatus($count, $status)); } - /** - * @Then I should not see any refund payments - */ + #[Then('I should not see any refund payments')] public function shouldNotSeeAnyRefundPayments(): void { Assert::same($this->showPage->countRefundPayments(), 0); } - /** - * @Then I should not see any credit memos - */ + #[Then('I should not see any credit memos')] public function shouldNotSeeAnyCreditMemos(): void { Assert::same($this->showPage->countCreditMemos(), 0); } - /** - * @When I complete the first refund payment - */ + #[When('I complete the first refund payment')] public function completeTheFirstRefundPayment(): void { $this->showPage->completeRefundPayment(0); } - /** - * @Then I should be notified that refund payment has been successfully completed - */ + #[Then('I should be notified that refund payment has been successfully completed')] public function shouldBeNotifiedThatRefundPaymentHasBeenSuccessfullyCompleted(): void { $this->notificationChecker->checkNotification( @@ -90,17 +77,13 @@ public function shouldBeNotifiedThatRefundPaymentHasBeenSuccessfullyCompleted(): ); } - /** - * @Then I should not be able to complete the first refund payment again - */ + #[Then('I should not be able to complete the first refund payment again')] public function shouldNotBeAbleToCompleteTheFirstRefundPaymentAgain(): void { Assert::false($this->showPage->canCompleteRefundPayment(0)); } - /** - * @Then /^(this order)'s payment state should be "([^"]+)"$/ - */ + #[Then('/^(this order)\'s payment state should be "([^"]+)"$/')] public function thisOrderSPaymentStateShouldBe(OrderInterface $order, string $orderPaymentState): void { $this->indexPage->open(); @@ -110,17 +93,13 @@ public function thisOrderSPaymentStateShouldBe(OrderInterface $order, string $or ])); } - /** - * @Then I should be redirected to the order :order show page - */ + #[Then('I should be redirected to the order :order show page')] public function iShouldBeRedirectedToTheOrderShowPage(OrderInterface $order): void { Assert::true($this->showPage->isOpen(['id' => $order->getId()])); } - /** - * @Then I should be notified that I cannot refund an order - */ + #[Then('I should be notified that I cannot refund an order')] public function iShouldBeNotifiedThatICannotRefundAnOrder(): void { $this->notificationChecker->checkNotification( diff --git a/tests/Behat/Context/Ui/RefundingContext.php b/tests/Behat/Context/Ui/RefundingContext.php index 35db4d691..4d55c3acd 100644 --- a/tests/Behat/Context/Ui/RefundingContext.php +++ b/tests/Behat/Context/Ui/RefundingContext.php @@ -5,10 +5,13 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Ui; use Behat\Behat\Context\Context; +use Behat\Step\Given; +use Behat\Step\Then; +use Behat\Step\When; use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException; use Sylius\Behat\NotificationType; -use Sylius\Behat\Service\NotificationCheckerInterface; use Sylius\Behat\Service\Checker\EmailCheckerInterface as BehatEmailCheckerInterface; +use Sylius\Behat\Service\NotificationCheckerInterface; use Symfony\Component\Finder\Exception\DirectoryNotFoundException; use Tests\Sylius\RefundPlugin\Behat\Page\Admin\OrderRefundsPageInterface; use Webmozart\Assert\Assert; @@ -22,17 +25,13 @@ public function __construct( ) { } - /** - * @When I want to refund some units of order :orderNumber - */ + #[When('I want to refund some units of order :orderNumber')] public function wantToRefundSomeUnitsOfOrder(string $orderNumber): void { $this->orderRefundsPage->open(['orderNumber' => $orderNumber]); } - /** - * @When I try to refund some units of order :orderNumber - */ + #[When('I try to refund some units of order :orderNumber')] public function tryToRefundSomeUnitsOfOrder(string $orderNumber): void { try { @@ -41,10 +40,8 @@ public function tryToRefundSomeUnitsOfOrder(string $orderNumber): void } } - /** - * @When /^I decide to refund (\d)st "([^"]+)" product with "([^"]+)" payment$/ - * @When /^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment) and "([^"]+)" comment$/ - */ + #[When('/^I decide to refund (\d)st "([^"]+)" product with "([^"]+)" payment$/')] + #[When('/^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment) and "([^"]+)" comment$/')] public function decideToRefundProduct( int $unitNumber, string $productName, @@ -57,9 +54,7 @@ public function decideToRefundProduct( $this->orderRefundsPage->refund(); } - /** - * @When /^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment) and a very long comment$/ - */ + #[When('/^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment) and a very long comment$/')] public function decideToRefundProductWithVeryLongComment( int $unitNumber, string $productName, @@ -71,9 +66,7 @@ public function decideToRefundProductWithVeryLongComment( $this->orderRefundsPage->refund(); } - /** - * @When /^I decide to refund (\d+) "([^"]*)" products with "([^"]*)" payment$/ - */ + #[When('/^I decide to refund (\d+) "([^"]*)" products with "([^"]*)" payment$/')] public function iDecideToRefundProductsWithPayment(int $amount, string $productName, string $paymentMethodName): void { for ($number = 0; $number < $amount; $number++) { @@ -83,9 +76,7 @@ public function iDecideToRefundProductsWithPayment(int $amount, string $productN $this->orderRefundsPage->refund(); } - /** - * @When /^I decide to refund (\d)st "([^"]+)" and (\d)st "([^"]+)" products with "([^"]+)" payment$/ - */ + #[When('/^I decide to refund (\d)st "([^"]+)" and (\d)st "([^"]+)" products with "([^"]+)" payment$/')] public function decideToRefundMultipleProduct( int $firstUnitNumber, string $firstProductName, @@ -101,9 +92,7 @@ public function decideToRefundMultipleProduct( $this->orderRefundsPage->refund(); } - /** - * @Given /^I decide to refund ("[^"]+") from (\d)st "([^"]+)" product with "([^"]+)" payment$/ - */ + #[Given('/^I decide to refund ("[^"]+") from (\d)st "([^"]+)" product with "([^"]+)" payment$/')] public function decideToRefundPartFromProductWithPayment( string $partialPrice, int $unitNumber, @@ -120,9 +109,7 @@ public function decideToRefundPartFromProductWithPayment( $this->orderRefundsPage->refund(); } - /** - * @When /^I decided to refund (\d)st "([^"]+)" product of the order "([^"]+)" with "([^"]+)" payment$/ - */ + #[When('/^I decided to refund (\d)st "([^"]+)" product of the order "([^"]+)" with "([^"]+)" payment$/')] public function decidedToRefundProduct( int $unitNumber, string $productName, @@ -135,9 +122,7 @@ public function decidedToRefundProduct( $this->orderRefundsPage->refund(); } - /** - * @When I decide to refund all units of this order with :paymentMethod payment - */ + #[When('I decide to refund all units of this order with :paymentMethod payment')] public function decideToRefundAllUnits(string $paymentMethod): void { $this->orderRefundsPage->pickAllUnitsToRefund(); @@ -145,9 +130,7 @@ public function decideToRefundAllUnits(string $paymentMethod): void $this->orderRefundsPage->refund(); } - /** - * @When /^I decide to refund order shipment with "([^"]+)" payment$/ - */ + #[When('/^I decide to refund order shipment with "([^"]+)" payment$/')] public function decideToRefundOrderShipment(string $paymentMethod): void { $this->orderRefundsPage->pickOrderShipment(); @@ -155,9 +138,7 @@ public function decideToRefundOrderShipment(string $paymentMethod): void $this->orderRefundsPage->refund(); } - /** - * @When I decide to refund :shippingMethodName order shipment with :paymentMethodName payment - */ + #[When('I decide to refund :shippingMethodName order shipment with :paymentMethodName payment')] public function iDecideToRefundOrderShipmentWithPayment( string $shippingMethodName, string $paymentMethodName @@ -167,10 +148,8 @@ public function iDecideToRefundOrderShipmentWithPayment( $this->orderRefundsPage->refund(); } - /** - * @When /^I decide to refund "\$([^"]+)" from order shipment with "([^"]+)" payment$/ - * @When /^I try to refund ("[^"]+") from order shipment with "([^"]+)" payment$/ - */ + #[When('/^I decide to refund "\$([^"]+)" from order shipment with "([^"]+)" payment$/')] + #[When('/^I try to refund ("[^"]+") from order shipment with "([^"]+)" payment$/')] public function decideToRefundPartOfOrderShipment(string $amount, string $paymentMethod): void { $this->orderRefundsPage->pickPartOfOrderShipmentToRefund($amount); @@ -178,9 +157,7 @@ public function decideToRefundPartOfOrderShipment(string $amount, string $paymen $this->orderRefundsPage->refund(); } - /** - * @When /^I decide to refund order shipment and (\d)st "([^"]+)" product with "([^"]+)" payment$/ - */ + #[When('/^I decide to refund order shipment and (\d)st "([^"]+)" product with "([^"]+)" payment$/')] public function decideToRefundProductAndShipment(int $unitNumber, string $productName, string $paymentMethod): void { $this->orderRefundsPage->pickUnitWithProductToRefund($productName, $unitNumber-1); @@ -189,33 +166,25 @@ public function decideToRefundProductAndShipment(int $unitNumber, string $produc $this->orderRefundsPage->refund(); } - /** - * @When I refund zero items - */ + #[When('I refund zero items')] public function refundZeroItems(): void { $this->orderRefundsPage->refund(); } - /** - * @Then I should be able to refund :count :productName products - */ + #[Then('I should be able to refund :count :productName products')] public function shouldBeAbleToRefundProducts(int $count, string $productName): void { Assert::same($count, $this->orderRefundsPage->countRefundableUnitsWithProduct($productName)); } - /** - * @Then I should be able to go back to order details - */ + #[Then('I should be able to go back to order details')] public function shouldBeAbleToGoBackToOrderDetails(): void { Assert::true($this->orderRefundsPage->hasBackButton()); } - /** - * @Then I should be notified that selected order units have been successfully refunded - */ + #[Then('I should be notified that selected order units have been successfully refunded')] public function shouldBeNotifiedThatSelectedOrderUnitsHaveBeenSuccessfullyRefunded(): void { $this->notificationChecker->checkNotification( @@ -224,9 +193,7 @@ public function shouldBeNotifiedThatSelectedOrderUnitsHaveBeenSuccessfullyRefund ); } - /** - * @Then I should be notified that refunded amount should be greater than 0 - */ + #[Then('I should be notified that refunded amount should be greater than 0')] public function shouldBeNotifiedThatRefundedAmountShouldBeGreaterThan(): void { $this->notificationChecker->checkNotification( @@ -235,10 +202,8 @@ public function shouldBeNotifiedThatRefundedAmountShouldBeGreaterThan(): void ); } - /** - * @Then I should be notified that I cannot refund more money than the order unit total - * @Then I should be notified that I cannot refund more money than the shipment total - */ + #[Then('I should be notified that I cannot refund more money than the order unit total')] + #[Then('I should be notified that I cannot refund more money than the shipment total')] public function shouldBeNotifiedThatICannotRefundMoreMoneyThanTheRefundedUnitTotal(): void { $this->notificationChecker->checkNotification( @@ -247,9 +212,7 @@ public function shouldBeNotifiedThatICannotRefundMoreMoneyThanTheRefundedUnitTot ); } - /** - * @Then I should be notified that at least one unit should be selected to refund - */ + #[Then('I should be notified that at least one unit should be selected to refund')] public function shouldBeNotifiedThatAtLeastOneUnitShouldBeSelectedToRefund(): void { $this->notificationChecker->checkNotification( @@ -258,98 +221,74 @@ public function shouldBeNotifiedThatAtLeastOneUnitShouldBeSelectedToRefund(): vo ); } - /** - * @Then this order refunded total should (still) be :refundedTotal - */ + #[Then('this order refunded total should (still) be :refundedTotal')] public function refundedTotalShouldBe(string $refundedTotal): void { Assert::same($this->orderRefundsPage->getRefundedTotal(), $refundedTotal); } - /** - * @Then /^(\d+)st "([^"]+)" product should have "([^"]+)" refunded$/ - */ + #[Then('/^(\d+)st "([^"]+)" product should have "([^"]+)" refunded$/')] public function productShouldHaveSomeAmountRefunded(int $unitNumber, string $productName, string $amount): void { Assert::same($this->orderRefundsPage->getUnitWithProductRefundedTotal($unitNumber-1, $productName), $amount); } - /** - * @Then /^I should not be able to refund (\d)(?:|st|nd|rd) unit with product "([^"]+)"$/ - */ + #[Then('/^I should not be able to refund (\d)(?:|st|nd|rd) unit with product "([^"]+)"$/')] public function shouldNotBeAbleToRefundUnitWithProduct(int $unitNumber, string $productName): void { Assert::false($this->orderRefundsPage->isUnitWithProductAvailableToRefund($productName, $unitNumber-1)); } - /** - * @Then I should still be able to refund order shipment with :paymentMethodName payment - */ + #[Then('I should still be able to refund order shipment with :paymentMethodName payment')] public function shouldStillBeAbleToRefundOrderShipment(): void { Assert::true($this->orderRefundsPage->isOrderShipmentAvailableToRefund()); } - /** - * @Then I should not be able to refund anything - */ + #[Then('I should not be able to refund anything')] public function iShouldNotBeAbleToRefundAnything(): void { Assert::true($this->orderRefundsPage->eachRefundButtonIsDisabled()); } - /** - * @Then I should not be able to refund order shipment - */ + #[Then('I should not be able to refund order shipment')] public function shouldNotBeAbleToRefundOrderShipment(): void { Assert::false($this->orderRefundsPage->isOrderShipmentAvailableToRefund()); } - /** - * @Then /^I should(?:| still) be able to refund (\d)(?:|st|nd|rd) unit with product "([^"]+)" with ("[^"]+" payment)$/ - */ + #[Then('/^I should(?:| still) be able to refund (\d)(?:|st|nd|rd) unit with product "([^"]+)" with ("[^"]+" payment)$/')] public function shouldBeAbleToRefundUnitWithProduct(int $unitNumber, string $productName): void { Assert::true($this->orderRefundsPage->isUnitWithProductAvailableToRefund($productName, $unitNumber-1)); } - /** - * @Then I should be able to choose refund payment method - */ + #[Then('I should be able to choose refund payment method')] public function shouldBeAbleToChooseRefundPaymentMethod(): void { Assert::true($this->orderRefundsPage->canChoosePaymentMethod()); } - /** - * @Then there should be :payment payment method - */ + #[Then('there should be :payment payment method')] public function thereShouldBePaymentMethod(string $payment): void { Assert::true($this->orderRefundsPage->isPaymentMethodVisible($payment)); } - /** - * @Then there should not be :payment payment method - */ + #[Then('there should not be :payment payment method')] public function thereShouldNotBePaymentMethod(string $payment): void { Assert::false($this->orderRefundsPage->isPaymentMethodVisible($payment)); } - /** - * @Then the selected refund payment method should be :paymentMethod - */ + #[Then('the selected refund payment method should be :paymentMethod')] public function theSelectedRefundPaymentMethodShouldBe(string $paymentMethod): void { Assert::true($this->orderRefundsPage->isPaymentMethodSelected($paymentMethod)); } - /** - * @Then email to :email with credit memo should not be sent - * @Then the customer :email should not receive an email that some units have been refunded - */ + #[Then('email to :email with credit memo should not be sent')] + #[Then('the customer :email should not receive an email that some units have been refunded')] public function emailToWithCreditMemoShouldNotBeSent(string $email): void { try { @@ -358,9 +297,7 @@ public function emailToWithCreditMemoShouldNotBeSent(string $email): void } } - /** - * @Then I should see original payment method :paymentMethodName - */ + #[Then('I should see original payment method :paymentMethodName')] public function iShouldSeeOriginalPaymentMethod(string $paymentMethodName): void { Assert::same($this->orderRefundsPage->getOriginalPaymentMethodName(), sprintf('Original Payment Method: %s', $paymentMethodName)); diff --git a/tests/Behat/Context/Ui/Shop/Customer/CreditMemoContext.php b/tests/Behat/Context/Ui/Shop/Customer/CreditMemoContext.php index a87c02b33..1e26577f1 100644 --- a/tests/Behat/Context/Ui/Shop/Customer/CreditMemoContext.php +++ b/tests/Behat/Context/Ui/Shop/Customer/CreditMemoContext.php @@ -5,6 +5,8 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Ui\Shop\Customer; use Behat\Behat\Context\Context; +use Behat\Step\Then; +use Behat\Step\When; use Sylius\Behat\Page\Shop\Order\ShowPageInterface; use Tests\Sylius\RefundPlugin\Behat\Element\PdfDownloadElementInterface; use Webmozart\Assert\Assert; @@ -17,33 +19,25 @@ public function __construct( ) { } - /** - * @Then there should be :count credit memo(s) related to this order - */ + #[Then('there should be :count credit memo(s) related to this order')] public function thereShouldBeCountCreditMemoRelatedToThisOrder(int $count): void { Assert::same($this->customerOrderShowPage->countCreditMemos(), $count); } - /** - * @Then a pdf file should be successfully downloaded - */ + #[Then('a pdf file should be successfully downloaded')] public function pdfFileShouldBeSuccessfullyDownloaded(): void { Assert::true($this->pdfDownloadElement->isPdfFileDownloaded()); } - /** - * @When I download the first credit memo - */ + #[When('I download the first credit memo')] public function downloadFirstCreditMemo(): void { $this->customerOrderShowPage->downloadCreditMemo(0); } - /** - * @When I should not be able to download the first credit memo - */ + #[When('I should not be able to download the first credit memo')] public function iShouldNotBeAbleToDownloadTheFirstCreditMemo(): void { $this->customerOrderShowPage->hasDownloadCreditMemoButton(0); diff --git a/tests/Behat/Resources/suites.php b/tests/Behat/Resources/suites.php new file mode 100644 index 000000000..2555c0783 --- /dev/null +++ b/tests/Behat/Resources/suites.php @@ -0,0 +1,13 @@ +import([ + 'suites/application/refunds.php', + 'suites/ui/customer_credit_memos.php', + 'suites/ui/refunds.php', + ]) +; diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml deleted file mode 100644 index d8148bbcd..000000000 --- a/tests/Behat/Resources/suites.yml +++ /dev/null @@ -1,4 +0,0 @@ -imports: - - suites/application/refunds.yaml - - suites/ui/customer_credit_memos.yaml - - suites/ui/refunds.yaml diff --git a/tests/Behat/Resources/suites/application/refunds.php b/tests/Behat/Resources/suites/application/refunds.php new file mode 100644 index 000000000..a7a54a8e1 --- /dev/null +++ b/tests/Behat/Resources/suites/application/refunds.php @@ -0,0 +1,64 @@ +withProfile( + (new Profile('default')) + ->withSuite( + (new Suite('application_refunds')) + ->withContexts( + 'sylius.behat.context.hook.doctrine_orm', + CreditMemosContext::class, + ) + ->withContexts( + 'sylius.behat.context.transform.address', + 'sylius.behat.context.transform.channel', + 'sylius.behat.context.transform.country', + 'sylius.behat.context.transform.customer', + 'sylius.behat.context.transform.lexical', + 'sylius.behat.context.transform.order', + 'sylius.behat.context.transform.payment', + 'sylius.behat.context.transform.product', + 'sylius.behat.context.transform.promotion', + 'sylius.behat.context.transform.shared_storage', + 'sylius.behat.context.transform.shipping_method', + 'sylius.behat.context.transform.tax_category', + 'sylius.behat.context.transform.tax_rate', + 'sylius.behat.context.transform.zone', + PriceContext::class, + ) + ->withContexts( + 'sylius.behat.context.setup.admin_security', + 'sylius.behat.context.setup.channel', + 'sylius.behat.context.setup.order', + 'sylius.behat.context.setup.payment', + 'sylius.behat.context.setup.product', + 'sylius.behat.context.setup.promotion', + 'sylius.behat.context.setup.shipping', + 'sylius.behat.context.setup.taxation', + 'sylius.behat.context.setup.zone', + ChannelContext::class, + SetupRefundingContext::class, + ) + ->withContexts( + ApplicationCreditMemoContext::class, + EmailsContext::class, + ApplicationRefundingContext::class, + ) + ->withFilter(new TagFilter('@refunds&&@application')), + ), + ) +; diff --git a/tests/Behat/Resources/suites/application/refunds.yaml b/tests/Behat/Resources/suites/application/refunds.yaml deleted file mode 100644 index 8c9917e96..000000000 --- a/tests/Behat/Resources/suites/application/refunds.yaml +++ /dev/null @@ -1,41 +0,0 @@ -default: - suites: - application_refunds: - contexts: - - sylius.behat.context.hook.doctrine_orm - - Tests\Sylius\RefundPlugin\Behat\Context\Hook\CreditMemosContext - - - sylius.behat.context.transform.address - - sylius.behat.context.transform.channel - - sylius.behat.context.transform.country - - sylius.behat.context.transform.customer - - sylius.behat.context.transform.lexical - - sylius.behat.context.transform.order - - sylius.behat.context.transform.payment - - sylius.behat.context.transform.product - - sylius.behat.context.transform.promotion - - sylius.behat.context.transform.shared_storage - - sylius.behat.context.transform.shipping_method - - sylius.behat.context.transform.tax_category - - sylius.behat.context.transform.tax_rate - - sylius.behat.context.transform.zone - - Tests\Sylius\RefundPlugin\Behat\Context\Transform\PriceContext - - - sylius.behat.context.setup.admin_security - - sylius.behat.context.setup.channel - - sylius.behat.context.setup.order - - sylius.behat.context.setup.payment - - sylius.behat.context.setup.product - - sylius.behat.context.setup.promotion - - sylius.behat.context.setup.shipping - - sylius.behat.context.setup.taxation - - sylius.behat.context.setup.zone - - Tests\Sylius\RefundPlugin\Behat\Context\Setup\ChannelContext - - Tests\Sylius\RefundPlugin\Behat\Context\Setup\RefundingContext - - - Tests\Sylius\RefundPlugin\Behat\Context\Application\CreditMemoContext - - Tests\Sylius\RefundPlugin\Behat\Context\Application\EmailsContext - - Tests\Sylius\RefundPlugin\Behat\Context\Application\RefundingContext - - filters: - tags: "@refunds&&@application" diff --git a/tests/Behat/Resources/suites/ui/customer_credit_memos.php b/tests/Behat/Resources/suites/ui/customer_credit_memos.php new file mode 100644 index 000000000..e4b8eaa8b --- /dev/null +++ b/tests/Behat/Resources/suites/ui/customer_credit_memos.php @@ -0,0 +1,60 @@ +withProfile( + (new Profile('default')) + ->withSuite( + (new Suite('customer_credit_memos')) + ->withContexts( + 'sylius.behat.context.hook.doctrine_orm', + CreditMemosContext::class, + ) + ->withContexts( + 'sylius.behat.context.transform.address', + 'sylius.behat.context.transform.customer', + 'sylius.behat.context.transform.order', + 'sylius.behat.context.transform.payment', + 'sylius.behat.context.transform.product', + 'sylius.behat.context.transform.product_variant', + 'sylius.behat.context.transform.promotion', + 'sylius.behat.context.transform.shared_storage', + 'sylius.behat.context.transform.shipping_method', + 'sylius.behat.context.transform.tax_category', + 'sylius.behat.context.transform.tax_rate', + 'sylius.behat.context.transform.user', + ) + ->withContexts( + 'sylius.behat.context.setup.channel', + 'sylius.behat.context.setup.order', + 'sylius.behat.context.setup.payment', + 'sylius.behat.context.setup.product', + 'sylius.behat.context.setup.promotion', + 'sylius.behat.context.setup.shipping', + 'sylius.behat.context.setup.shop_security', + 'sylius.behat.context.setup.user', + ChannelContext::class, + SetupRefundingContext::class, + ) + ->withContexts( + 'sylius.behat.context.ui.shop.account', + ) + ->withContexts( + EmailsContext::class, + ShopCustomerCreditMemoContext::class, + ) + ->withFilter(new TagFilter('@customer_credit_memos&&@ui')), + ), + ) +; diff --git a/tests/Behat/Resources/suites/ui/customer_credit_memos.yaml b/tests/Behat/Resources/suites/ui/customer_credit_memos.yaml deleted file mode 100644 index 42259e4e0..000000000 --- a/tests/Behat/Resources/suites/ui/customer_credit_memos.yaml +++ /dev/null @@ -1,38 +0,0 @@ -default: - suites: - customer_credit_memos: - contexts: - - sylius.behat.context.hook.doctrine_orm - - Tests\Sylius\RefundPlugin\Behat\Context\Hook\CreditMemosContext - - - sylius.behat.context.transform.address - - sylius.behat.context.transform.customer - - sylius.behat.context.transform.order - - sylius.behat.context.transform.payment - - sylius.behat.context.transform.product - - sylius.behat.context.transform.product_variant - - sylius.behat.context.transform.promotion - - sylius.behat.context.transform.shared_storage - - sylius.behat.context.transform.shipping_method - - sylius.behat.context.transform.tax_category - - sylius.behat.context.transform.tax_rate - - sylius.behat.context.transform.user - - - sylius.behat.context.setup.channel - - sylius.behat.context.setup.order - - sylius.behat.context.setup.payment - - sylius.behat.context.setup.product - - sylius.behat.context.setup.promotion - - sylius.behat.context.setup.shipping - - sylius.behat.context.setup.shop_security - - sylius.behat.context.setup.user - - Tests\Sylius\RefundPlugin\Behat\Context\Setup\ChannelContext - - Tests\Sylius\RefundPlugin\Behat\Context\Setup\RefundingContext - - - sylius.behat.context.ui.shop.account - - - Tests\Sylius\RefundPlugin\Behat\Context\Application\EmailsContext - - Tests\Sylius\RefundPlugin\Behat\Context\Ui\Shop\Customer\CreditMemoContext - - filters: - tags: "@customer_credit_memos&&@ui" diff --git a/tests/Behat/Resources/suites/ui/refunds.php b/tests/Behat/Resources/suites/ui/refunds.php new file mode 100644 index 000000000..d3b6a31df --- /dev/null +++ b/tests/Behat/Resources/suites/ui/refunds.php @@ -0,0 +1,78 @@ +withProfile( + (new Profile('default')) + ->withSuite( + (new Suite('ui_refunds')) + ->withContexts( + 'sylius.behat.context.hook.doctrine_orm', + 'sylius.behat.context.hook.mailer', + CreditMemosContext::class, + ) + ->withContexts( + 'sylius.behat.context.transform.address', + 'sylius.behat.context.transform.channel', + 'sylius.behat.context.transform.country', + 'sylius.behat.context.transform.customer', + 'sylius.behat.context.transform.lexical', + 'sylius.behat.context.transform.order', + 'sylius.behat.context.transform.payment', + 'sylius.behat.context.transform.product', + 'sylius.behat.context.transform.promotion', + 'sylius.behat.context.transform.shared_storage', + 'sylius.behat.context.transform.shipping_method', + 'sylius.behat.context.transform.tax_category', + 'sylius.behat.context.transform.tax_rate', + 'sylius.behat.context.transform.zone', + TransformOrderContext::class, + ) + ->withContexts( + 'sylius.behat.context.setup.admin_security', + 'sylius.behat.context.setup.channel', + 'sylius.behat.context.setup.customer', + 'sylius.behat.context.setup.geographical', + 'sylius.behat.context.setup.order', + 'sylius.behat.context.setup.payment', + 'sylius.behat.context.setup.product', + 'sylius.behat.context.setup.promotion', + 'sylius.behat.context.setup.shipping', + 'sylius.behat.context.setup.taxation', + 'sylius.behat.context.setup.zone', + ChannelContext::class, + SetupOrderContext::class, + ProductContext::class, + SetupRefundingContext::class, + ) + ->withContexts( + 'sylius.behat.context.ui.admin.managing_orders', + ) + ->withContexts( + EmailsContext::class, + PaymentContext::class, + UiCreditMemoContext::class, + ManagingOrdersContext::class, + UiRefundingContext::class, + ) + ->withFilter(new TagFilter('@refunds&&@ui')), + ), + ) +; diff --git a/tests/Behat/Resources/suites/ui/refunds.yaml b/tests/Behat/Resources/suites/ui/refunds.yaml deleted file mode 100644 index fdc8c2822..000000000 --- a/tests/Behat/Resources/suites/ui/refunds.yaml +++ /dev/null @@ -1,50 +0,0 @@ -default: - suites: - ui_refunds: - contexts: - - sylius.behat.context.hook.doctrine_orm - - sylius.behat.context.hook.mailer - - Tests\Sylius\RefundPlugin\Behat\Context\Hook\CreditMemosContext - - - sylius.behat.context.transform.address - - sylius.behat.context.transform.channel - - sylius.behat.context.transform.country - - sylius.behat.context.transform.customer - - sylius.behat.context.transform.lexical - - sylius.behat.context.transform.order - - sylius.behat.context.transform.payment - - sylius.behat.context.transform.product - - sylius.behat.context.transform.promotion - - sylius.behat.context.transform.shared_storage - - sylius.behat.context.transform.shipping_method - - sylius.behat.context.transform.tax_category - - sylius.behat.context.transform.tax_rate - - sylius.behat.context.transform.zone - - Tests\Sylius\RefundPlugin\Behat\Context\Transform\OrderContext - - - sylius.behat.context.setup.admin_security - - sylius.behat.context.setup.channel - - sylius.behat.context.setup.customer - - sylius.behat.context.setup.geographical - - sylius.behat.context.setup.order - - sylius.behat.context.setup.payment - - sylius.behat.context.setup.product - - sylius.behat.context.setup.promotion - - sylius.behat.context.setup.shipping - - sylius.behat.context.setup.taxation - - sylius.behat.context.setup.zone - - Tests\Sylius\RefundPlugin\Behat\Context\Setup\ChannelContext - - Tests\Sylius\RefundPlugin\Behat\Context\Setup\OrderContext - - Tests\Sylius\RefundPlugin\Behat\Context\Setup\ProductContext - - Tests\Sylius\RefundPlugin\Behat\Context\Setup\RefundingContext - - - sylius.behat.context.ui.admin.managing_orders - - - Tests\Sylius\RefundPlugin\Behat\Context\Application\EmailsContext - - Tests\Sylius\RefundPlugin\Behat\Context\Setup\PaymentContext - - Tests\Sylius\RefundPlugin\Behat\Context\Ui\CreditMemoContext - - Tests\Sylius\RefundPlugin\Behat\Context\Ui\ManagingOrdersContext - - Tests\Sylius\RefundPlugin\Behat\Context\Ui\RefundingContext - - filters: - tags: "@refunds&&@ui" diff --git a/tests/TestApplication/config/services_test.php b/tests/TestApplication/config/services_test.php index 11320ed86..8da61dfb9 100644 --- a/tests/TestApplication/config/services_test.php +++ b/tests/TestApplication/config/services_test.php @@ -7,7 +7,7 @@ return function (ContainerConfigurator $container) { $env = $_ENV['APP_ENV'] ?? 'dev'; - if (str_starts_with($env, 'test') && filter_var(getenv('TEST_SYLIUS_REFUND_BEHAT_ENABLED') ?: 'true', FILTER_VALIDATE_BOOLEAN)) { + if (str_starts_with($env, 'test')) { $container->import('../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml'); $container->import('@SyliusRefundPlugin/tests/Behat/Resources/services.php'); } From 2c687f992992378cc2e433a2d642e8707e06819c Mon Sep 17 00:00:00 2001 From: TheMilek Date: Fri, 18 Sep 2026 12:54:28 +0200 Subject: [PATCH 4/6] Test Sylius 2.2 and 2.3 on PHP 8.3/8.4 and Symfony 6.4/7.4/8 --- .github/workflows/build.yaml | 58 ++++++++++-------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1e30fde28..fed4410fd 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -27,16 +27,26 @@ jobs: strategy: fail-fast: false matrix: - php: ["8.2", "8.3"] - symfony: ["^6.4", "^7.4"] - sylius: ["~2.0.0", "~2.1.0", "~2.2.0"] - node: ["22.x"] + php: ["8.3", "8.4"] + symfony: ["^6.4", "^7.4", "^8.0"] + sylius: ["~2.2.0", "~2.3.0"] + node: ["24.x"] database: ["mysql"] database_version: ["8.4"] wkhtmltopdf: ["0.12.6.1-2"] state_machine_adapter: ["symfony_workflow"] legacy_pdf_generation: [true, false] - composer_minimum_stability: [""] + + exclude: + # Symfony 8 requires PHP >= 8.4.1 + - + php: "8.3" + symfony: "^8.0" + + # Sylius 2.2 supports Symfony ^6.4.1 || ^7.4 only + - + sylius: "~2.2.0" + symfony: "^8.0" include: - @@ -49,7 +59,6 @@ jobs: wkhtmltopdf: "0.12.6.1-2" state_machine_adapter: "winzou_state_machine" legacy_pdf_generation: true - composer_minimum_stability: "" - php: "8.3" @@ -61,7 +70,6 @@ jobs: wkhtmltopdf: "0.12.6.1-2" state_machine_adapter: "winzou_state_machine" legacy_pdf_generation: false - composer_minimum_stability: "" - php: "8.3" @@ -73,7 +81,6 @@ jobs: wkhtmltopdf: false state_machine_adapter: "symfony_workflow" legacy_pdf_generation: true - composer_minimum_stability: "" - php: "8.3" @@ -85,7 +92,6 @@ jobs: wkhtmltopdf: false state_machine_adapter: "symfony_workflow" legacy_pdf_generation: false - composer_minimum_stability: "" - php: "8.3" @@ -97,7 +103,6 @@ jobs: wkhtmltopdf: "0.12.6.1-2" state_machine_adapter: "symfony_workflow" legacy_pdf_generation: true - composer_minimum_stability: "" - php: "8.3" @@ -109,33 +114,6 @@ jobs: wkhtmltopdf: "0.12.6.1-2" state_machine_adapter: "symfony_workflow" legacy_pdf_generation: false - composer_minimum_stability: "" - - # TODO: drop the "~2.3.0" restriction to a plain matrix entry (instead of an - # include row) once sylius/sylius 2.3 has a stable release. - - - php: "8.4" - symfony: "^8.0" - sylius: "~2.3.0" - node: "24.x" - database: "mysql" - database_version: "8.4" - wkhtmltopdf: "0.12.6.1-2" - state_machine_adapter: "symfony_workflow" - legacy_pdf_generation: true - composer_minimum_stability: "alpha" - - - - php: "8.4" - symfony: "^8.0" - sylius: "~2.3.0" - node: "24.x" - database: "mysql" - database_version: "8.4" - wkhtmltopdf: "0.12.6.1-2" - state_machine_adapter: "symfony_workflow" - legacy_pdf_generation: false - composer_minimum_stability: "alpha" env: APP_ENV: test @@ -191,11 +169,6 @@ jobs: composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10" composer config extra.symfony.require "${{ matrix.symfony }}" - - - name: Restrict Sylius version - if: matrix.sylius != '' - run: composer require "sylius/sylius:${{ matrix.sylius }}" --no-update --no-scripts --no-interaction - - name: Require Winzou State Machine if: "${{ matrix.state_machine_adapter == 'winzou_state_machine' }}" @@ -216,7 +189,6 @@ jobs: php_version: "${{ matrix.php }}" sylius_version: "${{ matrix.sylius }}" symfony_version: "${{ matrix.symfony }}" - composer_minimum_stability: "${{ matrix.composer_minimum_stability }}" composer_prefer_stable: "yes" - From ede4eff7c40e405c6cd3ddc19309a52b3b4be4d9 Mon Sep 17 00:00:00 2001 From: TheMilek Date: Fri, 18 Sep 2026 14:19:09 +0200 Subject: [PATCH 5/6] Load Sylius Behat services from PHP config on Symfony 8 --- tests/TestApplication/config/services_test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/TestApplication/config/services_test.php b/tests/TestApplication/config/services_test.php index 8da61dfb9..ab22d71ae 100644 --- a/tests/TestApplication/config/services_test.php +++ b/tests/TestApplication/config/services_test.php @@ -8,7 +8,10 @@ $env = $_ENV['APP_ENV'] ?? 'dev'; if (str_starts_with($env, 'test')) { - $container->import('../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml'); + // Sylius 2.3 ships its Behat services as a PHP config, earlier versions only as XML, + // which Symfony 8 can no longer load. + $syliusBehatServices = '../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services'; + $container->import(is_file(__DIR__ . '/' . $syliusBehatServices . '.php') ? $syliusBehatServices . '.php' : $syliusBehatServices . '.xml'); $container->import('@SyliusRefundPlugin/tests/Behat/Resources/services.php'); } From 845801de7541c5f1a6b3d4c7505ab8c1fe0b5302 Mon Sep 17 00:00:00 2001 From: TheMilek Date: Tue, 29 Sep 2026 13:12:09 +0200 Subject: [PATCH 6/6] Require Gaufrette now that Sylius no longer ships it --- UPGRADE-2.2.md | 36 +++++++++++++++++++++++++++++++ composer.json | 2 ++ config/config.yaml | 7 ++++++ tests/TestApplication/bundles.php | 1 + 4 files changed, 46 insertions(+) create mode 100644 UPGRADE-2.2.md diff --git a/UPGRADE-2.2.md b/UPGRADE-2.2.md new file mode 100644 index 000000000..8c36990c5 --- /dev/null +++ b/UPGRADE-2.2.md @@ -0,0 +1,36 @@ +# UPGRADE FROM 2.1 TO 2.2 + +1. Sylius 2.3 no longer ships `knplabs/gaufrette` and `knplabs/knp-gaufrette-bundle`, so the plugin now requires them itself. + `knplabs/knp-gaufrette-bundle` 1.0 supports Symfony 8, but it also upgrades `knplabs/gaufrette` to 1.0, + so verify that the Gaufrette adapters you use still work with it. + + Make sure `Knp\Bundle\GaufretteBundle\KnpGaufretteBundle` is registered in your `config/bundles.php`. + Nothing else changes: credit memos are still stored through the `gaufrette.sylius_refund_credit_memo_filesystem` filesystem. + + Gaufrette is used by the legacy PDF generator and will be removed in 3.0, together with the `sylius_refund.pdf_generator.legacy` option. + Migrating to the `SyliusPdfGenerationBundle` integration is recommended: + + ```yaml + sylius_refund: + pdf_generator: + legacy: false + ``` + + With the integration enabled, the storage of credit memos is configured through the `sylius_refund` context + of `SyliusPdfGenerationBundle`, which supports the `filesystem`, `flysystem` and `gaufrette` storage types. + It defaults to the Gaufrette filesystem above. The plugin also provides the `sylius_refund.storage.credit_memo` Flysystem storage, + using the local adapter in the same `%sylius_refund.credit_memo_save_path%` directory, which will become the default in 3.0. + To switch to it already, so existing credit memos are still found: + + ```yaml + sylius_pdf_generation: + contexts: + sylius_refund: + storage: + type: flysystem + filesystem: sylius_refund.storage.credit_memo + ``` + + To store credit memos elsewhere (e.g. on S3), redefine the `sylius_refund.storage.credit_memo` storage under `flysystem.storages`, + see the [FlysystemBundle documentation](https://github.com/thephpleague/flysystem-bundle/blob/3.x/docs/2-cloud-storage-providers.md). + See the [SyliusPdfGenerationBundle documentation](https://github.com/Sylius/PdfGenerationBundle#configuration) for the other storage types. diff --git a/composer.json b/composer.json index d15e38ba2..1afe7e154 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,8 @@ ], "require": { "php": "^8.2", + "knplabs/gaufrette": "^0.11 || ^1.0", + "knplabs/knp-gaufrette-bundle": "^0.9 || ^1.0", "knplabs/knp-snappy-bundle": "^1.10", "myclabs/php-enum": "^1.8", "php-http/discovery": "^1.20", diff --git a/config/config.yaml b/config/config.yaml index 45d348deb..76a0a6acd 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -143,3 +143,10 @@ knp_gaufrette: filesystems: sylius_refund_credit_memo: adapter: "%sylius_refund.filesystem_adapter.credit_memo%" + +flysystem: + storages: + sylius_refund.storage.credit_memo: + adapter: "local" + options: + directory: "%sylius_refund.credit_memo_save_path%" diff --git a/tests/TestApplication/bundles.php b/tests/TestApplication/bundles.php index 2e87f1f8f..d9a0e60a7 100644 --- a/tests/TestApplication/bundles.php +++ b/tests/TestApplication/bundles.php @@ -3,6 +3,7 @@ declare(strict_types=1); $bundles = [ + Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true], Knp\Bundle\SnappyBundle\KnpSnappyBundle::class => ['all' => true], Sylius\PdfGenerationBundle\SyliusPdfGenerationBundle::class => ['all' => true], Sylius\RefundPlugin\SyliusRefundPlugin::class => ['all' => true],