From 3cbd71112518dcaf9ddc924bc0d3fd2481356c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Thu, 4 Jan 2024 11:53:43 +0100 Subject: [PATCH 01/12] Upgrade to Sylius 1.11 and 1.12 --- .circleci/config.yml | 14 ++++++--- Makefile | 10 +++++- README.md | 72 ++++++++++++++++++++++---------------------- behat.yml.dist | 56 ++++++++++++++++++++++++++++++++++ composer.json | 3 +- ecs.php | 1 + phpstan.neon | 1 + 7 files changed, 115 insertions(+), 42 deletions(-) create mode 100644 behat.yml.dist diff --git a/.circleci/config.yml b/.circleci/config.yml index 2eea0b9..ec3fc6d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -61,13 +61,13 @@ jobs: MYSQL_PASSWORD: pass steps: - - checkout + - checkout # to avoid installing different package "Note, selecting 'cmdtest' instead of 'yarn'" - run: curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - - run: echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list - run: curl -fsSL https://deb.nodesource.com/setup_18.x | bash - - run: apt-get update - # netcat to get 'nc' command for waiting for database + # netcat to get 'nc' command for waiting for database - run: apt-get install -y nodejs yarn mariadb-client netcat - run: composer self-update @@ -77,8 +77,8 @@ jobs: - run: name: Wait for database - command: timeout 60s bash -c -- 'while ! nc -z 127.0.0.1 3306; do sleep 0.1; done' \ - && timeout 30s bash -c -- 'mysql --user=sylius --password=pass --host=127.0.0.1 --port=3306 -e "exit"' + command: timeout 60s bash -c -- 'while ! nc -z localhost 3306; do sleep 0.1; done' \ + && timeout 30s bash -c -- 'mysql --user=sylius --password=pass --host=localhost --port=3306 -e "exit"' # COMPOSER PREFER LOWEST (oldest possible) # # has to delete vendor for next test with different libraries version to avoid Composer error 'Failed to extract...' if vendor dir cache does not exist @@ -90,6 +90,11 @@ jobs: - run: (cd tests/Application && bin/console doctrine:schema:update --force --env=test -vvv) - run: (cd tests/Application && bin/console cache:clear --env=test -vvv) - run: (cd tests/Application && bin/console cache:warmup --env=test -vvv) + - run: + name: Behat + environment: + APP_SUPPRESS_DEPRECATED_ERRORS: 1 + command: APP_ENV=test bin/behat - run: APP_ENV=test bin/phpstan.sh - run: APP_ENV=test bin/ecs.sh --clear-cache - run: APP_ENV=test bin/symfony-lint.sh @@ -102,6 +107,7 @@ jobs: - run: (cd tests/Application && bin/console doctrine:schema:update --force --env=test -vvv) - run: (cd tests/Application && bin/console cache:clear --env=test -vvv) - run: (cd tests/Application && bin/console cache:warmup --env=test -vvv) + - run: APP_ENV=test bin/behat - run: APP_ENV=test bin/phpstan.sh - run: APP_ENV=test bin/ecs.sh --clear-cache - run: APP_ENV=test bin/symfony-lint.sh diff --git a/Makefile b/Makefile index 0c2e616..9dd3c07 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ phpstan: ecs: APP_ENV=test bin/ecs.sh +behat-js: + APP_ENV=test APP_SUPPRESS_DEPRECATED_ERRORS=1 bin/behat --colors --strict --no-interaction -vvv -f progress + install: composer install --no-interaction --no-scripts @@ -16,11 +19,16 @@ frontend: (cd tests/Application && yarn install --pure-lockfile) (cd tests/Application && GULP_ENV=prod yarn build) +behat: + APP_ENV=test bin/behat --colors --strict --no-interaction -vvv -f progress + lint: APP_ENV=test bin/symfony-lint.sh init: install backend frontend -ci: init phpstan ecs lint +ci: init phpstan ecs behat lint + +integration: init behat static: install phpstan ecs lint diff --git a/README.md b/README.md index 6a57be6..820da60 100644 --- a/README.md +++ b/README.md @@ -49,53 +49,53 @@ For guide how to use your own entity see [Sylius docs - Customizing Models](http 1. Include `@ThreeBRSSyliusPaymentFeePlugin/Admin/_form.html.twig` into `@SyliusAdmin/PaymentMethod/_form.html.twig`. -```twig -{# ... #} - -{% include '@ThreeBRSSyliusPaymentFeePlugin/Admin/_form.html.twig' %} -``` + ```twig + {# ... #} + + {% include '@ThreeBRSSyliusPaymentFeePlugin/Admin/_form.html.twig' %} + ``` 1. Include `@ThreeBRSSyliusPaymentFeePlugin/Admin/_order_show.html.twig` into `@AdminBundle/Order/Show/Summary/_totals.html.twig`. -```twig -{# ... #} - -{% include '@ThreeBRSSyliusPaymentFeePlugin/Admin/_order_show.html.twig' %} -``` + ```twig + {# ... #} + + {% include '@ThreeBRSSyliusPaymentFeePlugin/Admin/_order_show.html.twig' %} + ``` ### Shop 1. Include `@ThreeBRSSyliusPaymentFeePlugin/Shop/Checkout/SelectPayment/_choice.html.twig` into `@ShopBundle/Checkout/SelectPayment/_choice.html.twig`. -```twig -{# ... #} - -{% include '@ThreeBRSSyliusPaymentFeePlugin/Shop/Checkout/SelectPayment/_choice.html.twig' %} -``` + ```twig + {# ... #} + + {% include '@ThreeBRSSyliusPaymentFeePlugin/Shop/Checkout/SelectPayment/_choice.html.twig' %} + ``` 1. Add variable fee `{% set fee = form.method.vars.payment_costs[choice_form.vars.value] %}` into `@ShopBundle/Checkout/SelectPayment/_payment.html.twig` into `foreach`. -```twig -{# ... #} - -{% for key, choice_form in form.method %} - {% set fee = form.method.vars.payment_costs[choice_form.vars.value] %} - {% include '@SyliusShop/Checkout/SelectPayment/_choice.html.twig' with {'form': choice_form, 'method': form.method.vars.choices[key].data} %} -{% else %} - {% include '@SyliusShop/Checkout/SelectPayment/_unavailable.html.twig' %} -{% endfor %} -``` + ```twig + {# ... #} + + {% for key, choice_form in form.method %} + {% set fee = form.method.vars.payment_costs[choice_form.vars.value] %} + {% include '@SyliusShop/Checkout/SelectPayment/_choice.html.twig' with {'form': choice_form, 'method': form.method.vars.choices[key].data} %} + {% else %} + {% include '@SyliusShop/Checkout/SelectPayment/_unavailable.html.twig' %} + {% endfor %} + ``` 1. Include `@ThreeBRSSyliusPaymentFeePlugin/Shop/Common/Order/Table/_payment.html.twig` into `@ShopBundle/Common/Order/Table/_totals.html.twig`. -```twig -{# ... #} - - - {% include '@SyliusShop/Common/Order/Table/_shipping.html.twig' with {'order': order} %} - -{% include '@ThreeBRSSyliusPaymentFeePlugin/Shop/Common/Order/Table/_payment.html.twig' with {'order': order} %} -``` + ```twig + {# ... #} + + + {% include '@SyliusShop/Common/Order/Table/_shipping.html.twig' with {'order': order} %} + + {% include '@ThreeBRSSyliusPaymentFeePlugin/Shop/Common/Order/Table/_payment.html.twig' with {'order': order} %} + ``` 1. Create and run doctrine database migrations ```bash @@ -133,9 +133,9 @@ vendor/bin/phpspec run ### Opening Sylius with your plugin 1. Install symfony CLI command: https://symfony.com/download - - hint: for Docker (with Ubuntu) use _Debian/Ubuntu — APT based - Linux_ installation steps as `root` user and without `sudo` command - - you may need to install `curl` first ```apt-get update && apt-get install curl --yes``` + - hint: for Docker (with Ubuntu) use _Debian/Ubuntu — APT based + Linux_ installation steps as `root` user and without `sudo` command + - you may need to install `curl` first ```apt-get update && apt-get install curl --yes``` 2. Run app ```bash diff --git a/behat.yml.dist b/behat.yml.dist new file mode 100644 index 0000000..84738de --- /dev/null +++ b/behat.yml.dist @@ -0,0 +1,56 @@ +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: "https://127.0.0.1:8080/" + default_session: symfony + javascript_session: chrome_headless + sessions: + symfony: + symfony: ~ + chrome_headless: + chrome: + api_url: http://127.0.0.1:9222 + validate_certificate: false + chrome: + selenium2: + browser: chrome + capabilities: + browserName: chrome + browser: chrome + version: "" + marionette: null # https://github.com/Behat/MinkExtension/pull/311 + chrome: + switches: + - "start-fullscreen" + - "start-maximized" + - "no-sandbox" + extra_capabilities: + unexpectedAlertBehaviour: accept + firefox: + selenium2: + browser: firefox + show_auto: false + + FriendsOfBehat\SymfonyExtension: + bootstrap: tests/Application/config/bootstrap.php + kernel: + class: Tests\ThreeBRS\SyliusPaymentFeePlugin\Kernel + environment: test + + FriendsOfBehat\VariadicExtension: ~ + + FriendsOfBehat\SuiteSettingsExtension: + paths: + - "features" diff --git a/composer.json b/composer.json index c705077..2ae2b17 100644 --- a/composer.json +++ b/composer.json @@ -89,7 +89,8 @@ }, "autoload-dev": { "psr-4": { - "Tests\\ThreeBRS\\SyliusPaymentFeePlugin\\": "tests/Application/src/" + "Tests\\ThreeBRS\\SyliusPaymentFeePlugin\\": "tests/Application/src/", + "Tests\\ThreeBRS\\SyliusPaymentFeePlugin\\Behat\\": "tests/Behat/" } }, "exclude-from-classmap": [ diff --git a/ecs.php b/ecs.php index 8912a27..67d06fd 100644 --- a/ecs.php +++ b/ecs.php @@ -8,6 +8,7 @@ return static function (ECSConfig $ecsConfig): void { $ecsConfig->paths([ __DIR__ . '/src', + __DIR__ . '/tests/Behat', __DIR__ . '/ecs.php', ]); diff --git a/phpstan.neon b/phpstan.neon index d212c4f..6dcf7cb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,6 +7,7 @@ parameters: paths: - src - tests/Application/src + - tests/Behat excludePaths: # Makes PHPStan crash From 5058942d39043ecc31f56a52b8b20acb428bb3aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Tue, 9 Jan 2024 14:06:14 +0100 Subject: [PATCH 02/12] Update make commands to init test app more smoothly --- .circleci/config.yml | 48 +++++++++++++++++++++----------------------- Makefile | 4 +++- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ec3fc6d..9d21e15 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,30 +7,27 @@ workflows: name: php-<>-sylius-<< matrix.sylius_version >>-symfony-<< matrix.symfony_version >> matrix: parameters: - php_version: - - "8.0" - sylius_version: - - "1.11" - symfony_version: - - "5.4" + sylius_version: [ "1.11" ] + php_version: [ "8.0" ] + symfony_version: [ "5.4" ] + sylius1.11-php8.1+: + jobs: + - build: + name: php-<>-sylius-<< matrix.sylius_version >>-symfony-<< matrix.symfony_version >> + matrix: + parameters: + sylius_version: [ "1.11" ] + php_version: [ "8.1", "8.2", "8.3" ] + symfony_version: [ "5.4" ] sylius1.12-php8.0: jobs: - build: name: php-<>-sylius-<< matrix.sylius_version >>-symfony-<< matrix.symfony_version >> matrix: parameters: - php_version: [ "8.0" ] sylius_version: [ "1.12" ] + php_version: [ "8.0" ] symfony_version: [ "5.4", "6.0" ] - sylius1.11-php8.1+: - jobs: - - build: - name: php-<>-sylius-<< matrix.sylius_version >>-symfony-<< matrix.symfony_version >> - matrix: - parameters: - sylius_version: [ "1.11" ] - symfony_version: [ "5.4" ] - php_version: [ "8.1", "8.2" ] sylius1.12-php8.1+: jobs: - build: @@ -38,7 +35,7 @@ workflows: matrix: parameters: sylius_version: [ "1.12" ] - php_version: [ "8.1", "8.2" ] + php_version: [ "8.1", "8.2", "8.3" ] symfony_version: [ "5.4", "6.0", "6.1", "6.2", "6.3", "6.4" ] jobs: @@ -61,14 +58,14 @@ jobs: MYSQL_PASSWORD: pass steps: - - checkout + - checkout # to avoid installing different package "Note, selecting 'cmdtest' instead of 'yarn'" - run: curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - - run: echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list - run: curl -fsSL https://deb.nodesource.com/setup_18.x | bash - - run: apt-get update - # netcat to get 'nc' command for waiting for database - - run: apt-get install -y nodejs yarn mariadb-client netcat + # netcat to get 'nc' command for waiting for database + - run: apt-get install -y nodejs yarn mariadb-client netcat-traditional - run: composer self-update # Sylius & Symfony in current matrix versions @@ -77,8 +74,8 @@ jobs: - run: name: Wait for database - command: timeout 60s bash -c -- 'while ! nc -z localhost 3306; do sleep 0.1; done' \ - && timeout 30s bash -c -- 'mysql --user=sylius --password=pass --host=localhost --port=3306 -e "exit"' + command: timeout 60s bash -c -- 'while ! nc -z 127.0.0.1 3306; do sleep 0.1; done' \ + && timeout 30s bash -c -- 'mysql --user=sylius --password=pass --host=127.0.0.1 --port=3306 -e "exit"' # COMPOSER PREFER LOWEST (oldest possible) # # has to delete vendor for next test with different libraries version to avoid Composer error 'Failed to extract...' if vendor dir cache does not exist @@ -86,10 +83,11 @@ jobs: - run: composer update --no-interaction --prefer-lowest --no-plugins - run: yarn --cwd tests/Application install - run: yarn --cwd tests/Application build - - run: (cd tests/Application && bin/console doctrine:database:create --if-not-exists --env=test -vvv) - - run: (cd tests/Application && bin/console doctrine:schema:update --force --env=test -vvv) - run: (cd tests/Application && bin/console cache:clear --env=test -vvv) - run: (cd tests/Application && bin/console cache:warmup --env=test -vvv) + - run: (cd tests/Application && bin/console doctrine:database:create --if-not-exists --env=test -vvv) + - run: (cd tests/Application && bin/console doctrine:schema:update --force --complete --no-interaction --env=test -vvv) + - run: (cd tests/Application && bin/console doctrine:migrations:sync-metadata-storage --no-interaction --env=test -vvv) - run: name: Behat environment: @@ -104,7 +102,7 @@ jobs: - run: yarn --cwd tests/Application install - run: yarn --cwd tests/Application build - run: (cd tests/Application && bin/console doctrine:database:create --if-not-exists --env=test -vvv) - - run: (cd tests/Application && bin/console doctrine:schema:update --force --env=test -vvv) + - run: (cd tests/Application && bin/console doctrine:schema:update --force --complete --no-interaction --env=test -vvv) - run: (cd tests/Application && bin/console cache:clear --env=test -vvv) - run: (cd tests/Application && bin/console cache:warmup --env=test -vvv) - run: APP_ENV=test bin/behat diff --git a/Makefile b/Makefile index 9dd3c07..cc035e1 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,10 @@ install: composer install --no-interaction --no-scripts backend: - APP_ENV=test tests/Application/bin/console sylius:install --no-interaction + APP_ENV=test tests/Application/bin/console doctrine:database:create --if-not-exists --no-interaction + APP_ENV=test tests/Application/bin/console doctrine:migrations:sync-metadata-storage --no-interaction APP_ENV=test tests/Application/bin/console doctrine:schema:update --force --complete --no-interaction + APP_ENV=test tests/Application/bin/console sylius:install --no-interaction APP_ENV=test tests/Application/bin/console sylius:fixtures:load default --no-interaction frontend: From 8f2cd8c9ccffe1336d25399273996983015c2f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Tue, 9 Jan 2024 15:04:28 +0100 Subject: [PATCH 03/12] Update EasyCodingStandard --- easy-coding-standard.yml | 6 ----- ecs.php | 10 ++++---- .../Compiler/RegisterFeeCalculatorsPass.php | 8 +++++-- .../PaymentMethodChoiceTypeExtension.php | 9 ++++--- .../Extension/PaymentMethodTypeExtension.php | 10 ++++---- .../Calculator/FlatRateConfigurationType.php | 24 +++++++++---------- src/Form/Type/CalculatorChoiceType.php | 5 ++-- src/Model/Calculator/DelegatingCalculator.php | 5 ++-- src/Model/PaymentChargesProcessor.php | 6 +++-- 9 files changed, 42 insertions(+), 41 deletions(-) delete mode 100644 easy-coding-standard.yml diff --git a/easy-coding-standard.yml b/easy-coding-standard.yml deleted file mode 100644 index 56efe75..0000000 --- a/easy-coding-standard.yml +++ /dev/null @@ -1,6 +0,0 @@ -imports: - - { resource: 'vendor/sylius-labs/coding-standard/easy-coding-standard.yml' } - -parameters: - indentation: tab - diff --git a/ecs.php b/ecs.php index 67d06fd..3e6f984 100644 --- a/ecs.php +++ b/ecs.php @@ -3,16 +3,16 @@ declare(strict_types=1); use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer; +use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer; +use Symplify\CodingStandard\Fixer\Spacing\StandaloneLineConstructorParamFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; return static function (ECSConfig $ecsConfig): void { - $ecsConfig->paths([ - __DIR__ . '/src', - __DIR__ . '/tests/Behat', - __DIR__ . '/ecs.php', - ]); + $ecsConfig->paths([__DIR__ . '/src', __DIR__ . '/tests/Behat', __DIR__ . '/ecs.php']); $ecsConfig->import('vendor/sylius-labs/coding-standard/ecs.php'); + $ecsConfig->rule(StandaloneLineConstructorParamFixer::class); + $ecsConfig->rule(LineLengthFixer::class); $ecsConfig->skip([ __DIR__ . '/tests/Application/var/', diff --git a/src/DependencyInjection/Compiler/RegisterFeeCalculatorsPass.php b/src/DependencyInjection/Compiler/RegisterFeeCalculatorsPass.php index 561c0a8..b3976b8 100644 --- a/src/DependencyInjection/Compiler/RegisterFeeCalculatorsPass.php +++ b/src/DependencyInjection/Compiler/RegisterFeeCalculatorsPass.php @@ -19,12 +19,16 @@ public function process(ContainerBuilder $container): void } $registry = $container->getDefinition('threebrs.sylius_payment_fee_plugin.registry.payment_calculator'); - $formTypeRegistry = $container->getDefinition('threebrs.sylius_payment_fee_plugin.form_registry.payment_calculator'); + $formTypeRegistry = $container->getDefinition( + 'threebrs.sylius_payment_fee_plugin.form_registry.payment_calculator', + ); $calculators = []; foreach ($container->findTaggedServiceIds(DelegatingCalculator::class) as $id => $attributes) { if (!isset($attributes[0]['calculator'], $attributes[0]['label'])) { - throw new \InvalidArgumentException('Tagged payment fee calculators needs to have `calculator` and `label` attributes.'); + throw new \InvalidArgumentException( + 'Tagged payment fee calculators needs to have `calculator` and `label` attributes.', + ); } $name = $attributes[0]['calculator']; diff --git a/src/Form/Extension/PaymentMethodChoiceTypeExtension.php b/src/Form/Extension/PaymentMethodChoiceTypeExtension.php index 8000992..de22efa 100644 --- a/src/Form/Extension/PaymentMethodChoiceTypeExtension.php +++ b/src/Form/Extension/PaymentMethodChoiceTypeExtension.php @@ -15,8 +15,9 @@ class PaymentMethodChoiceTypeExtension extends AbstractTypeExtension { - public function __construct(private ServiceRegistryInterface $calculatorRegistry) - { + public function __construct( + private ServiceRegistryInterface $calculatorRegistry, + ) { } /** @@ -55,8 +56,6 @@ public function buildView(FormView $view, FormInterface $form, array $options): public static function getExtendedTypes(): iterable { - return [ - PaymentMethodChoiceType::class, - ]; + return [PaymentMethodChoiceType::class]; } } diff --git a/src/Form/Extension/PaymentMethodTypeExtension.php b/src/Form/Extension/PaymentMethodTypeExtension.php index 0dff11b..3e1294a 100644 --- a/src/Form/Extension/PaymentMethodTypeExtension.php +++ b/src/Form/Extension/PaymentMethodTypeExtension.php @@ -21,8 +21,10 @@ class PaymentMethodTypeExtension extends AbstractTypeExtension { - public function __construct(private ServiceRegistryInterface $calculatorRegistry, private FormTypeRegistryInterface $formTypeRegistry) - { + public function __construct( + private ServiceRegistryInterface $calculatorRegistry, + private FormTypeRegistryInterface $formTypeRegistry, + ) { } public function buildForm(FormBuilderInterface $builder, array $options): void @@ -109,8 +111,6 @@ public function buildView(FormView $view, FormInterface $form, array $options): public static function getExtendedTypes(): iterable { - return [ - SyliusPaymentMethodType::class, - ]; + return [SyliusPaymentMethodType::class]; } } diff --git a/src/Form/Type/Calculator/FlatRateConfigurationType.php b/src/Form/Type/Calculator/FlatRateConfigurationType.php index 4c459fc..08d1843 100644 --- a/src/Form/Type/Calculator/FlatRateConfigurationType.php +++ b/src/Form/Type/Calculator/FlatRateConfigurationType.php @@ -20,14 +20,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'amount', MoneyType::class, [ - 'label' => 'threebrs.form.payment_calculator.flat_rate_configuration.amount', - 'constraints' => [ - new NotBlank(['groups' => ['sylius']]), - new Type(['type' => 'integer', 'groups' => ['sylius']]), + 'label' => 'threebrs.form.payment_calculator.flat_rate_configuration.amount', + 'constraints' => [ + new NotBlank(['groups' => ['sylius']]), + new Type(['type' => 'integer', 'groups' => ['sylius']]), + ], + 'currency' => $options['currency'], ], - 'currency' => $options['currency'], - ], - ); + ) + ; } /** @@ -36,13 +37,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver - ->setDefaults( - [ + ->setDefaults([ 'data_class' => null, - ], - ) + ]) ->setRequired('currency') - ->setAllowedTypes('currency', 'string'); + ->setAllowedTypes('currency', 'string') + ; } /** diff --git a/src/Form/Type/CalculatorChoiceType.php b/src/Form/Type/CalculatorChoiceType.php index 4a3a953..306c128 100644 --- a/src/Form/Type/CalculatorChoiceType.php +++ b/src/Form/Type/CalculatorChoiceType.php @@ -13,8 +13,9 @@ final class CalculatorChoiceType extends AbstractType /** * @param array $calculators */ - public function __construct(private array $calculators) - { + public function __construct( + private array $calculators, + ) { } /** diff --git a/src/Model/Calculator/DelegatingCalculator.php b/src/Model/Calculator/DelegatingCalculator.php index 47db406..fb1669b 100644 --- a/src/Model/Calculator/DelegatingCalculator.php +++ b/src/Model/Calculator/DelegatingCalculator.php @@ -10,8 +10,9 @@ final class DelegatingCalculator implements DelegatingCalculatorInterface { - public function __construct(private ServiceRegistryInterface $registry) - { + public function __construct( + private ServiceRegistryInterface $registry, + ) { } public function calculate(PaymentInterface $subject): ?int diff --git a/src/Model/PaymentChargesProcessor.php b/src/Model/PaymentChargesProcessor.php index 3d33027..8176021 100644 --- a/src/Model/PaymentChargesProcessor.php +++ b/src/Model/PaymentChargesProcessor.php @@ -13,8 +13,10 @@ final class PaymentChargesProcessor implements OrderProcessorInterface { - public function __construct(private FactoryInterface $adjustmentFactory, private DelegatingCalculatorInterface $paymentChargesCalculator) - { + public function __construct( + private FactoryInterface $adjustmentFactory, + private DelegatingCalculatorInterface $paymentChargesCalculator, + ) { } public function process(BaseOrderInterface $order): void From 6ff52a70bdcc443215ab6e16e21cb7ffd2b2c583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Thu, 11 Jan 2024 08:55:02 +0100 Subject: [PATCH 04/12] Update translation key to be more expectable --- src/Resources/translations/messages+intl-icu.cs_CZ.yml | 2 ++ src/Resources/translations/messages+intl-icu.en.yml | 2 ++ src/Resources/views/Admin/_order_show.html.twig | 2 +- .../views/Shop/Common/Order/Table/_payment.html.twig | 6 +++--- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Resources/translations/messages+intl-icu.cs_CZ.yml b/src/Resources/translations/messages+intl-icu.cs_CZ.yml index cd80773..9f34ab0 100644 --- a/src/Resources/translations/messages+intl-icu.cs_CZ.yml +++ b/src/Resources/translations/messages+intl-icu.cs_CZ.yml @@ -1,7 +1,9 @@ threebrs: ui: payment_charges: Poplatky + # deprecated, use payment_fee_total instead paymentFee_total: Poplatky celkem + payment_fee_total: Poplatky celkem form: payment_method: calculator: Calculator diff --git a/src/Resources/translations/messages+intl-icu.en.yml b/src/Resources/translations/messages+intl-icu.en.yml index 17505d3..6870ed6 100644 --- a/src/Resources/translations/messages+intl-icu.en.yml +++ b/src/Resources/translations/messages+intl-icu.en.yml @@ -1,7 +1,9 @@ threebrs: ui: payment_charges: Payment charges + # deprecated, use payment_fee_total instead paymentFee_total: Payment fees total + payment_fee_total: Payment fees total form: payment_method: calculator: Calculator diff --git a/src/Resources/views/Admin/_order_show.html.twig b/src/Resources/views/Admin/_order_show.html.twig index d3599ec..43784dd 100644 --- a/src/Resources/views/Admin/_order_show.html.twig +++ b/src/Resources/views/Admin/_order_show.html.twig @@ -20,7 +20,7 @@ - {{ 'threebrs.ui.paymentFee_total'|trans }}: + {{ 'threebrs.ui.payment_fee_total'|trans }}: {{ money.format(order.getAdjustmentsTotal(paymentFeeAdjustment) ,order.currencyCode) }} diff --git a/src/Resources/views/Shop/Common/Order/Table/_payment.html.twig b/src/Resources/views/Shop/Common/Order/Table/_payment.html.twig index e2e3253..a2a0623 100644 --- a/src/Resources/views/Shop/Common/Order/Table/_payment.html.twig +++ b/src/Resources/views/Shop/Common/Order/Table/_payment.html.twig @@ -7,9 +7,9 @@ {% if paymentFeeAdjustmentTotal > 0 %} - - {{ 'threebrs.ui.paymentFee_total'|trans }}: - {{ money.convertAndFormat(paymentFeeAdjustmentTotal) }} + + {{ 'threebrs.ui.payment_fee_total'|trans }}: + {{ money.convertAndFormat(paymentFeeAdjustmentTotal) }} {% endif %} From cc4f6292e8e54a6ae70992c3e918f5d4e8fc0fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Thu, 11 Jan 2024 08:55:58 +0100 Subject: [PATCH 05/12] Add support to Doctrine attributes --- CHANGELOG.md | 8 +++++++- src/Model/PaymentMethodWithFeeTrait.php | 7 +++++-- tests/Application/config/packages/doctrine.yaml | 2 +- tests/Application/src/Entity/PaymentMethod.php | 5 +++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e452251..7303649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,14 @@ #### Details -- Add support for Sylius 1.11|1.12, Symfony ^5.4|^6.0, PHP ^8.0 +```diff ++ Add support for Sylius 1.11|1.12, Symfony ^5.4|^6.0, PHP ^8.0 + - Drop support for Sylius <= 1.10 and consequentially for Symfony <= 5.3, <= PHP 7.4 +``` +- ⚠️ *BC break: interface \ThreeBRS\SyliusPaymentFeePlugin\Model\PaymentMethodWithFeeInterface enforces new methods `setCalculator`, `setCalculatorConfiguration` and `getTaxCategory`* +- 👎 Deprecated translation key `paymentFee_total` in favor of `payment_fee_total` +- 👎 Deprecated [Doctrine `@annotations`](https://www.doctrine-project.org/projects/doctrine-annotations/en/stable/index.html) in favor of [Doctrine `#[Atributtes]`](https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/attributes-reference.html) ## v1.0.0 (2021-11-10) diff --git a/src/Model/PaymentMethodWithFeeTrait.php b/src/Model/PaymentMethodWithFeeTrait.php index 161833f..2b7ad1e 100644 --- a/src/Model/PaymentMethodWithFeeTrait.php +++ b/src/Model/PaymentMethodWithFeeTrait.php @@ -10,16 +10,19 @@ trait PaymentMethodWithFeeTrait { /** @ORM\Column(name="calculator", type="text", nullable=true) */ + #[ORM\Column(name: 'calculator', type: 'text', nullable: true)] protected ?string $calculator = null; /** * @ORM\ManyToOne(targetEntity="Sylius\Component\Taxation\Model\TaxCategoryInterface") - * * @ORM\JoinColumn(name="tax_category_id") */ + #[ORM\ManyToOne(targetEntity: TaxCategoryInterface::class)] + #[ORM\JoinColumn(name: 'tax_category_id')] protected ?TaxCategoryInterface $taxCategory = null; /** @ORM\Column(name="calculator_configuration", type="json", nullable=true) */ + #[ORM\Column(name: 'calculator_configuration', type: 'json', nullable: true)] protected array $calculatorConfiguration = []; public function getCalculator(): ?string @@ -34,7 +37,7 @@ public function setCalculator(?string $calculator): void public function getCalculatorConfiguration(): array { - return $this->calculatorConfiguration ?? []; + return $this->calculatorConfiguration; } public function setCalculatorConfiguration(array $calculatorConfiguration): void diff --git a/tests/Application/config/packages/doctrine.yaml b/tests/Application/config/packages/doctrine.yaml index c4512e6..fdbd228 100644 --- a/tests/Application/config/packages/doctrine.yaml +++ b/tests/Application/config/packages/doctrine.yaml @@ -18,7 +18,7 @@ doctrine: mappings: App: is_bundle: false - type: annotation + type: attribute dir: '%kernel.project_dir%/src/Entity' prefix: 'Tests\ThreeBRS\SyliusPaymentFeePlugin\Entity' alias: App diff --git a/tests/Application/src/Entity/PaymentMethod.php b/tests/Application/src/Entity/PaymentMethod.php index 669bbf7..e159363 100644 --- a/tests/Application/src/Entity/PaymentMethod.php +++ b/tests/Application/src/Entity/PaymentMethod.php @@ -10,9 +10,14 @@ use ThreeBRS\SyliusPaymentFeePlugin\Model\PaymentMethodWithFeeTrait; /** + * Doctrine annotations are deprecated + * You can test they still works by changing in tests/Application/config/packages/doctrine.yaml + * configuration doctrine.orm.mappings.App.type to 'annotation' * @ORM\Entity * @ORM\Table(name="sylius_payment_method") */ +#[ORM\Entity] +#[ORM\Table(name: "sylius_payment_method")] class PaymentMethod extends BasePaymentMethod implements PaymentMethodWithFeeInterface { use PaymentMethodWithFeeTrait; From ebce67dfb12d6c71e5a0af59e7643ba14b8604a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Thu, 11 Jan 2024 08:56:51 +0100 Subject: [PATCH 06/12] Extend payment method with fee interface for new methods --- src/Model/PaymentMethodWithFeeInterface.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Model/PaymentMethodWithFeeInterface.php b/src/Model/PaymentMethodWithFeeInterface.php index d1921ee..d77f1f3 100644 --- a/src/Model/PaymentMethodWithFeeInterface.php +++ b/src/Model/PaymentMethodWithFeeInterface.php @@ -12,10 +12,13 @@ interface PaymentMethodWithFeeInterface extends PaymentMethodInterface, TaxableI { public function getCalculator(): ?string; - /** - * @return array - */ + public function setCalculator(?string $calculator): void; + public function getCalculatorConfiguration(): array; + public function setCalculatorConfiguration(array $calculatorConfiguration): void; + + public function getTaxCategory(): ?TaxCategoryInterface; + public function setTaxCategory(?TaxCategoryInterface $category): void; } From 5392c0c2f3df4947aed8561eef31707ef7e7ff50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Thu, 11 Jan 2024 08:57:32 +0100 Subject: [PATCH 07/12] Clean some PHPDocs and Twig --- src/Form/Extension/PaymentMethodChoiceTypeExtension.php | 3 --- src/Form/Extension/PaymentMethodTypeExtension.php | 4 ++-- src/Form/Type/CalculatorChoiceType.php | 2 +- src/Model/PaymentMethodWithFeeTrait.php | 1 + src/Resources/views/Admin/_form.html.twig | 2 +- src/Resources/views/Admin/_order_show.html.twig | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Form/Extension/PaymentMethodChoiceTypeExtension.php b/src/Form/Extension/PaymentMethodChoiceTypeExtension.php index de22efa..5ebc0d7 100644 --- a/src/Form/Extension/PaymentMethodChoiceTypeExtension.php +++ b/src/Form/Extension/PaymentMethodChoiceTypeExtension.php @@ -20,9 +20,6 @@ public function __construct( ) { } - /** - * @param array $options - */ public function buildView(FormView $view, FormInterface $form, array $options): void { if (!isset($options['subject'])) { diff --git a/src/Form/Extension/PaymentMethodTypeExtension.php b/src/Form/Extension/PaymentMethodTypeExtension.php index 3e1294a..9efa039 100644 --- a/src/Form/Extension/PaymentMethodTypeExtension.php +++ b/src/Form/Extension/PaymentMethodTypeExtension.php @@ -75,12 +75,12 @@ function (FormEvent $event) { continue; } - $form = $builder->create( + $formBuilder = $builder->create( 'calculatorConfiguration', $this->formTypeRegistry->get($calculatorType, 'default'), ); - $prototypes['calculators'][$name] = $form->getForm(); + $prototypes['calculators'][$name] = $formBuilder->getForm(); } $builder->setAttribute('prototypes', $prototypes); diff --git a/src/Form/Type/CalculatorChoiceType.php b/src/Form/Type/CalculatorChoiceType.php index 306c128..994ad76 100644 --- a/src/Form/Type/CalculatorChoiceType.php +++ b/src/Form/Type/CalculatorChoiceType.php @@ -11,7 +11,7 @@ final class CalculatorChoiceType extends AbstractType { /** - * @param array $calculators + * @param array $calculators */ public function __construct( private array $calculators, diff --git a/src/Model/PaymentMethodWithFeeTrait.php b/src/Model/PaymentMethodWithFeeTrait.php index 2b7ad1e..cd29360 100644 --- a/src/Model/PaymentMethodWithFeeTrait.php +++ b/src/Model/PaymentMethodWithFeeTrait.php @@ -15,6 +15,7 @@ trait PaymentMethodWithFeeTrait /** * @ORM\ManyToOne(targetEntity="Sylius\Component\Taxation\Model\TaxCategoryInterface") + * * @ORM\JoinColumn(name="tax_category_id") */ #[ORM\ManyToOne(targetEntity: TaxCategoryInterface::class)] diff --git a/src/Resources/views/Admin/_form.html.twig b/src/Resources/views/Admin/_form.html.twig index 098a095..4b8b7ac 100644 --- a/src/Resources/views/Admin/_form.html.twig +++ b/src/Resources/views/Admin/_form.html.twig @@ -5,7 +5,7 @@ {{ form_row(form.calculator) }} {% for name, calculatorConfigurationPrototype in form.vars.prototypes %}
+ data-prototype="{{ form_widget(calculatorConfigurationPrototype)|escape }}">
{% endfor %}
diff --git a/src/Resources/views/Admin/_order_show.html.twig b/src/Resources/views/Admin/_order_show.html.twig index 43784dd..ee41969 100644 --- a/src/Resources/views/Admin/_order_show.html.twig +++ b/src/Resources/views/Admin/_order_show.html.twig @@ -21,7 +21,7 @@ {{ 'threebrs.ui.payment_fee_total'|trans }}: - {{ money.format(order.getAdjustmentsTotal(paymentFeeAdjustment) ,order.currencyCode) }} + {{ money.format(order.getAdjustmentsTotal(paymentFeeAdjustment), order.currencyCode) }} {% endif %} From e674f6205d9748e078626531851adaff14a59abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Thu, 11 Jan 2024 09:00:25 +0100 Subject: [PATCH 08/12] Add Behat tests for checkout --- .circleci/config.yml | 3 +- Makefile | 20 ++--- docker-compose.yml | 11 ++- ...elect_payment_with_fee_on_checkout.feature | 51 +++++++++++ tests/Application/config/services_test.yaml | 1 + .../Context/Setup/PaymentMethodContext.php | 57 ++++++++++++ .../Admin/ManagingShippingMethodContext.php | 89 +++++++++++++++++++ .../Shop/Checkout/CheckoutCompleteContext.php | 44 +++++++++ .../Ui/Shop/ManagingZasilkovnaContext.php | 54 +++++++++++ .../ShippingMethod/UpdateShippingPage.php | 39 ++++++++ .../UpdateShippingPageInterface.php | 14 +++ .../Behat/Page/Shop/Checkout/CompletePage.php | 27 ++++++ .../Shop/Checkout/CompletePageInterface.php | 14 +++ .../Page/Shop/Zasilkovna/ZasilkovnaPages.php | 31 +++++++ .../Zasilkovna/ZasilkovnaPagesInterface.php | 14 +++ tests/Behat/Resources/services.yml | 20 +++++ tests/Behat/Resources/suites.yml | 3 + .../suites/admin_can_set_payment_fee.yml | 52 +++++++++++ .../select_payment_with_fee_on_checkout.yml | 58 ++++++++++++ tests/bootstrap.php | 11 +++ 20 files changed, 596 insertions(+), 17 deletions(-) create mode 100644 features/select_payment_with_fee_on_checkout.feature create mode 100644 tests/Behat/Context/Setup/PaymentMethodContext.php create mode 100644 tests/Behat/Context/Ui/Admin/ManagingShippingMethodContext.php create mode 100644 tests/Behat/Context/Ui/Shop/Checkout/CheckoutCompleteContext.php create mode 100644 tests/Behat/Context/Ui/Shop/ManagingZasilkovnaContext.php create mode 100644 tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPage.php create mode 100644 tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPageInterface.php create mode 100644 tests/Behat/Page/Shop/Checkout/CompletePage.php create mode 100644 tests/Behat/Page/Shop/Checkout/CompletePageInterface.php create mode 100644 tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPages.php create mode 100644 tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPagesInterface.php create mode 100644 tests/Behat/Resources/services.yml create mode 100644 tests/Behat/Resources/suites.yml create mode 100644 tests/Behat/Resources/suites/admin_can_set_payment_fee.yml create mode 100644 tests/Behat/Resources/suites/select_payment_with_fee_on_checkout.yml create mode 100644 tests/bootstrap.php diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d21e15..e106149 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -92,7 +92,8 @@ jobs: name: Behat environment: APP_SUPPRESS_DEPRECATED_ERRORS: 1 - command: APP_ENV=test bin/behat + # suppress deprecation errors like 'Function utf8_encode() is deprecated in vendor/egulias/email-validator/src/EmailLexer.php line 275' converted to fatal + command: APP_ENV=test php --define error_reporting=E_ALL^E_DEPRECATED bin/behat - run: APP_ENV=test bin/phpstan.sh - run: APP_ENV=test bin/ecs.sh --clear-cache - run: APP_ENV=test bin/symfony-lint.sh diff --git a/Makefile b/Makefile index cc035e1..d5b719f 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,31 @@ phpstan: - APP_ENV=test bin/phpstan.sh + bin/phpstan.sh ecs: - APP_ENV=test bin/ecs.sh + bin/ecs.sh behat-js: - APP_ENV=test APP_SUPPRESS_DEPRECATED_ERRORS=1 bin/behat --colors --strict --no-interaction -vvv -f progress + APP_SUPPRESS_DEPRECATED_ERRORS=1 bin/behat --colors --strict --no-interaction -vvv -f progress install: composer install --no-interaction --no-scripts backend: - APP_ENV=test tests/Application/bin/console doctrine:database:create --if-not-exists --no-interaction - APP_ENV=test tests/Application/bin/console doctrine:migrations:sync-metadata-storage --no-interaction - APP_ENV=test tests/Application/bin/console doctrine:schema:update --force --complete --no-interaction - APP_ENV=test tests/Application/bin/console sylius:install --no-interaction - APP_ENV=test tests/Application/bin/console sylius:fixtures:load default --no-interaction + bin/console doctrine:database:create --if-not-exists --no-interaction + bin/console doctrine:migrations:sync-metadata-storage --no-interaction + bin/console doctrine:schema:update --force --complete --no-interaction + bin/console sylius:install --no-interaction + bin/console sylius:fixtures:load default --no-interaction frontend: (cd tests/Application && yarn install --pure-lockfile) (cd tests/Application && GULP_ENV=prod yarn build) behat: - APP_ENV=test bin/behat --colors --strict --no-interaction -vvv -f progress + bin/behat --colors --strict --no-interaction -vvv -f progress lint: - APP_ENV=test bin/symfony-lint.sh + bin/symfony-lint.sh init: install backend frontend diff --git a/docker-compose.yml b/docker-compose.yml index c2ccd38..48107df 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ services: app: image: sylius/standard:1.11-traditional environment: - APP_ENV: "dev" + APP_ENV: "test" DATABASE_URL: "mysql://root:mysql@mysql/sylius_%kernel.environment%?charset=utf8mb4" # DATABASE_URL: "pgsql://root:postgres@postgres/sylius_%kernel.environment%?charset=utf8" # When using postgres PHP_DATE_TIMEZONE: "Europe/Prague" @@ -16,13 +16,12 @@ services: # XDEBUG_MODE: "profile" PHP_IDE_CONFIG: "serverName=3brsSyliusPaymentFeePlugin" volumes: - - ./:/app:delegated - - ./:/var/www:delegated - - ./.docker/nginx/nginx.conf:/etc/nginx/nginx.conf:delegated + - ./:/app + - ./.docker/nginx/nginx.conf:/etc/nginx/nginx.conf # - ./.docker/php/php.ini:/etc/php8/php.ini:delegated # - ./.docker/nginx/nginx.conf:/etc/nginx/nginx.conf:delegated ports: - - "${APP_HOST_MAPPING_PORT:-8080}:80" + - "${APP_HOST_MAPPING_PORT:-8080}:80" # http://localhost:8080 depends_on: - mysql # - postgres @@ -40,7 +39,7 @@ services: # - set MYSQL_HOST_MAPPING_PORT variable in .env file for example # - or extends ports in docker-compose.override.yml # To find out used port use `docker ps` and look for PORTS column to see mapped host port, including IP it can be for example 0.0.0.0:32772 which is roughly equivalent to 127.0.0.1:32772 for internal network requests - - "${MYSQL_HOST_MAPPING_PORT:-0}:3306" + - "${MYSQL_HOST_MAPPING_PORT:-32772}:3306" networks: - sylius diff --git a/features/select_payment_with_fee_on_checkout.feature b/features/select_payment_with_fee_on_checkout.feature new file mode 100644 index 0000000..edfa929 --- /dev/null +++ b/features/select_payment_with_fee_on_checkout.feature @@ -0,0 +1,51 @@ +@select_payment_with_fee_on_checkout +Feature: Selecting free of charge payment in checkout + In order to select shipping method without a fee to pay + As a Customer + I want to select free of charge shipping method and see in final checkout step that I don't have to pay for shipping + + Background: + Given the store operates on a channel named "3BRS Channel" + And the store operates in "Czechia" + And the store also has a zone "EU" with code "EU" + And this zone has the "Czechia" country member + And the store has a product "PHP T-Shirt" priced at "$19.99" + And the store has "DHL" shipping method with "$5" fee within the "EU" zone + And the store allows paying with "CSOB" + And the store allows paying with "Cash on delivery" + And the payment method "CSOB" is free of charge + And the payment method "Cash on delivery" is charged for "$2" + + @ui + Scenario: Complete order with free of charge payment method + When I add "PHP T-Shirt" product to the cart + Then my cart's total should be "$19.99" + When I complete addressing step with email "john@example.com" and "Czechia" based billing address + Then I should be on the checkout shipping step + When I select "DHL" shipping method + And I complete the shipping step + And I select "CSOB" payment method + And I complete the payment step + Then I should be on the checkout complete step + And my order shipping should be "$5.00" + And I should not see payment fee total + And my order total should be "$24.99" + When I confirm my order + Then I should see the thank you page + + @ui + Scenario: Complete order with charged payment method + When I add "PHP T-Shirt" product to the cart + Then my cart's total should be "$19.99" + When I complete addressing step with email "john@example.com" and "Czechia" based billing address + Then I should be on the checkout shipping step + When I select "DHL" shipping method + And I complete the shipping step + And I select "Cash on delivery" payment method + And I complete the payment step + Then I should be on the checkout complete step + And my order shipping should be "$5.00" + And my order payment fee should be "$2.00" + And my order total should be "$26.99" + When I confirm my order + Then I should see the thank you page diff --git a/tests/Application/config/services_test.yaml b/tests/Application/config/services_test.yaml index 898899e..9edf553 100644 --- a/tests/Application/config/services_test.yaml +++ b/tests/Application/config/services_test.yaml @@ -1,4 +1,5 @@ imports: + - { resource: "../../Behat/Resources/services.yml" } - { resource: "../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml" } # workaround needed for strange "test.client.history" problem diff --git a/tests/Behat/Context/Setup/PaymentMethodContext.php b/tests/Behat/Context/Setup/PaymentMethodContext.php new file mode 100644 index 0000000..3ba731c --- /dev/null +++ b/tests/Behat/Context/Setup/PaymentMethodContext.php @@ -0,0 +1,57 @@ +[^"]+)" is free of charge$/ + */ + public function thePaymentMethodIsFreeOfCharge(PaymentMethodWithFeeInterface $paymentMethod): void + { + $paymentMethod->setCalculator(null); + $paymentMethod->setCalculatorConfiguration([]); + + $this->entityManager->persist($paymentMethod); + $this->entityManager->flush(); + } + + /** + * @Given /^(?:the )?payment method "(?P[^"]+)" is charged for (?P"[^"]+")$/ + */ + public function thisPaymentMethodIsChargedForPrice(PaymentMethodInterface $paymentMethod, int $price): void + { + assert($paymentMethod instanceof PaymentMethodWithFeeInterface); + + $paymentMethod->setCalculator((new FlatRateCalculator())->getType()); + $paymentMethod->setCalculatorConfiguration([$this->getChannel()->getCode() => ['amount' => $price]]); + + $this->entityManager->persist($paymentMethod); + $this->entityManager->flush(); + } + + private function getChannel(): ChannelInterface + { + $channel = $this->sharedStorage->get('channel'); + + assert($channel instanceof ChannelInterface); + + return $channel; + } +} diff --git a/tests/Behat/Context/Ui/Admin/ManagingShippingMethodContext.php b/tests/Behat/Context/Ui/Admin/ManagingShippingMethodContext.php new file mode 100644 index 0000000..30edfcb --- /dev/null +++ b/tests/Behat/Context/Ui/Admin/ManagingShippingMethodContext.php @@ -0,0 +1,89 @@ +updatePage->changeInput(UpdateShippingPage::AMOUNT_INPUT, ''); + } + + /** + * @Then /^(this payment method) should be free of charge$/ + */ + public function paymentMethodShouldBeFreeOfCharge(PaymentMethodInterface $paymentMethod): void + { + Assert::same($this->updatePage->getInputValue(), ''); + } + + /** + * @When /^I set charge for (this payment method) to :amount $/ + */ + public function iSetChargeForPaymentMethodToAmount(PaymentMethodInterface $paymentMethod, float $amount): void + { + $this->updatePage->changeInput(UpdateShippingPage::AMOUNT_INPUT, (string) $amount); + } + + /** + * @Then /^(this payment method) should be free of charge$/ + */ + public function paymentMethodShouldFeeShouldBeSetTo(PaymentMethodInterface $paymentMethod, float $amount): void + { + Assert::same($this->updatePage->getInputValue(), (string) $amount); + } + + /** + * @Then the Zásilkovna Carrier pickup point for this shipping method should be :arg1 + */ + public function theZasilkovnaCarrierIdForThisShippingMethodShouldBe($arg1) + { + Assert::eq($this->updatePage->isSingleResourceOnPage('carrierId'), $arg1); + } + + /** + * @When I change Zásilkovna api key to :apiKey + */ + public function iChangeZasilkovnaApiKeyTo(string $apiKey) + { + $this->updatePage->changeApiKey($apiKey); + } + + /** + * @Then the Zásilkovna api key for this shipping method should be :apiKey + */ + public function theZasilkovnaApiKeyForThisShippingMethodShouldBe(string $apiKey) + { + Assert::eq($this->updatePage->isSingleResourceOnPage('apiKey'), $apiKey); + } + + /** + * @Then it should be shipped to Zásilkovna branch + */ + public function itShouldBeShippedToZasilkovnaBranch() + { + Assert::true($this->updatePage->iSeeZasilkovnaBranchInsteadOfShippingAddress()); + } +} diff --git a/tests/Behat/Context/Ui/Shop/Checkout/CheckoutCompleteContext.php b/tests/Behat/Context/Ui/Shop/Checkout/CheckoutCompleteContext.php new file mode 100644 index 0000000..28bf5cb --- /dev/null +++ b/tests/Behat/Context/Ui/Shop/Checkout/CheckoutCompleteContext.php @@ -0,0 +1,44 @@ +completePage->getPaymentFeeTotal(), $price); + } + + /** + * @Then I should see payment fee total + */ + public function iShouldSeePaymentFeeTotal(): void + { + Assert::true($this->completePage->hasPaymentFeeTotal()); + } + + /** + * @Then I should not see payment fee total + */ + public function iShouldNotSeePaymentFeeTotal(): void + { + Assert::false($this->completePage->hasPaymentFeeTotal()); + } +} diff --git a/tests/Behat/Context/Ui/Shop/ManagingZasilkovnaContext.php b/tests/Behat/Context/Ui/Shop/ManagingZasilkovnaContext.php new file mode 100644 index 0000000..e185d58 --- /dev/null +++ b/tests/Behat/Context/Ui/Shop/ManagingZasilkovnaContext.php @@ -0,0 +1,54 @@ +zasilkovnaPages = $zasilkovnaPages; + $this->checkoutShippingContext = $checkoutShippingContext; + } + + /** + * @Then I should not be able to go to the payment step again + */ + public function iShouldNotBeAbleToGoToThePaymentStepAgain() + { + Assert::throws(function () { + $this->checkoutShippingContext->iShouldBeAbleToGoToThePaymentStepAgain(); + }, UnexpectedPageException::class); + } + + /** + * @Then I select :zasilkovnaName Zásilkovna branch + */ + public function iSelectZasilkovnaBranch(string $zasilkovnaName) + { + $this->zasilkovnaPages->selectZasilkovnaBranch(['id' => 1, 'place' => $zasilkovnaName]); + } + + /** + * @Given I see Zásilkovna branch instead of shipping address + */ + public function iSeeZasilkovnaBranchInsteadOfShippingAddress() + { + Assert::true($this->zasilkovnaPages->iSeeZasilkovnaBranchInsteadOfShippingAddress()); + } +} diff --git a/tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPage.php b/tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPage.php new file mode 100644 index 0000000..8e805c8 --- /dev/null +++ b/tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPage.php @@ -0,0 +1,39 @@ +getElement($elementName)->setValue($value); + } + + public function iSeeZasilkovnaBranchInsteadOfShippingAddress(): bool + { + $shippingAddress = $this->getElement('shippingAddress')->getText(); + + return false !== strpos($shippingAddress, 'Zásilkovna branch'); + } + + public function getInputValue(): array|bool|string + { + return $this->getElement(self::AMOUNT_INPUT)->getValue(); + } + + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + self::AMOUNT_INPUT => $this->isAvailableInChannel(), + 'senderLabel' => '#sylius_shipping_method_zasilkovnaConfig_senderLabel', + 'carrierId' => '#sylius_shipping_method_zasilkovnaConfig_carrierId', + 'shippingAddress' => '#shipping-address', + ]); + } +} diff --git a/tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPageInterface.php b/tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPageInterface.php new file mode 100644 index 0000000..f95f2fb --- /dev/null +++ b/tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPageInterface.php @@ -0,0 +1,14 @@ +getElement('payment_fee_total')->getText(); + } + + public function hasPaymentFeeTotal(): bool + { + return $this->hasElement('payment_fee_total'); + } + + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + 'payment_fee_total' => '[data-test-payment-fee-total]', + ]); + } +} diff --git a/tests/Behat/Page/Shop/Checkout/CompletePageInterface.php b/tests/Behat/Page/Shop/Checkout/CompletePageInterface.php new file mode 100644 index 0000000..9104e8a --- /dev/null +++ b/tests/Behat/Page/Shop/Checkout/CompletePageInterface.php @@ -0,0 +1,14 @@ +getElement('zasilkovna_hidden_input'); + $zasilkovnaSelect->setValue(json_encode($zasilkovna)); + } + + public function iSeeZasilkovnaBranchInsteadOfShippingAddress(): bool + { + $shippingAddress = $this->getElement('shippingAddress')->getText(); + + return false !== strpos($shippingAddress, 'Zásilkovna branch'); + } + + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + 'zasilkovna_hidden_input' => 'input[type="hidden"][name^="sylius_checkout_select_shipping[shipments][0][zasilkovna_"]', + 'shippingAddress' => '#sylius-shipping-address', + ]); + } +} diff --git a/tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPagesInterface.php b/tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPagesInterface.php new file mode 100644 index 0000000..494f170 --- /dev/null +++ b/tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPagesInterface.php @@ -0,0 +1,14 @@ +bootEnv(dirname(__DIR__).'/.env'); +} From f910b8fca2ffe0a10b7a5dcbbb2d94dd0760a9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Wed, 17 Jan 2024 08:41:25 +0100 Subject: [PATCH 09/12] Use https for local development --- .docker/nginx/nginx-selfsigned.crt | 22 ++++++++++++++++++++++ .docker/nginx/nginx-selfsigned.key | 28 ++++++++++++++++++++++++++++ .docker/nginx/nginx.conf | 12 +++++++++++- docker-compose.yml | 8 ++++---- 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 .docker/nginx/nginx-selfsigned.crt create mode 100644 .docker/nginx/nginx-selfsigned.key diff --git a/.docker/nginx/nginx-selfsigned.crt b/.docker/nginx/nginx-selfsigned.crt new file mode 100644 index 0000000..52595ea --- /dev/null +++ b/.docker/nginx/nginx-selfsigned.crt @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDrTCCApWgAwIBAgIUKCa3obUEwPsaJOUUOkCRU/jmHqwwDQYJKoZIhvcNAQEL +BQAwZjELMAkGA1UEBhMCQ1oxEzARBgNVBAgMClNvbWUtU3RhdGUxDzANBgNVBAcM +BlByYWd1ZTERMA8GA1UECgwIM2Jycy5jb20xCzAJBgNVBAsMAklUMREwDwYDVQQD +DAgzYnJzLmNvbTAeFw0yNDAxMTEyMTE3NDhaFw0yNTAxMTAyMTE3NDhaMGYxCzAJ +BgNVBAYTAkNaMRMwEQYDVQQIDApTb21lLVN0YXRlMQ8wDQYDVQQHDAZQcmFndWUx +ETAPBgNVBAoMCDNicnMuY29tMQswCQYDVQQLDAJJVDERMA8GA1UEAwwIM2Jycy5j +b20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC8dCTNfrLtrpEyIR2f +XgcsQko4uEgP9fIdhe7sCz1cH2jx3KvLsa/IzElAtEqRXPOiVNt972zoi4+fw4A1 +QBRWHg7IL1JkmfrbemhmkJHWv3+4h1FGvlyslNULSdtp/s00jSfCxqYd5fspu0hH +U5CcOvFg5Jh/YU54aBazIh42cJXxIBsv8TKkYMk1HlA6dZF/KMdzTy+Umu5sF9+r +X9sPB9m7xWbyyq5T1gKacE6CdCd0hy9IpdHpCCwY3cWvkBHBUM7FGvSl8OZyxRQX +nxkFXw6J0JP8Ns0g/q1nyvFTJbED8EVIyWP7MUKD+mocq/qGEoBmLidtZ89dcK1Z +UpzPAgMBAAGjUzBRMB0GA1UdDgQWBBSw6/8l/Q97IdML1lrNB7qY9MW/nTAfBgNV +HSMEGDAWgBSw6/8l/Q97IdML1lrNB7qY9MW/nTAPBgNVHRMBAf8EBTADAQH/MA0G +CSqGSIb3DQEBCwUAA4IBAQAXCwTa22HpSBJuEgbyKK1oBllEL6VCuDj6TvpUOMZC +TGMnUkMwBnS8/NzQ/qfVPix+x3qqDe4HzCrNYBO0LeaUp5yk93qAMgCXeJugGSIg +oAsBHvmVurCfmtVruLf/y8Df/IetKvcVmAAj0wt32gtB6TlpKkQPZdoLNvmEWIpm +2MC/OzTYGCPp6vry5JnIPZXOcuQjHgKhEPU7YeN5nIvvP27NfhXCXTubpag/7spp +7fq5hiSgZHsYAh9OIxdAfou1I8rbIenn8zElbOvc6bwU0drMykmAVMvpu55ctWGk +/cRl1D8UbcsDWUpiucnaMv3v64vA/9BlFx3mh1ORNDh/ +-----END CERTIFICATE----- diff --git a/.docker/nginx/nginx-selfsigned.key b/.docker/nginx/nginx-selfsigned.key new file mode 100644 index 0000000..80c76d6 --- /dev/null +++ b/.docker/nginx/nginx-selfsigned.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC8dCTNfrLtrpEy +IR2fXgcsQko4uEgP9fIdhe7sCz1cH2jx3KvLsa/IzElAtEqRXPOiVNt972zoi4+f +w4A1QBRWHg7IL1JkmfrbemhmkJHWv3+4h1FGvlyslNULSdtp/s00jSfCxqYd5fsp +u0hHU5CcOvFg5Jh/YU54aBazIh42cJXxIBsv8TKkYMk1HlA6dZF/KMdzTy+Umu5s +F9+rX9sPB9m7xWbyyq5T1gKacE6CdCd0hy9IpdHpCCwY3cWvkBHBUM7FGvSl8OZy +xRQXnxkFXw6J0JP8Ns0g/q1nyvFTJbED8EVIyWP7MUKD+mocq/qGEoBmLidtZ89d +cK1ZUpzPAgMBAAECggEAAW+RQkuNbVyk2I5Ub2hyHFhBRY1HUsv3rDsce1a252fw +QhKvqLdHqAWiRZA2P8pRJinp0/Vx339hCCe+AMN1yAugvcONk26Qa84k6Ek40Ag/ +KRGYyKZwfCicDc5naOBUtMuscYTH8JWn8kUCf6/7LuqosIrRKp/spgyuQI3xEljb +vae+py33fWCFJE3z9jqvlcGKMM9pAdM2DqrlVXW+QbeFZ3u3zzFkgjYAnHjqBktb +ZmhgNn0gRjKOpQ1AUNfkXqYj0bHIVeFNWUYPisHb5P+oTa0Ohp+sP2nSCdYv3tlk +16t5ihQpJOxQdL4ZKAfLzzAaYWki4MfjmhK1gA1myQKBgQDbmjULEeKRB78uKykc +X1LCvDwG1yaQzZqu+0x3FM2oK8JG1RUL3EOr4nuWymBfim0XHySsUeNydqise9VD +XwKaFV2dpUfntdCPeJiBsPAXsua5y8VpDYnfoiZQ1+IBSGrBSkor4UctvKt7BAlx +8BNJt3/Xv86QJcr7UY1Ffd7oHQKBgQDbsEnq/vUAfVoIntZoHoVcfZCORKvsYbP/ +jyZW/pvxFpLJFKqbbQdWPHfMLpnR4mF0iFv6wiWWpvWtN+aQiie93AFZMxnZVBqA +MKNi9QdD3HjFWCPL9cWaZPMjipsYpkUiFJUNblkU7/0F2wpOtolPUhLJq7pFuKtB +FfZeYcR82wKBgGwWVZ9SOUMLHhVaVwzI+lIxFhaD1U6WdFlGBVfjXGo2x5PXk1lY +G9LBUfVhPNgpqRIlWQab86hGMTVcahaT8BLpCz/ptx+cRMApKl9DOJlhi+DNJChV +6pOxGszVxT6+ZxUmPKWmZ0NixsBwtzlmYgf5kqodlU0r3OGgPTmD/7AdAoGAHsXG +1N/5uaPVZLe7GMKNs7Ly+LqtymK1L+sBV9Y6Sb77uKbobvUKvg2iSjuM2FV5iTVA +jRN86GliqGzYIw73GiUjGzeJO2QIgkRN3qKr7dmIITyDZyJ6F3JkjGnx57YCoQ95 +AXSfjctACf3wp63x9eZtM0qWwQVpF6jX5ciUGVkCgYEAm0uEuFPeT68nkg4xQIEr +EwtPcqU6Q9PpFCYjGdiTQGIo22z48NYAZcTri+YI4PscHsPZytP/E70U49dbv+7R +sziWeQ5JvRH3Ske46OC0IGGOA/XRkeFb8HsaiVttqy6jEXcCw8FoXdQUQg0b3nN+ +fETGdtkVPcHxPpcV3Ws2600= +-----END PRIVATE KEY----- diff --git a/.docker/nginx/nginx.conf b/.docker/nginx/nginx.conf index 2150ac7..8b825a6 100644 --- a/.docker/nginx/nginx.conf +++ b/.docker/nginx/nginx.conf @@ -25,8 +25,18 @@ http { access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; - server { + server { + # Listen 80: This instructs the system to catch all HTTP traffic on Port 80 listen 80; + # Server_name _;: This will match any hostname + server_name _; + return 301 https://$host$request_uri; + } + + server { + listen 443 ssl; + ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt; + ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key; server_name sylius_plugin_docker; diff --git a/docker-compose.yml b/docker-compose.yml index 48107df..c71bbce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: YARN_CACHE_FOLDER: "/tmp" HOME: "/tmp" XDEBUG_CONFIG: "client_host=172.17.0.1 client_port=9003 remote_log=/tmp/xdebug.log" - XDEBUG_TRIGGER: "yes" # to start XDebug for EVERY request (use `export XDEBUG_TRIGGER: "yes"` to enable it in CLI and `unset XDEBUG_TRIGGER` to disable for CLI again - in browser use same-named variable in GET, POST or COOKIE, or legacy named via some browser extension). For a single shot can be used inline environment variable like `XDEBUG_TRIGGER=yes ./bin/console + XDEBUG_TRIGGER: "yes" # to start XDebug for EVERY request (use `export XDEBUG_TRIGGER: "yes"` to enable it in CLI and `unset XDEBUG_TRIGGER` to disable for CLI again - in browser use same-named variable in GET, POST or COOKIE, or legacy XDEBUG_SESSION via some browser extension). For a single shot can be used inline environment variable like `XDEBUG_TRIGGER=yes ./bin/console # XDEBUG_MODE: "off" XDEBUG_MODE: "debug" # XDEBUG_MODE: "profile" @@ -18,10 +18,10 @@ services: volumes: - ./:/app - ./.docker/nginx/nginx.conf:/etc/nginx/nginx.conf -# - ./.docker/php/php.ini:/etc/php8/php.ini:delegated -# - ./.docker/nginx/nginx.conf:/etc/nginx/nginx.conf:delegated + - ./.docker/nginx/nginx-selfsigned.crt:/etc/nginx/ssl/nginx-selfsigned.crt + - ./.docker/nginx/nginx-selfsigned.key:/etc/nginx/ssl/nginx-selfsigned.key ports: - - "${APP_HOST_MAPPING_PORT:-8080}:80" # http://localhost:8080 + - "${APP_HOST_MAPPING_PORT:-8080}:443" # https://localhost:8080 for Nginx depends_on: - mysql # - postgres From 2bbcb187ff7e44bb6caa67fa687fb589399f7843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Wed, 17 Jan 2024 08:42:33 +0100 Subject: [PATCH 10/12] Fix app installation commands via make --- Makefile | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index d5b719f..54e2b10 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,47 @@ phpstan: + bin/console cache:warmup bin/phpstan.sh ecs: bin/ecs.sh behat-js: - APP_SUPPRESS_DEPRECATED_ERRORS=1 bin/behat --colors --strict --no-interaction -vvv -f progress + bin/behat-js --colors --strict --no-interaction -vvv -f progress --tags="@javascript" + +behat-no-js: + bin/behat --colors --strict --no-interaction -vvv -f progress --tags="~@javascript" + +behat: behat-no-js behat-js install: composer install --no-interaction --no-scripts +backend-bare: + bin/console doctrine:database:create --if-not-exists --no-interaction + bin/console doctrine:migrations:sync-metadata-storage --no-interaction + bin/console doctrine:schema:update --force --complete --no-interaction + backend: bin/console doctrine:database:create --if-not-exists --no-interaction + bin/console sylius:install --no-interaction # create schema and fixtures + # requires update of database schema due to plugin entities bin/console doctrine:migrations:sync-metadata-storage --no-interaction bin/console doctrine:schema:update --force --complete --no-interaction - bin/console sylius:install --no-interaction bin/console sylius:fixtures:load default --no-interaction frontend: (cd tests/Application && yarn install --pure-lockfile) (cd tests/Application && GULP_ENV=prod yarn build) -behat: - bin/behat --colors --strict --no-interaction -vvv -f progress - lint: bin/symfony-lint.sh init: install backend frontend -ci: init phpstan ecs behat lint +init-integration: install backend-bare frontend -integration: init behat +integration: init-integration behat static: install phpstan ecs lint + +ci: static integration From fc30661024c2f29349988a94231fcfd171705101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20T=C3=BDc?= Date: Wed, 17 Jan 2024 08:42:44 +0100 Subject: [PATCH 11/12] Add admin Behat tests --- ...elect_payment_with_fee_on_checkout.feature | 9 +- features/set_fee_to_payment_in_admin.feature | 45 ++++++++++ tests/Application/.env | 2 +- .../Admin/ManagingPaymentMethodsContext.php | 70 +++++++++++++++ .../Admin/ManagingShippingMethodContext.php | 89 ------------------- .../Ui/Shop/ManagingZasilkovnaContext.php | 54 ----------- .../Admin/PaymentMethod/UpdatePaymentPage.php | 36 ++++++++ .../UpdatePaymentPageInterface.php | 15 ++++ .../ShippingMethod/UpdateShippingPage.php | 39 -------- .../UpdateShippingPageInterface.php | 14 --- .../Page/Shop/Zasilkovna/ZasilkovnaPages.php | 31 ------- .../Zasilkovna/ZasilkovnaPagesInterface.php | 14 --- tests/Behat/Resources/services.yml | 9 +- tests/Behat/Resources/suites.yml | 3 +- .../select_payment_with_fee_on_checkout.yml | 2 +- ...ee.yml => set_fee_to_payment_in_admin.yml} | 12 +-- 16 files changed, 190 insertions(+), 254 deletions(-) create mode 100644 features/set_fee_to_payment_in_admin.feature create mode 100644 tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php delete mode 100644 tests/Behat/Context/Ui/Admin/ManagingShippingMethodContext.php delete mode 100644 tests/Behat/Context/Ui/Shop/ManagingZasilkovnaContext.php create mode 100644 tests/Behat/Page/Admin/PaymentMethod/UpdatePaymentPage.php create mode 100644 tests/Behat/Page/Admin/PaymentMethod/UpdatePaymentPageInterface.php delete mode 100644 tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPage.php delete mode 100644 tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPageInterface.php delete mode 100644 tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPages.php delete mode 100644 tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPagesInterface.php rename tests/Behat/Resources/suites/{admin_can_set_payment_fee.yml => set_fee_to_payment_in_admin.yml} (85%) diff --git a/features/select_payment_with_fee_on_checkout.feature b/features/select_payment_with_fee_on_checkout.feature index edfa929..acf23ac 100644 --- a/features/select_payment_with_fee_on_checkout.feature +++ b/features/select_payment_with_fee_on_checkout.feature @@ -1,8 +1,8 @@ @select_payment_with_fee_on_checkout -Feature: Selecting free of charge payment in checkout - In order to select shipping method without a fee to pay +Feature: Selecting charged payment in checkout + In order to payment method with or without fee to pay As a Customer - I want to select free of charge shipping method and see in final checkout step that I don't have to pay for shipping + I want to select payment method and see in final checkout step if I have to pay for that payment method Background: Given the store operates on a channel named "3BRS Channel" @@ -24,6 +24,7 @@ Feature: Selecting free of charge payment in checkout Then I should be on the checkout shipping step When I select "DHL" shipping method And I complete the shipping step + Then I should be on the checkout payment step And I select "CSOB" payment method And I complete the payment step Then I should be on the checkout complete step @@ -41,10 +42,12 @@ Feature: Selecting free of charge payment in checkout Then I should be on the checkout shipping step When I select "DHL" shipping method And I complete the shipping step + Then I should be on the checkout payment step And I select "Cash on delivery" payment method And I complete the payment step Then I should be on the checkout complete step And my order shipping should be "$5.00" + And I should see payment fee total And my order payment fee should be "$2.00" And my order total should be "$26.99" When I confirm my order diff --git a/features/set_fee_to_payment_in_admin.feature b/features/set_fee_to_payment_in_admin.feature new file mode 100644 index 0000000..5f167a1 --- /dev/null +++ b/features/set_fee_to_payment_in_admin.feature @@ -0,0 +1,45 @@ +@set_fee_to_payment_in_admin +Feature: Admin can set fee to a payment method in admin panel + In order to charge payment method + As an Administrator + I want to set a fee to a payment method and see that the fee was set in admin panel + + Background: + Given the store operates on a single channel in "United States" + And the store has a product "Angel T-Shirt" + And the store allows paying with "UPS" + And the store also allows paying with "Cash on Delivery" + + @ui + Scenario: Set fee to a payment method in admin panel + When I am logged in as an administrator + And I browse payment methods + Then I should see the payment method "UPS" in the list + And I should see the payment method "Cash on Delivery" in the list + + When I want to modify the "Cash on Delivery" payment method + Then I should see that payment method "Cash on Delivery" has no fee + + When I want to modify the "Cash on Delivery" payment method + And I set fee "2.00" to "Cash on Delivery" payment method + Then I should see that payment method "Cash on Delivery" has fee "2.00" + And I want to modify the "UPS" payment method + And I should see that payment method "UPS" has no fee + + When I want to modify the "Cash on Delivery" payment method + And I set fee "0.00" to "Cash on Delivery" payment method + Then I should see that payment method "Cash on Delivery" has no fee + And I want to modify the "UPS" payment method + And I should see that payment method "UPS" has no fee + + When I want to modify the "Cash on Delivery" payment method + And I set fee "999.00" to "Cash on Delivery" payment method + Then I should see that payment method "Cash on Delivery" has fee "999.00" + And I want to modify the "UPS" payment method + And I should see that payment method "UPS" has no fee + + When I want to modify the "Cash on Delivery" payment method + And I remove fee from "Cash on Delivery" payment method + Then I should see that payment method "Cash on Delivery" has no fee + And I want to modify the "UPS" payment method + And I should see that payment method "UPS" has no fee diff --git a/tests/Application/.env b/tests/Application/.env index c896d17..2480c08 100644 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -12,7 +12,7 @@ APP_SECRET=EDITME # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls -DATABASE_URL=mysql://root@127.0.0.1/threebrs_sylius_payment_fee_plugin_%kernel.environment%?serverVersion=5.7 +DATABASE_URL='mysql://root:mysql@mysql/sylius_%kernel.environment%?charset=utf8mb4' ###< doctrine/doctrine-bundle ### ###> lexik/jwt-authentication-bundle ### diff --git a/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php b/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php new file mode 100644 index 0000000..f9ab295 --- /dev/null +++ b/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php @@ -0,0 +1,70 @@ +updatePaymentPage->changeAmount('', $this->getChannel()); + } + + /** + * @Then I should see that payment method :paymentMethod has no fee + */ + public function paymentMethodShouldBeFreeOfCharge(PaymentMethodInterface $paymentMethod): void + { + try { + Assert::oneOf($this->updatePaymentPage->getAmount($this->getChannel()), ['0', '0.00', '0,00']); + } catch (ElementNotFoundException) { + Assert::true(true, 'Amount input should be hidden when empty'); + } + } + + /** + * @When I set fee :amount to :paymentMethod payment method + */ + public function iSetChargeForPaymentMethodToAmount(string $amount, PaymentMethodInterface $paymentMethod): void + { + $this->updatePaymentPage->changeAmount($amount, $this->getChannel()); + } + + /** + * @Then I should see that payment method :paymentMethod has fee :amount + */ + public function paymentMethodShouldFeeShouldBeSetTo(PaymentMethodInterface $paymentMethod, string $amount): void + { + Assert::same($this->updatePaymentPage->getAmount($this->getChannel()), $amount,); + } + + private function getChannel(): ChannelInterface + { + $channel = $this->sharedStorage->get('channel'); + + assert($channel instanceof ChannelInterface); + + return $channel; + } +} diff --git a/tests/Behat/Context/Ui/Admin/ManagingShippingMethodContext.php b/tests/Behat/Context/Ui/Admin/ManagingShippingMethodContext.php deleted file mode 100644 index 30edfcb..0000000 --- a/tests/Behat/Context/Ui/Admin/ManagingShippingMethodContext.php +++ /dev/null @@ -1,89 +0,0 @@ -updatePage->changeInput(UpdateShippingPage::AMOUNT_INPUT, ''); - } - - /** - * @Then /^(this payment method) should be free of charge$/ - */ - public function paymentMethodShouldBeFreeOfCharge(PaymentMethodInterface $paymentMethod): void - { - Assert::same($this->updatePage->getInputValue(), ''); - } - - /** - * @When /^I set charge for (this payment method) to :amount $/ - */ - public function iSetChargeForPaymentMethodToAmount(PaymentMethodInterface $paymentMethod, float $amount): void - { - $this->updatePage->changeInput(UpdateShippingPage::AMOUNT_INPUT, (string) $amount); - } - - /** - * @Then /^(this payment method) should be free of charge$/ - */ - public function paymentMethodShouldFeeShouldBeSetTo(PaymentMethodInterface $paymentMethod, float $amount): void - { - Assert::same($this->updatePage->getInputValue(), (string) $amount); - } - - /** - * @Then the Zásilkovna Carrier pickup point for this shipping method should be :arg1 - */ - public function theZasilkovnaCarrierIdForThisShippingMethodShouldBe($arg1) - { - Assert::eq($this->updatePage->isSingleResourceOnPage('carrierId'), $arg1); - } - - /** - * @When I change Zásilkovna api key to :apiKey - */ - public function iChangeZasilkovnaApiKeyTo(string $apiKey) - { - $this->updatePage->changeApiKey($apiKey); - } - - /** - * @Then the Zásilkovna api key for this shipping method should be :apiKey - */ - public function theZasilkovnaApiKeyForThisShippingMethodShouldBe(string $apiKey) - { - Assert::eq($this->updatePage->isSingleResourceOnPage('apiKey'), $apiKey); - } - - /** - * @Then it should be shipped to Zásilkovna branch - */ - public function itShouldBeShippedToZasilkovnaBranch() - { - Assert::true($this->updatePage->iSeeZasilkovnaBranchInsteadOfShippingAddress()); - } -} diff --git a/tests/Behat/Context/Ui/Shop/ManagingZasilkovnaContext.php b/tests/Behat/Context/Ui/Shop/ManagingZasilkovnaContext.php deleted file mode 100644 index e185d58..0000000 --- a/tests/Behat/Context/Ui/Shop/ManagingZasilkovnaContext.php +++ /dev/null @@ -1,54 +0,0 @@ -zasilkovnaPages = $zasilkovnaPages; - $this->checkoutShippingContext = $checkoutShippingContext; - } - - /** - * @Then I should not be able to go to the payment step again - */ - public function iShouldNotBeAbleToGoToThePaymentStepAgain() - { - Assert::throws(function () { - $this->checkoutShippingContext->iShouldBeAbleToGoToThePaymentStepAgain(); - }, UnexpectedPageException::class); - } - - /** - * @Then I select :zasilkovnaName Zásilkovna branch - */ - public function iSelectZasilkovnaBranch(string $zasilkovnaName) - { - $this->zasilkovnaPages->selectZasilkovnaBranch(['id' => 1, 'place' => $zasilkovnaName]); - } - - /** - * @Given I see Zásilkovna branch instead of shipping address - */ - public function iSeeZasilkovnaBranchInsteadOfShippingAddress() - { - Assert::true($this->zasilkovnaPages->iSeeZasilkovnaBranchInsteadOfShippingAddress()); - } -} diff --git a/tests/Behat/Page/Admin/PaymentMethod/UpdatePaymentPage.php b/tests/Behat/Page/Admin/PaymentMethod/UpdatePaymentPage.php new file mode 100644 index 0000000..70c0ff5 --- /dev/null +++ b/tests/Behat/Page/Admin/PaymentMethod/UpdatePaymentPage.php @@ -0,0 +1,36 @@ +getAmountElement($channel->getCode())->setValue($value); + } + + public function getAmount(ChannelInterface $channel): array|bool|string + { + return $this->getAmountElement($channel->getCode())->getValue(); + } + + private function getAmountElement(string $channelCode): NodeElement + { + return $this->getElement(self::AMOUNT_INPUT, ['%channel%' => $channelCode]); + } + + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + self::AMOUNT_INPUT => '#sylius_payment_method_calculatorConfiguration_%channel%_amount', + ]); + } +} diff --git a/tests/Behat/Page/Admin/PaymentMethod/UpdatePaymentPageInterface.php b/tests/Behat/Page/Admin/PaymentMethod/UpdatePaymentPageInterface.php new file mode 100644 index 0000000..da23a31 --- /dev/null +++ b/tests/Behat/Page/Admin/PaymentMethod/UpdatePaymentPageInterface.php @@ -0,0 +1,15 @@ +getElement($elementName)->setValue($value); - } - - public function iSeeZasilkovnaBranchInsteadOfShippingAddress(): bool - { - $shippingAddress = $this->getElement('shippingAddress')->getText(); - - return false !== strpos($shippingAddress, 'Zásilkovna branch'); - } - - public function getInputValue(): array|bool|string - { - return $this->getElement(self::AMOUNT_INPUT)->getValue(); - } - - protected function getDefinedElements(): array - { - return array_merge(parent::getDefinedElements(), [ - self::AMOUNT_INPUT => $this->isAvailableInChannel(), - 'senderLabel' => '#sylius_shipping_method_zasilkovnaConfig_senderLabel', - 'carrierId' => '#sylius_shipping_method_zasilkovnaConfig_carrierId', - 'shippingAddress' => '#shipping-address', - ]); - } -} diff --git a/tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPageInterface.php b/tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPageInterface.php deleted file mode 100644 index f95f2fb..0000000 --- a/tests/Behat/Page/Admin/ShippingMethod/UpdateShippingPageInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -getElement('zasilkovna_hidden_input'); - $zasilkovnaSelect->setValue(json_encode($zasilkovna)); - } - - public function iSeeZasilkovnaBranchInsteadOfShippingAddress(): bool - { - $shippingAddress = $this->getElement('shippingAddress')->getText(); - - return false !== strpos($shippingAddress, 'Zásilkovna branch'); - } - - protected function getDefinedElements(): array - { - return array_merge(parent::getDefinedElements(), [ - 'zasilkovna_hidden_input' => 'input[type="hidden"][name^="sylius_checkout_select_shipping[shipments][0][zasilkovna_"]', - 'shippingAddress' => '#sylius-shipping-address', - ]); - } -} diff --git a/tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPagesInterface.php b/tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPagesInterface.php deleted file mode 100644 index 494f170..0000000 --- a/tests/Behat/Page/Shop/Zasilkovna/ZasilkovnaPagesInterface.php +++ /dev/null @@ -1,14 +0,0 @@ - Date: Wed, 17 Jan 2024 16:04:34 +0100 Subject: [PATCH 12/12] Remove Behat admin tests because they require not-yet-working JS --- Makefile | 5 +--- README.md | 5 ++++ features/set_fee_to_payment_in_admin.feature | 27 +------------------- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 54e2b10..600d532 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,10 @@ phpstan: ecs: bin/ecs.sh -behat-js: - bin/behat-js --colors --strict --no-interaction -vvv -f progress --tags="@javascript" - behat-no-js: bin/behat --colors --strict --no-interaction -vvv -f progress --tags="~@javascript" -behat: behat-no-js behat-js +behat: behat-no-js install: composer install --no-interaction --no-scripts diff --git a/README.md b/README.md index 820da60..81c382e 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,11 @@ bin/ecs.sh vendor/bin/phpspec run ``` +#### Behat Debugging +- use `-vvv` for verbose output `bin/behat -vvv` +- see `etc/build/*.html` for output detail +- check `tests/Application/var/log/test.log` for errors + ### Opening Sylius with your plugin 1. Install symfony CLI command: https://symfony.com/download diff --git a/features/set_fee_to_payment_in_admin.feature b/features/set_fee_to_payment_in_admin.feature index 5f167a1..cc99837 100644 --- a/features/set_fee_to_payment_in_admin.feature +++ b/features/set_fee_to_payment_in_admin.feature @@ -17,29 +17,4 @@ Feature: Admin can set fee to a payment method in admin panel Then I should see the payment method "UPS" in the list And I should see the payment method "Cash on Delivery" in the list - When I want to modify the "Cash on Delivery" payment method - Then I should see that payment method "Cash on Delivery" has no fee - - When I want to modify the "Cash on Delivery" payment method - And I set fee "2.00" to "Cash on Delivery" payment method - Then I should see that payment method "Cash on Delivery" has fee "2.00" - And I want to modify the "UPS" payment method - And I should see that payment method "UPS" has no fee - - When I want to modify the "Cash on Delivery" payment method - And I set fee "0.00" to "Cash on Delivery" payment method - Then I should see that payment method "Cash on Delivery" has no fee - And I want to modify the "UPS" payment method - And I should see that payment method "UPS" has no fee - - When I want to modify the "Cash on Delivery" payment method - And I set fee "999.00" to "Cash on Delivery" payment method - Then I should see that payment method "Cash on Delivery" has fee "999.00" - And I want to modify the "UPS" payment method - And I should see that payment method "UPS" has no fee - - When I want to modify the "Cash on Delivery" payment method - And I remove fee from "Cash on Delivery" payment method - Then I should see that payment method "Cash on Delivery" has no fee - And I want to modify the "UPS" payment method - And I should see that payment method "UPS" has no fee +# TODO Behat with JS because amount field is rendered by JS