diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e7e9d11 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/.idea/SyliusPaymentFeePlugin.iml b/.idea/SyliusPaymentFeePlugin.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/SyliusPaymentFeePlugin.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0d7e96b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 2119593..44edbaf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ dist: trusty sudo: false php: - - 7.2 + - '7.2' + - '7.3' cache: yarn: true @@ -15,11 +16,9 @@ cache: env: global: + - APP_ENV=test - SYLIUS_CACHE_DIR=$HOME/.sylius-cache - SYLIUS_BUILD_DIR=etc/build - matrix: - - SYMFONY_VERSION="3.4.*" - - SYMFONY_VERSION="4.1.*" before_install: - phpenv config-rm xdebug.ini @@ -27,15 +26,14 @@ before_install: - mkdir -p "${SYLIUS_CACHE_DIR}" install: - - composer require "symfony/symfony:${SYMFONY_VERSION}" --no-interaction --no-update - composer install --no-interaction --prefer-dist - (cd tests/Application && yarn install) before_script: - - (cd tests/Application && bin/console doctrine:database:create --env=test -vvv) - - (cd tests/Application && bin/console doctrine:schema:create --env=test -vvv) - - (cd tests/Application && bin/console assets:install web --env=test -vvv) - - (cd tests/Application && bin/console cache:warmup --env=test -vvv) + - (cd tests/Application && bin/console doctrine:database:create -vvv) + - (cd tests/Application && bin/console doctrine:schema:create -vvv) + - (cd tests/Application && bin/console assets:install public -vvv) + - (cd tests/Application && bin/console cache:warmup -vvv) - (cd tests/Application && yarn build) # Configure display @@ -65,15 +63,15 @@ before_script: - java -Dwebdriver.chrome.driver=$SYLIUS_CACHE_DIR/chromedriver -jar $SYLIUS_CACHE_DIR/selenium.jar > /dev/null 2>&1 & # Run webserver - - (cd tests/Application && bin/console server:run 127.0.0.1:8080 -d web --env=test --quiet > /dev/null 2>&1 &) + - (cd tests/Application && bin/console server:run 127.0.0.1:8080 --quiet > /dev/null 2>&1 &) script: - - composer validate --strict - - bin/phpstan.phar analyse -c phpstan.neon -l max src/ + - composer validate + - vendor/bin/phpstan analyse -c phpstan.neon -l max src/ - - bin/phpunit - - bin/phpspec run - - bin/behat --strict -vvv --no-interaction || bin/behat --strict -vvv --no-interaction --rerun + - vendor/bin/phpunit + - vendor/bin/phpspec run + - vendor/bin/behat --strict -vvv --no-interaction || vendor/bin/behat --strict -vvv --no-interaction --rerun after_failure: - vendor/lakion/mink-debug-extension/travis/tools/upload-textfiles "${SYLIUS_BUILD_DIR}/*.log" diff --git a/behat.yml.dist b/behat.yml.dist index 5b462e1..e331f13 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -1,24 +1,49 @@ imports: - - vendor/sylius/sylius/behat.yml.dist + - vendor/sylius/sylius/src/Sylius/Behat/Resources/config/suites.yml - tests/Behat/Resources/suites.yml default: extensions: - FriendsOfBehat\ContextServiceExtension: - imports: - - vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml - - tests/Behat/Resources/services.xml - - FriendsOfBehat\SymfonyExtension: - kernel: - class: \App\Kernel - path: tests/Application/src/Kernel.php - bootstrap: vendor/autoload.php - Lakion\Behat\MinkDebugExtension: directory: etc/build clean_start: false screenshot: true Behat\MinkExtension: - base_url: "http://nginx" + files_path: "%paths.base%/vendor/sylius/sylius/src/Sylius/Behat/Resources/fixtures/" + base_url: "http://localhost:8080/" + default_session: symfony + javascript_session: chrome + sessions: + symfony: + symfony: ~ + 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\MangoSylius\PaymentFeePlugin\Application\Kernel + + FriendsOfBehat\VariadicExtension: ~ + + FriendsOfBehat\SuiteSettingsExtension: + paths: + - "features" diff --git a/bin/behat.sh b/bin/behat.sh new file mode 100755 index 0000000..e1b51e8 --- /dev/null +++ b/bin/behat.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# project root +cd "$(dirname "$DIR")" + +set -x + +vendor/bin/behat features diff --git a/bin/ecs.sh b/bin/ecs.sh index 1ec25dc..b7db7ac 100755 --- a/bin/ecs.sh +++ b/bin/ecs.sh @@ -8,5 +8,4 @@ cd "$(dirname "$DIR")" set -x -rm -rf tests/Application/var/cache/ -vendor/bin/ecs check src tests "$@" +vendor/bin/ecs check src "$@" diff --git a/bin/phpstan.sh b/bin/phpstan.sh index e945f84..d23acc0 100755 --- a/bin/phpstan.sh +++ b/bin/phpstan.sh @@ -9,6 +9,6 @@ cd "$(dirname "$DIR")" set -x vendor/bin/phpstan analyse \ --level 7 \ - --memory-limit 1G \ + --memory-limit 2G \ --configuration phpstan.neon \ src tests diff --git a/composer.json b/composer.json index a66926c..6c47de7 100644 --- a/composer.json +++ b/composer.json @@ -1,45 +1,52 @@ { - "name": "mangoweb-sylius/sylius-payment-fee-plugin", - "type": "sylius-plugin", - "description": "Payment fee plugin for Sylius.", - "license": "proprietary", - "require": { - "php": "^7.1", - "sylius/sylius": "^1.2.5", - "symfony/symfony": "^4.1", - "symfony/framework-bundle": "^4.1" - }, - "require-dev": { - "behat/behat": "^3.4", - "behat/mink": "^1.7@dev", - "behat/mink-browserkit-driver": "^1.3", - "behat/mink-extension": "^2.2", - "behat/mink-selenium2-driver": "^1.3", - "friends-of-behat/context-service-extension": "^1.2", - "friends-of-behat/cross-container-extension": "^1.1", - "friends-of-behat/service-container-extension": "^1.0", - "friends-of-behat/symfony-extension": "^1.2.1", - "friends-of-behat/variadic-extension": "^1.1", - "lakion/mink-debug-extension": "^1.2.3", - "phpstan/phpstan-doctrine": "^0.10", - "phpstan/phpstan-shim": "^0.10", - "phpstan/phpstan-symfony": "^0.10", - "phpstan/phpstan-webmozart-assert": "^0.10", - "phpunit/phpunit": "^6.5", - "sylius-labs/coding-standard": "^2.0", - "se/selenium-server-standalone": "^3.12", - "symfony/templating": "^4.1" - }, - "prefer-stable": true, - "autoload": { - "psr-4": { - "MangoSylius\\PaymentFeePlugin\\": "src/", - "Tests\\MangoSylius\\PaymentFeePlugin\\": "tests/" - } - }, - "autoload-dev": { - "psr-4": { - "App\\": "tests/Application/src/" - } - } + "name": "mangoweb-sylius/sylius-payment-fee-plugin", + "type": "sylius-plugin", + "keywords": ["sylius", "sylius-plugin"], + "description": "Payment fee plugin for Sylius.", + "license": "MIT", + "require": { + "php": "^7.2", + + "sylius/sylius": "^1.6" + }, + "require-dev": { + "behat/behat": "^3.4", + "behat/mink": "^1.7@dev", + "behat/mink-browserkit-driver": "^1.3", + "behat/mink-extension": "^2.2", + "behat/mink-selenium2-driver": "^1.3", + "friends-of-behat/page-object-extension": "^0.3", + "friends-of-behat/suite-settings-extension": "^1.0", + "friends-of-behat/symfony-extension": "^2.0", + "friends-of-behat/variadic-extension": "^1.1", + "lakion/mink-debug-extension": "^1.2.3", + "phpspec/phpspec": "^6.1", + "phpstan/phpstan-doctrine": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpstan/phpstan-webmozart-assert": "^0.11", + "phpunit/phpunit": "^8.0", + "sensiolabs/security-checker": "^5.0", + "sylius-labs/coding-standard": "^3.0", + "symfony/browser-kit": "^3.4|^4.3", + "symfony/debug-bundle": "^3.4|^4.3", + "symfony/dotenv": "^4.3", + "symfony/intl": "^3.4|^4.3", + "symfony/web-profiler-bundle": "^3.4|^4.3", + "symfony/web-server-bundle": "^3.4|^4.3" + }, + "prefer-stable": true, + "autoload": { + "psr-4": { + "MangoSylius\\PaymentFeePlugin\\": "src/", + "Tests\\MangoSylius\\PaymentFeePlugin\\": "tests/" + } + }, + "autoload-dev": { + "classmap": ["tests/Application/Kernel.php"] + }, + "extra": { + "branch-alias": { + "dev-master": "1.6-dev" + } + } } diff --git a/easy-coding-standard.yml b/easy-coding-standard.yml index 56efe75..2403599 100644 --- a/easy-coding-standard.yml +++ b/easy-coding-standard.yml @@ -1,6 +1,2 @@ imports: - { resource: 'vendor/sylius-labs/coding-standard/easy-coding-standard.yml' } - -parameters: - indentation: tab - diff --git a/features/managing_payment_methods/set_payment_method_extra_fee.feature b/features/managing_payment_methods/set_payment_method_extra_fee.feature new file mode 100644 index 0000000..204f70f --- /dev/null +++ b/features/managing_payment_methods/set_payment_method_extra_fee.feature @@ -0,0 +1,20 @@ +@set_payment_method_extra_fee +Feature: Set payment method extra fee + In order to add extra fee for a certain payment method + As an Administrator + I want to be able to define a extra fee amount for a payment method + + Background: + Given the store operates on a single channel in "United States" + And the store has zones "NorthAmerica", "SouthAmerica" and "Europe" + And the store has a payment method "Offline" with a code "offline" + And I am logged in as an administrator + + @ui + Scenario: Being able to define a fee amount for the payment method + Given I want to modify the "Offline" payment method + When I save my changes + And I add an extra fee of '30'$ + And I save my changes + Then I should be notified that it has been successfully edited + And this payment method have an extra fee of '30'$ diff --git a/phpspec.yml.dist b/phpspec.yml.dist new file mode 100644 index 0000000..94cf7fd --- /dev/null +++ b/phpspec.yml.dist @@ -0,0 +1,4 @@ +suites: + main: + namespace: MangoSylius\PaymentFeePlugin + psr4_prefix: MangoSylius\PaymentFeePlugin diff --git a/phpstan.neon b/phpstan.neon index d2ef937..bbf92cc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,11 +1,11 @@ includes: - vendor/phpstan/phpstan-doctrine/extension.neon - - vendor/phpstan/phpstan-symfony/extension.neon - vendor/phpstan/phpstan-webmozart-assert/extension.neon + parameters: symfony: - container_xml_path: tests/Application/var/cache/dev/srcDevDebugProjectContainer.xml + container_xml_path: tests/Application/var/cache/test/testContainer.xml excludes_analyse: # Too slow @@ -13,3 +13,6 @@ parameters: # Test dependencies - '*/tests/Application/var/*' + + - 'src/Migrations/' + - 'tests/' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 44ca447..2572002 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,20 @@ + bootstrap="tests/Application/config/bootstrap.php"> - + tests - + + + + diff --git a/src/DependencyInjection/Compiler/RegisterFeeCalculatorsPass.php b/src/DependencyInjection/Compiler/RegisterFeeCalculatorsPass.php index c3c6408..e5f2358 100644 --- a/src/DependencyInjection/Compiler/RegisterFeeCalculatorsPass.php +++ b/src/DependencyInjection/Compiler/RegisterFeeCalculatorsPass.php @@ -11,32 +11,32 @@ final class RegisterFeeCalculatorsPass implements CompilerPassInterface { - public function process(ContainerBuilder $container): void - { - if (!$container->hasDefinition('mango_sylius.payment_fee_plugin.registry.payment_calculator') - || !$container->hasDefinition('mango_sylius.payment_fee_plugin.form_registry.payment_calculator')) { - return; - } - - $registry = $container->getDefinition('mango_sylius.payment_fee_plugin.registry.payment_calculator'); - $formTypeRegistry = $container->getDefinition('mango_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.'); - } - - $name = $attributes[0]['calculator']; - $calculators[$name] = $attributes[0]['label']; - - $registry->addMethodCall('register', [$name, new Reference($id)]); - - if (isset($attributes[0]['form_type'])) { - $formTypeRegistry->addMethodCall('add', [$name, 'default', $attributes[0]['form_type']]); - } - } - - $container->setParameter('mango_sylius.payment_fee_plugin.payment_fee_calculators', $calculators); - } + public function process(ContainerBuilder $container): void + { + if (!$container->hasDefinition('mango_sylius.payment_fee_plugin.registry.payment_calculator') + || !$container->hasDefinition('mango_sylius.payment_fee_plugin.form_registry.payment_calculator')) { + return; + } + + $registry = $container->getDefinition('mango_sylius.payment_fee_plugin.registry.payment_calculator'); + $formTypeRegistry = $container->getDefinition('mango_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.'); + } + + $name = $attributes[0]['calculator']; + $calculators[$name] = $attributes[0]['label']; + + $registry->addMethodCall('register', [$name, new Reference($id)]); + + if (isset($attributes[0]['form_type'])) { + $formTypeRegistry->addMethodCall('add', [$name, 'default', $attributes[0]['form_type']]); + } + } + + $container->setParameter('mango_sylius.payment_fee_plugin.payment_fee_calculators', $calculators); + } } diff --git a/src/DependencyInjection/Compiler/TaxApplicatorCompilerPass.php b/src/DependencyInjection/Compiler/TaxApplicatorCompilerPass.php new file mode 100644 index 0000000..a047ede --- /dev/null +++ b/src/DependencyInjection/Compiler/TaxApplicatorCompilerPass.php @@ -0,0 +1,44 @@ +registerToOrderItemsBasedStrategy($container); + $this->registerToOrderItemUnitsBasedStrategy($container); + } + + private function registerToOrderItemsBasedStrategy( + ContainerBuilder $container + ): void { + $definition = $container->getDefinition( + 'sylius.taxation.order_items_based_strategy' + ); + $arg = $definition->getArgument(1); + $arg[] = new Reference(OrderPaymentTaxesApplicator::class); + $definition->setArgument(1, $arg); + } + + private function registerToOrderItemUnitsBasedStrategy( + ContainerBuilder $container + ): void { + $definition = $container->getDefinition( + 'sylius.taxation.order_item_units_based_strategy' + ); + $arg = $definition->getArgument(1); + $arg[] = new Reference(OrderPaymentTaxesApplicator::class); + $definition->setArgument(1, $arg); + } +} diff --git a/src/DependencyInjection/MangoSyliusPaymentFeeExtension.php b/src/DependencyInjection/MangoSyliusPaymentFeeExtension.php index ff504d2..cca2746 100644 --- a/src/DependencyInjection/MangoSyliusPaymentFeeExtension.php +++ b/src/DependencyInjection/MangoSyliusPaymentFeeExtension.php @@ -11,9 +11,9 @@ class MangoSyliusPaymentFeeExtension extends Extension { - public function load(array $configs, ContainerBuilder $container) - { - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('services.yml'); - } + public function load(array $configs, ContainerBuilder $container) + { + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('services.yml'); + } } diff --git a/src/Entity/Payment/PaymentMethod.php b/src/Entity/Payment/PaymentMethod.php new file mode 100644 index 0000000..c0d8880 --- /dev/null +++ b/src/Entity/Payment/PaymentMethod.php @@ -0,0 +1,19 @@ +calculatorRegistry = $calculatorRegistry; - } + public function __construct( + ServiceRegistryInterface $calculatorRegistry + ) { + $this->calculatorRegistry = $calculatorRegistry; + } - public function buildView(FormView $view, FormInterface $form, array $options): void - { - if (!isset($options['subject'])) { - return; - } + public function buildView(FormView $view, FormInterface $form, array $options): void + { + if (!isset($options['subject'])) { + return; + } - $subject = $options['subject']; - $paymentCosts = []; + $subject = $options['subject']; + $paymentCosts = []; - foreach ($view->vars['choices'] as $choiceView) { - $method = $choiceView->data; + foreach ($view->vars['choices'] as $choiceView) { + $method = $choiceView->data; - if (!$method instanceof PaymentMethodWithFeeInterface) { - throw new UnexpectedTypeException($method, PaymentMethodWithFeeInterface::class); - } + if (!$method instanceof PaymentMethodWithFeeInterface) { + throw new UnexpectedTypeException($method, PaymentMethodWithFeeInterface::class); + } - if ($method->getCalculator() === null) { - $paymentCosts[$choiceView->value] = 0; + if ($method->getCalculator() === null) { + $paymentCosts[$choiceView->value] = 0; - continue; - } + continue; + } - $calculator = $this->calculatorRegistry->get($method->getCalculator()); - assert($calculator instanceof CalculatorInterface); + $calculator = $this->calculatorRegistry->get($method->getCalculator()); + assert($calculator instanceof CalculatorInterface); - $paymentCosts[$choiceView->value] = $calculator->calculate($subject, $method->getCalculatorConfiguration()); - } + $paymentCosts[$choiceView->value] = $calculator->calculate($subject, $method->getCalculatorConfiguration()); + } - $view->vars['payment_costs'] = $paymentCosts; - } + $view->vars['payment_costs'] = $paymentCosts; + } - /** - * {@inheritdoc} - */ - public function getExtendedType() - { - return PaymentMethodChoiceType::class; - } + /** + * {@inheritdoc} + */ + public function getExtendedType() + { + return PaymentMethodChoiceType::class; + } } diff --git a/src/Form/Extension/PaymentMethodTypeExtension.php b/src/Form/Extension/PaymentMethodTypeExtension.php index 7bf55bb..0525f2d 100644 --- a/src/Form/Extension/PaymentMethodTypeExtension.php +++ b/src/Form/Extension/PaymentMethodTypeExtension.php @@ -21,100 +21,96 @@ class PaymentMethodTypeExtension extends AbstractTypeExtension { - /** - * @var ServiceRegistryInterface - */ - private $calculatorRegistry; - - /** - * @var FormTypeRegistryInterface - */ - private $formTypeRegistry; - - public function __construct( - ServiceRegistryInterface $calculatorRegistry, - FormTypeRegistryInterface $formTypeRegistry - ) { - $this->calculatorRegistry = $calculatorRegistry; - $this->formTypeRegistry = $formTypeRegistry; - } - - public function buildForm(FormBuilderInterface $builder, array $options) - { - $builder - ->addEventSubscriber(new AddCodeFormSubscriber()) - ->add('taxCategory', TaxCategoryChoiceType::class) - ->add('calculator', CalculatorChoiceType::class, [ - 'label' => 'mango-sylius.form.payment_method.calculator', - ] - )->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { - $method = $event->getData(); - - if ($method === null || $method->getId() === null) { - return; - } - - if ($method instanceof PaymentMethodWithFeeInterface && $method->getCalculator() !== null) { - $this->addConfigurationField($event->getForm(), $method->getCalculator()); - } - } - ) - ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { - $data = $event->getData(); - - if (!is_array($data) || empty($data) || !array_key_exists('calculator', $data)) { - return; - } - - $this->addConfigurationField($event->getForm(), $data['calculator']); - } - ); - - $prototypes = []; - foreach ($this->calculatorRegistry->all() as $name => $calculator) { - assert($calculator instanceof CalculatorInterface); - $calculatorType = $calculator->getType(); - - if (!$this->formTypeRegistry->has($calculatorType, 'default')) { - continue; - } - - $form = $builder->create('calculatorConfiguration', $this->formTypeRegistry->get($calculatorType, 'default')); - - $prototypes['calculators'][$name] = $form->getForm(); - } - - $builder->setAttribute('prototypes', $prototypes); - } - - private function addConfigurationField(FormInterface $form, string $calculatorName): void - { - $calculator = $this->calculatorRegistry->get($calculatorName); - assert($calculator instanceof CalculatorInterface); - - $calculatorType = $calculator->getType(); - if (!$this->formTypeRegistry->has($calculatorType, 'default')) { - return; - } - - $form->add('calculatorConfiguration', $this->formTypeRegistry->get($calculatorType, 'default')); - } - - public function buildView(FormView $view, FormInterface $form, array $options): void - { - $view->vars['prototypes'] = []; - foreach ($form->getConfig()->getAttribute('prototypes') as $group => $prototypes) { - foreach ($prototypes as $type => $prototype) { - $view->vars['prototypes'][$group . '_' . $type] = $prototype->createView($view); - } - } - } - - /** - * {@inheritdoc} - */ - public function getExtendedType() - { - return SyliusPaymentMethodType::class; - } + /** @var ServiceRegistryInterface */ + private $calculatorRegistry; + + /** @var FormTypeRegistryInterface */ + private $formTypeRegistry; + + public function __construct( + ServiceRegistryInterface $calculatorRegistry, + FormTypeRegistryInterface $formTypeRegistry + ) { + $this->calculatorRegistry = $calculatorRegistry; + $this->formTypeRegistry = $formTypeRegistry; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->addEventSubscriber(new AddCodeFormSubscriber()) + ->add('taxCategory', TaxCategoryChoiceType::class) + ->add('calculator', CalculatorChoiceType::class, [ + 'label' => 'mango-sylius.form.payment_method.calculator', + ] + )->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { + $method = $event->getData(); + + if ($method === null || $method->getId() === null) { + return; + } + + if ($method instanceof PaymentMethodWithFeeInterface && $method->getCalculator() !== null) { + $this->addConfigurationField($event->getForm(), $method->getCalculator()); + } + } + ) + ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { + $data = $event->getData(); + + if (!is_array($data) || empty($data) || !array_key_exists('calculator', $data)) { + return; + } + + $this->addConfigurationField($event->getForm(), $data['calculator']); + } + ); + + $prototypes = []; + foreach ($this->calculatorRegistry->all() as $name => $calculator) { + assert($calculator instanceof CalculatorInterface); + $calculatorType = $calculator->getType(); + + if (!$this->formTypeRegistry->has($calculatorType, 'default')) { + continue; + } + + $form = $builder->create('calculatorConfiguration', $this->formTypeRegistry->get($calculatorType, 'default')); + + $prototypes['calculators'][$name] = $form->getForm(); + } + + $builder->setAttribute('prototypes', $prototypes); + } + + private function addConfigurationField(FormInterface $form, string $calculatorName): void + { + $calculator = $this->calculatorRegistry->get($calculatorName); + assert($calculator instanceof CalculatorInterface); + + $calculatorType = $calculator->getType(); + if (!$this->formTypeRegistry->has($calculatorType, 'default')) { + return; + } + + $form->add('calculatorConfiguration', $this->formTypeRegistry->get($calculatorType, 'default')); + } + + public function buildView(FormView $view, FormInterface $form, array $options): void + { + $view->vars['prototypes'] = []; + foreach ($form->getConfig()->getAttribute('prototypes') as $group => $prototypes) { + foreach ($prototypes as $type => $prototype) { + $view->vars['prototypes'][$group . '_' . $type] = $prototype->createView($view); + } + } + } + + /** + * {@inheritdoc} + */ + public function getExtendedType() + { + return SyliusPaymentMethodType::class; + } } diff --git a/src/Form/Type/Calculator/ChannelBasedFlatRateConfigurationType.php b/src/Form/Type/Calculator/ChannelBasedFlatRateConfigurationType.php index 0a490d0..a3ba86f 100644 --- a/src/Form/Type/Calculator/ChannelBasedFlatRateConfigurationType.php +++ b/src/Form/Type/Calculator/ChannelBasedFlatRateConfigurationType.php @@ -11,40 +11,40 @@ final class ChannelBasedFlatRateConfigurationType extends AbstractType { - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'entry_type' => FlatRateConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel): array { - if ($channel->getBaseCurrency() === null) { - throw new \ErrorException('$channel->getBaseCurrency() cannot by NULL'); - } + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'entry_type' => FlatRateConfigurationType::class, + 'entry_options' => function (ChannelInterface $channel): array { + if ($channel->getBaseCurrency() === null) { + throw new \ErrorException('$channel->getBaseCurrency() cannot by NULL'); + } - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, - ] - ); - } + return [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ]; + }, + ] + ); + } - /** - * {@inheritdoc} - */ - public function getParent(): string - { - return ChannelCollectionType::class; - } + /** + * {@inheritdoc} + */ + public function getParent(): string + { + return ChannelCollectionType::class; + } - /** - * {@inheritdoc} - */ - public function getBlockPrefix(): string - { - return 'mango-sylius_channel_based_payment_calculator_flat_rate'; - } + /** + * {@inheritdoc} + */ + public function getBlockPrefix(): string + { + return 'mango-sylius_channel_based_payment_calculator_flat_rate'; + } } diff --git a/src/Form/Type/Calculator/FlatRateConfigurationType.php b/src/Form/Type/Calculator/FlatRateConfigurationType.php index a62ee48..10ad1d5 100644 --- a/src/Form/Type/Calculator/FlatRateConfigurationType.php +++ b/src/Form/Type/Calculator/FlatRateConfigurationType.php @@ -13,39 +13,39 @@ class FlatRateConfigurationType extends AbstractType { - public function buildForm(FormBuilderInterface $builder, array $options): void - { - $builder - ->add('amount', MoneyType::class, [ - 'label' => 'mango-sylius.form.payment_calculator.flat_rate_configuration.amount', - 'constraints' => [ - new NotBlank(['groups' => ['sylius']]), - new Type(['type' => 'integer', 'groups' => ['sylius']]), - ], - 'currency' => $options['currency'], - ] - ); - } + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('amount', MoneyType::class, [ + 'label' => 'mango-sylius.form.payment_calculator.flat_rate_configuration.amount', + 'constraints' => [ + new NotBlank(['groups' => ['sylius']]), + new Type(['type' => 'integer', 'groups' => ['sylius']]), + ], + 'currency' => $options['currency'], + ] + ); + } - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver): void - { - $resolver - ->setDefaults([ - 'data_class' => null, - ] - ) - ->setRequired('currency') - ->setAllowedTypes('currency', 'string'); - } + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver): void + { + $resolver + ->setDefaults([ + 'data_class' => null, + ] + ) + ->setRequired('currency') + ->setAllowedTypes('currency', 'string'); + } - /** - * {@inheritdoc} - */ - public function getBlockPrefix(): string - { - return 'sylius_shipping_calculator_flat_rate'; - } + /** + * {@inheritdoc} + */ + public function getBlockPrefix(): string + { + return 'sylius_shipping_calculator_flat_rate'; + } } diff --git a/src/Form/Type/CalculatorChoiceType.php b/src/Form/Type/CalculatorChoiceType.php index 3cba6ec..6786bc2 100644 --- a/src/Form/Type/CalculatorChoiceType.php +++ b/src/Form/Type/CalculatorChoiceType.php @@ -10,44 +10,39 @@ final class CalculatorChoiceType extends AbstractType { - /** - * @var array - */ - private $calculators; - - /** - * @param array $calculators - */ - public function __construct(array $calculators) - { - $this->calculators = $calculators; - } - - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver): void - { - $resolver - ->setDefaults([ - 'choices' => array_flip($this->calculators), - ]) - ; - } - - /** - * {@inheritdoc} - */ - public function getParent(): string - { - return ChoiceType::class; - } - - /** - * {@inheritdoc} - */ - public function getBlockPrefix(): string - { - return 'sylius_payment_calculator_choice'; - } + /** @var array */ + private $calculators; + + public function __construct(array $calculators) + { + $this->calculators = $calculators; + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver): void + { + $resolver + ->setDefaults([ + 'choices' => array_flip($this->calculators), + ]) + ; + } + + /** + * {@inheritdoc} + */ + public function getParent(): string + { + return ChoiceType::class; + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix(): string + { + return 'sylius_payment_calculator_choice'; + } } diff --git a/src/MangoSyliusPaymentFeePlugin.php b/src/MangoSyliusPaymentFeePlugin.php index a9d0f6d..0451964 100644 --- a/src/MangoSyliusPaymentFeePlugin.php +++ b/src/MangoSyliusPaymentFeePlugin.php @@ -4,16 +4,18 @@ namespace MangoSylius\PaymentFeePlugin; +use MangoSylius\PaymentFeePlugin\DependencyInjection\Compiler\TaxApplicatorCompilerPass; use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; class MangoSyliusPaymentFeePlugin extends Bundle { - use SyliusPluginTrait; + use SyliusPluginTrait; - public function build(ContainerBuilder $container) - { - $container->addCompilerPass(new DependencyInjection\Compiler\RegisterFeeCalculatorsPass()); - } + public function build(ContainerBuilder $container) + { + $container->addCompilerPass(new DependencyInjection\Compiler\RegisterFeeCalculatorsPass()); + $container->addCompilerPass(new TaxApplicatorCompilerPass()); + } } diff --git a/src/Model/AdjustmentInterface.php b/src/Model/AdjustmentInterface.php index 0bb8d2e..b68d75a 100644 --- a/src/Model/AdjustmentInterface.php +++ b/src/Model/AdjustmentInterface.php @@ -8,5 +8,5 @@ interface AdjustmentInterface extends SyliusAdjustmentInterface { - public const PAYMENT_ADJUSTMENT = 'payment'; + public const PAYMENT_ADJUSTMENT = 'payment'; } diff --git a/src/Model/Calculator/CalculatorInterface.php b/src/Model/Calculator/CalculatorInterface.php index fb12587..df581d8 100644 --- a/src/Model/Calculator/CalculatorInterface.php +++ b/src/Model/Calculator/CalculatorInterface.php @@ -8,7 +8,7 @@ interface CalculatorInterface { - public function calculate(PaymentInterface $subject, array $configuration): ?int; + public function calculate(PaymentInterface $subject, array $configuration): ?int; - public function getType(): string; + public function getType(): string; } diff --git a/src/Model/Calculator/DelegatingCalculator.php b/src/Model/Calculator/DelegatingCalculator.php index 8c49036..dcc8d7f 100644 --- a/src/Model/Calculator/DelegatingCalculator.php +++ b/src/Model/Calculator/DelegatingCalculator.php @@ -10,36 +10,34 @@ final class DelegatingCalculator implements DelegatingCalculatorInterface { - /** - * @var ServiceRegistryInterface - */ - private $registry; - - public function __construct(ServiceRegistryInterface $registry) - { - $this->registry = $registry; - } - - /** - * {@inheritdoc} - */ - public function calculate(PaymentInterface $subject): ?int - { - $method = $subject->getMethod(); - if ($method === null) { - throw new UndefinedPaymentMethodException('Cannot calculate charge for payment without a defined payment method.'); - } - - if (!($method instanceof PaymentMethodWithFeeInterface)) { - return 0; - } - if ($method->getCalculator() === null) { - return 0; - } - - $calculator = $this->registry->get($method->getCalculator()); - assert($calculator instanceof CalculatorInterface); - - return $calculator->calculate($subject, $method->getCalculatorConfiguration()); - } + /** @var ServiceRegistryInterface */ + private $registry; + + public function __construct(ServiceRegistryInterface $registry) + { + $this->registry = $registry; + } + + /** + * {@inheritdoc} + */ + public function calculate(PaymentInterface $subject): ?int + { + $method = $subject->getMethod(); + if ($method === null) { + throw new UndefinedPaymentMethodException('Cannot calculate charge for payment without a defined payment method.'); + } + + if (!($method instanceof PaymentMethodWithFeeInterface)) { + return 0; + } + if ($method->getCalculator() === null) { + return 0; + } + + $calculator = $this->registry->get($method->getCalculator()); + assert($calculator instanceof CalculatorInterface); + + return $calculator->calculate($subject, $method->getCalculatorConfiguration()); + } } diff --git a/src/Model/Calculator/DelegatingCalculatorInterface.php b/src/Model/Calculator/DelegatingCalculatorInterface.php index dfe0681..0a416af 100644 --- a/src/Model/Calculator/DelegatingCalculatorInterface.php +++ b/src/Model/Calculator/DelegatingCalculatorInterface.php @@ -8,5 +8,5 @@ interface DelegatingCalculatorInterface { - public function calculate(PaymentInterface $subject): ?int; + public function calculate(PaymentInterface $subject): ?int; } diff --git a/src/Model/Calculator/FlatRateCalculator.php b/src/Model/Calculator/FlatRateCalculator.php index 048380f..0774a4e 100644 --- a/src/Model/Calculator/FlatRateCalculator.php +++ b/src/Model/Calculator/FlatRateCalculator.php @@ -11,41 +11,41 @@ final class FlatRateCalculator implements CalculatorInterface { - /** - * {@inheritdoc} - * - * @throws \Sylius\Component\Core\Exception\MissingChannelConfigurationException - */ - public function calculate(BasePaymentInterface $subject, array $configuration): ?int - { - assert($subject instanceof PaymentInterface); - - $order = $subject->getOrder(); - assert($order instanceof OrderInterface); - - if ($order->getChannel() === null) { - throw new \ErrorException('$order->getChannel() cannot by NULL'); - } - - $channelCode = $order->getChannel()->getCode(); - - if (!isset($configuration[$channelCode])) { - throw new MissingChannelConfigurationException(sprintf( - 'Channel %s has no amount defined for shipping method %s', - $order->getChannel()->getName(), - $subject->getMethod() !== null ? $subject->getMethod()->getName() : 'null' - ) - ); - } - - return (int) $configuration[$channelCode]['amount']; - } - - /** - * {@inheritdoc} - */ - public function getType(): string - { - return 'flat_rate'; - } + /** + * {@inheritdoc} + * + * @throws \Sylius\Component\Core\Exception\MissingChannelConfigurationException + */ + public function calculate(BasePaymentInterface $subject, array $configuration): ?int + { + assert($subject instanceof PaymentInterface); + + $order = $subject->getOrder(); + assert($order instanceof OrderInterface); + + if ($order->getChannel() === null) { + throw new \ErrorException('$order->getChannel() cannot by NULL'); + } + + $channelCode = $order->getChannel()->getCode(); + + if (!isset($configuration[$channelCode])) { + throw new MissingChannelConfigurationException(sprintf( + 'Channel %s has no amount defined for shipping method %s', + $order->getChannel()->getName(), + $subject->getMethod() !== null ? $subject->getMethod()->getName() : 'null' + ) + ); + } + + return (int) $configuration[$channelCode]['amount']; + } + + /** + * {@inheritdoc} + */ + public function getType(): string + { + return 'flat_rate'; + } } diff --git a/src/Model/Calculator/FreeCalculator.php b/src/Model/Calculator/FreeCalculator.php index dd81582..1ebee97 100644 --- a/src/Model/Calculator/FreeCalculator.php +++ b/src/Model/Calculator/FreeCalculator.php @@ -8,21 +8,21 @@ final class FreeCalculator implements CalculatorInterface { - /** - * {@inheritdoc} - * - * @throws \Sylius\Component\Core\Exception\MissingChannelConfigurationException - */ - public function calculate(BasePaymentInterface $subject, array $configuration): ?int - { - return null; - } + /** + * {@inheritdoc} + * + * @throws \Sylius\Component\Core\Exception\MissingChannelConfigurationException + */ + public function calculate(BasePaymentInterface $subject, array $configuration): ?int + { + return null; + } - /** - * {@inheritdoc} - */ - public function getType(): string - { - return 'free'; - } + /** + * {@inheritdoc} + */ + public function getType(): string + { + return 'free'; + } } diff --git a/src/Model/PaymentChargesProcessor.php b/src/Model/PaymentChargesProcessor.php index ca2f494..2970a62 100644 --- a/src/Model/PaymentChargesProcessor.php +++ b/src/Model/PaymentChargesProcessor.php @@ -13,51 +13,43 @@ final class PaymentChargesProcessor implements OrderProcessorInterface { - /** - * @var FactoryInterface - */ - private $adjustmentFactory; - - /** - * @var DelegatingCalculatorInterface - */ - private $paymentChargesCalculator; - - /** - * @param FactoryInterface $adjustmentFactory - * @param DelegatingCalculatorInterface $paymentChargesCalculator - */ - public function __construct( - FactoryInterface $adjustmentFactory, - DelegatingCalculatorInterface $paymentChargesCalculator - ) { - $this->adjustmentFactory = $adjustmentFactory; - $this->paymentChargesCalculator = $paymentChargesCalculator; - } - - public function process(BaseOrderInterface $order): void - { - assert($order instanceof OrderInterface); - - $order->removeAdjustments(AdjustmentInterface::PAYMENT_ADJUSTMENT); - - foreach ($order->getPayments() as $payment) { - $paymentCharge = $this->paymentChargesCalculator->calculate($payment); - - if ($paymentCharge === null) { - continue; - } - - $adjustment = $this->adjustmentFactory->createNew(); - assert($adjustment instanceof BaseAdjustmentInterface); - - $adjustment->setType(AdjustmentInterface::PAYMENT_ADJUSTMENT); - $adjustment->setAmount($paymentCharge); - $adjustment->setLabel($payment->getMethod() !== null ? $payment->getMethod()->getName() : null); - $adjustment->setOriginCode($payment->getMethod() !== null ? $payment->getMethod()->getCode() : null); - $adjustment->setNeutral(false); - - $order->addAdjustment($adjustment); - } - } + /** @var FactoryInterface */ + private $adjustmentFactory; + + /** @var DelegatingCalculatorInterface */ + private $paymentChargesCalculator; + + public function __construct( + FactoryInterface $adjustmentFactory, + DelegatingCalculatorInterface $paymentChargesCalculator + ) { + $this->adjustmentFactory = $adjustmentFactory; + $this->paymentChargesCalculator = $paymentChargesCalculator; + } + + public function process(BaseOrderInterface $order): void + { + assert($order instanceof OrderInterface); + + $order->removeAdjustments(AdjustmentInterface::PAYMENT_ADJUSTMENT); + + foreach ($order->getPayments() as $payment) { + $paymentCharge = $this->paymentChargesCalculator->calculate($payment); + + if ($paymentCharge === null) { + continue; + } + + $adjustment = $this->adjustmentFactory->createNew(); + assert($adjustment instanceof BaseAdjustmentInterface); + + $adjustment->setType(AdjustmentInterface::PAYMENT_ADJUSTMENT); + $adjustment->setAmount($paymentCharge); + $adjustment->setLabel($payment->getMethod() !== null ? $payment->getMethod()->getName() : null); + $adjustment->setOriginCode($payment->getMethod() !== null ? $payment->getMethod()->getCode() : null); + $adjustment->setNeutral(false); + + $order->addAdjustment($adjustment); + } + } } diff --git a/src/Model/PaymentMethodWithFeeInterface.php b/src/Model/PaymentMethodWithFeeInterface.php index 35502df..e308129 100644 --- a/src/Model/PaymentMethodWithFeeInterface.php +++ b/src/Model/PaymentMethodWithFeeInterface.php @@ -10,9 +10,9 @@ interface PaymentMethodWithFeeInterface extends PaymentMethodInterface, TaxableInterface { - public function getCalculator(): ?string; + public function getCalculator(): ?string; - public function getCalculatorConfiguration(): array; + public function getCalculatorConfiguration(): array; - public function setTaxCategory(?TaxCategoryInterface $category): void; + public function setTaxCategory(?TaxCategoryInterface $category): void; } diff --git a/src/Model/PaymentMethodWithFeeTrait.php b/src/Model/PaymentMethodWithFeeTrait.php index 5aaa3c5..aba3aad 100644 --- a/src/Model/PaymentMethodWithFeeTrait.php +++ b/src/Model/PaymentMethodWithFeeTrait.php @@ -9,52 +9,52 @@ trait PaymentMethodWithFeeTrait { - /** - * @var string|null - * @ORM\Column(name="calculator", type="text", nullable=true) - */ - protected $calculator; - - /** - * @var TaxCategoryInterface|null - * @ORM\ManyToOne(targetEntity="Sylius\Component\Taxation\Model\TaxCategory") - * @ORM\JoinColumn(name="tax_category_id") - */ - protected $taxCategory; - - /** - * @var array - * @ORM\Column(name="calculator_configuration", type="json", nullable=true) - */ - protected $calculatorConfiguration = []; - - public function getCalculator(): ?string - { - return $this->calculator; - } - - public function setCalculator(?string $calculator) - { - $this->calculator = $calculator; - } - - public function getCalculatorConfiguration(): array - { - return $this->calculatorConfiguration ?? []; - } - - public function setCalculatorConfiguration(array $calculatorConfiguration) - { - $this->calculatorConfiguration = $calculatorConfiguration; - } - - public function getTaxCategory(): ?TaxCategoryInterface - { - return $this->taxCategory; - } - - public function setTaxCategory(?TaxCategoryInterface $taxCategory): void - { - $this->taxCategory = $taxCategory; - } + /** + * @var string|null + * @ORM\Column(name="calculator", type="text", nullable=true) + */ + protected $calculator; + + /** + * @var TaxCategoryInterface|null + * @ORM\ManyToOne(targetEntity="Sylius\Component\Taxation\Model\TaxCategory") + * @ORM\JoinColumn(name="tax_category_id") + */ + protected $taxCategory; + + /** + * @var array + * @ORM\Column(name="calculator_configuration", type="json", nullable=true) + */ + protected $calculatorConfiguration = []; + + public function getCalculator(): ?string + { + return $this->calculator; + } + + public function setCalculator(?string $calculator) + { + $this->calculator = $calculator; + } + + public function getCalculatorConfiguration(): array + { + return $this->calculatorConfiguration ?? []; + } + + public function setCalculatorConfiguration(array $calculatorConfiguration) + { + $this->calculatorConfiguration = $calculatorConfiguration; + } + + public function getTaxCategory(): ?TaxCategoryInterface + { + return $this->taxCategory; + } + + public function setTaxCategory(?TaxCategoryInterface $taxCategory): void + { + $this->taxCategory = $taxCategory; + } } diff --git a/src/Model/Taxation/Applicator/OrderPaymentTaxesApplicator.php b/src/Model/Taxation/Applicator/OrderPaymentTaxesApplicator.php index 8bf4e5d..618b298 100644 --- a/src/Model/Taxation/Applicator/OrderPaymentTaxesApplicator.php +++ b/src/Model/Taxation/Applicator/OrderPaymentTaxesApplicator.php @@ -17,105 +17,88 @@ class OrderPaymentTaxesApplicator implements OrderTaxesApplicatorInterface { - /** - * @var CalculatorInterface - */ - private $calculator; - - /** - * @var AdjustmentFactoryInterface - */ - private $adjustmentFactory; - - /** - * @var TaxRateResolverInterface - */ - private $taxRateResolver; - - /** - * @param CalculatorInterface $calculator - * @param AdjustmentFactoryInterface $adjustmentFactory - * @param TaxRateResolverInterface $taxRateResolver - */ - public function __construct( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentFactory, - TaxRateResolverInterface $taxRateResolver - ) { - $this->calculator = $calculator; - $this->adjustmentFactory = $adjustmentFactory; - $this->taxRateResolver = $taxRateResolver; - } - - private function getPaymentFee(OrderInterface $order): int - { - $paymentFees = $order->getAdjustmentsRecursively(AdjustmentInterface::PAYMENT_ADJUSTMENT); - if (!$paymentFees->count()) { - return 0; - } - - $paymentFee = $paymentFees->first(); - - return $paymentFee->getAmount(); - } - - /** - * {@inheritdoc} - */ - public function apply(OrderInterface $order, ZoneInterface $zone): void - { - $paymentTotal = $this->getPaymentFee($order); - - if (0 === $paymentTotal) { - return; - } - - $paymentMethod = $this->getPaymentMethod($order); - if ($paymentMethod === null) { - return; - } - - $taxRate = $this->taxRateResolver->resolve($paymentMethod, ['zone' => $zone]); - if (null === $taxRate) { - return; - } - - $taxAmount = $this->calculator->calculate($paymentTotal, $taxRate); - if (0.00 === $taxAmount) { - return; - } - - $label = $taxRate->getLabel() ?? 'payment tax'; - $this->addAdjustment($order, (int) $taxAmount, $label, $taxRate->isIncludedInPrice()); - } - - /** - * @param OrderInterface $order - * @param int $taxAmount - * @param string $label - * @param bool $included - */ - private function addAdjustment(OrderInterface $order, int $taxAmount, string $label, bool $included): void - { - /** @var AdjustmentInterface $paymentTaxAdjustment */ - $paymentTaxAdjustment = $this->adjustmentFactory - ->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, $label, $taxAmount, $included); - $order->addAdjustment($paymentTaxAdjustment); - } - - private function getPaymentMethod(OrderInterface $order): ?PaymentMethodWithFeeInterface - { - /** @var PaymentInterface|bool $shipment */ - $payment = $order->getPayments()->first(); - if (false === $payment) { - return null; - } - - $method = $payment->getMethod(); - - /** @var PaymentMethodWithFeeInterface $method */ - Assert::isInstanceOf($method, PaymentMethodWithFeeInterface::class); - - return $method; - } + /** @var CalculatorInterface */ + private $calculator; + + /** @var AdjustmentFactoryInterface */ + private $adjustmentFactory; + + /** @var TaxRateResolverInterface */ + private $taxRateResolver; + + public function __construct( + CalculatorInterface $calculator, + AdjustmentFactoryInterface $adjustmentFactory, + TaxRateResolverInterface $taxRateResolver + ) { + $this->calculator = $calculator; + $this->adjustmentFactory = $adjustmentFactory; + $this->taxRateResolver = $taxRateResolver; + } + + private function getPaymentFee(OrderInterface $order): int + { + $paymentFees = $order->getAdjustmentsRecursively(AdjustmentInterface::PAYMENT_ADJUSTMENT); + if (!$paymentFees->count()) { + return 0; + } + + $paymentFee = $paymentFees->first(); + + return $paymentFee->getAmount(); + } + + /** + * {@inheritdoc} + */ + public function apply(OrderInterface $order, ZoneInterface $zone): void + { + $paymentTotal = $this->getPaymentFee($order); + + if (0 === $paymentTotal) { + return; + } + + $paymentMethod = $this->getPaymentMethod($order); + if ($paymentMethod === null) { + return; + } + + $taxRate = $this->taxRateResolver->resolve($paymentMethod, ['zone' => $zone]); + if (null === $taxRate) { + return; + } + + $taxAmount = $this->calculator->calculate($paymentTotal, $taxRate); + if (0.00 === $taxAmount) { + return; + } + + $label = $taxRate->getLabel() ?? 'payment tax'; + $this->addAdjustment($order, (int) $taxAmount, $label, $taxRate->isIncludedInPrice()); + } + + private function addAdjustment(OrderInterface $order, int $taxAmount, string $label, bool $included): void + { + /** @var AdjustmentInterface $paymentTaxAdjustment */ + $paymentTaxAdjustment = $this->adjustmentFactory + ->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, $label, $taxAmount, $included); + $order->addAdjustment($paymentTaxAdjustment); + } + + private function getPaymentMethod(OrderInterface $order): ?PaymentMethodWithFeeInterface + { + /** @var PaymentInterface|bool $shipment */ + $payment = $order->getPayments()->first(); + if (false === $payment) { + return null; + } + + $method = $payment->getMethod(); + + /** @var PaymentMethodWithFeeInterface $method */ + Assert::isInstanceOf($method, PaymentMethodWithFeeInterface::class); + + return $method; + } } diff --git a/src/Resources/config/resources.yml b/src/Resources/config/resources.yml new file mode 100644 index 0000000..5b4c9c2 --- /dev/null +++ b/src/Resources/config/resources.yml @@ -0,0 +1,5 @@ +sylius_payment: + resources: + payment_method: + classes: + model: MangoSylius\PaymentFeePlugin\Entity\Payment\PaymentMethod diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 4c9c894..a08b225 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -79,25 +79,3 @@ services: $calculator: '@sylius.tax_calculator' $adjustmentFactory: '@sylius.factory.adjustment' $taxRateResolver: '@sylius.tax_rate_resolver' - - mango_sylius.taxation.order_items_based_strategy: - class: Sylius\Bundle\CoreBundle\Taxation\Strategy\TaxCalculationStrategy - decorates: sylius.taxation.order_items_based_strategy - tags: - - name: sylius.taxation.calculation_strategy - type: order_items_based - label: 'Order items based' - arguments: - $type: 'order_items_based' - $applicators: ['@sylius.taxation.order_items_taxes_applicator', '@sylius.taxation.order_shipment_taxes_applicator', '@MangoSylius\PaymentFeePlugin\Model\Taxation\Applicator\OrderPaymentTaxesApplicator'] - - mango_sylius.taxation.order_item_units_based_strategy: - class: Sylius\Bundle\CoreBundle\Taxation\Strategy\TaxCalculationStrategy - decorates: sylius.taxation.order_item_units_based_strategy - tags: - - name: sylius.taxation.calculation_strategy - type: order_item_units_based - label: 'Order item units based' - arguments: - $type: order_item_units_based - $applicators: ['@sylius.taxation.order_item_units_taxes_applicator', '@sylius.taxation.order_shipment_taxes_applicator', '@MangoSylius\PaymentFeePlugin\Model\Taxation\Applicator\OrderPaymentTaxesApplicator'] diff --git a/tests/Application/.babelrc b/tests/Application/.babelrc index 0ac85eb..e563a62 100644 --- a/tests/Application/.babelrc +++ b/tests/Application/.babelrc @@ -1,16 +1,15 @@ - { - "presets": [ - ["env", { - "targets": { - "node": "6" - }, - "useBuiltIns": true - }] - ], - "plugins": [ - ["transform-object-rest-spread", { - "useBuiltIns": true - }] - ] + "presets": [ + ["env", { + "targets": { + "node": "6" + }, + "useBuiltIns": true + }] + ], + "plugins": [ + ["transform-object-rest-spread", { + "useBuiltIns": true + }] + ] } diff --git a/tests/Application/.env.dist b/tests/Application/.env similarity index 54% rename from tests/Application/.env.dist rename to tests/Application/.env index de29f0e..e6d78b7 100644 --- a/tests/Application/.env.dist +++ b/tests/Application/.env @@ -1,24 +1,23 @@ -# This file is a "template" of which env vars need to be defined for your application -# Copy this file to .env file for development, create environment variables when deploying to production +# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file +# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production. # https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration ###> symfony/framework-bundle ### APP_ENV=dev -APP_SECRET=de8fad07a7c13ea682ad37d41b14516d -#TRUSTED_PROXIES=127.0.0.1,127.0.0.2 -#TRUSTED_HOSTS=localhost,example.com +APP_DEBUG=1 +APP_SECRET=EDITME ###< symfony/framework-bundle ### ###> doctrine/doctrine-bundle ### # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url -# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" -# Configure your db driver and server_version in config/packages/doctrine.yaml -DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name +# 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://syliususer:root@127.0.0.1/sylius ###< doctrine/doctrine-bundle ### ###> symfony/swiftmailer-bundle ### # For Gmail as a transport, use: "gmail://username:password@localhost" # For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" # Delivery is disabled by default via "null://localhost" -MAILER_URL=null://localhost +MAILER_URL=smtp://localhost ###< symfony/swiftmailer-bundle ### diff --git a/tests/Application/.env.test b/tests/Application/.env.test new file mode 100644 index 0000000..3d8d4d3 --- /dev/null +++ b/tests/Application/.env.test @@ -0,0 +1,5 @@ +APP_SECRET='ch4mb3r0f5ecr3ts' + +KERNEL_CLASS='Tests\MangoSylius\PaymentFeePlugin\Application\Kernel' + + diff --git a/tests/Application/.eslintrc.js b/tests/Application/.eslintrc.js new file mode 100644 index 0000000..92c4cee --- /dev/null +++ b/tests/Application/.eslintrc.js @@ -0,0 +1,20 @@ +module.exports = { + extends: 'airbnb-base', + env: { + node: true, + }, + rules: { + 'object-shorthand': ['error', 'always', { + avoidQuotes: true, + avoidExplicitReturnArrows: true, + }], + 'function-paren-newline': ['error', 'consistent'], + 'max-len': ['warn', 120, 2, { + ignoreUrls: true, + ignoreComments: false, + ignoreRegExpLiterals: true, + ignoreStrings: true, + ignoreTemplateLiterals: true, + }], + }, +}; diff --git a/tests/Application/.gitignore b/tests/Application/.gitignore index 1625cca..8ad1225 100644 --- a/tests/Application/.gitignore +++ b/tests/Application/.gitignore @@ -1,27 +1,22 @@ +/public/assets +/public/css +/public/js +/public/media/* +!/public/media/image/ +/public/media/image/* +!/public/media/image/.gitignore + +/node_modules ###> symfony/framework-bundle ### -/public/bundles/ +/.env.*.local +/.env.local +/.env.local.php +/public/bundles /var/ /vendor/ ###< symfony/framework-bundle ### -###> symfony/phpunit-bridge ### -.phpunit -/phpunit.xml -###< symfony/phpunit-bridge ### - ###> symfony/web-server-bundle ### /.web-server-pid ###< symfony/web-server-bundle ### - -.env - -/node_modules/ - -/public/* -!/public/assets/.gitkeep -!/public/bundles/.gitkeep -!/public/media/image/.gitkeep -!/public/app.php -!/public/app_dev.php -!/public/app_test.php diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php new file mode 100644 index 0000000..ae3c9d1 --- /dev/null +++ b/tests/Application/Kernel.php @@ -0,0 +1,106 @@ +getProjectDir() . '/var/cache/' . $this->environment; + } + + public function getLogDir(): string + { + return $this->getProjectDir() . '/var/log'; + } + + public function registerBundles(): iterable + { + $contents = require $this->getProjectDir() . '/config/bundles.php'; + foreach ($contents as $class => $envs) { + if (isset($envs['all']) || isset($envs[$this->environment])) { + yield new $class(); + } + } + } + + protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void + { + $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php')); + $container->setParameter('container.dumper.inline_class_loader', true); + $confDir = $this->getProjectDir() . '/config'; + + $loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob'); + $loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); + $loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); + $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); + } + + protected function configureRoutes(RouteCollectionBuilder $routes): void + { + $confDir = $this->getProjectDir() . '/config'; + + $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob'); + $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob'); + $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob'); + } + + protected function getContainerBaseClass(): string + { + if ($this->isTestEnvironment()) { + return MockerContainer::class; + } + + return parent::getContainerBaseClass(); + } + + protected function getContainerLoader(ContainerInterface $container): LoaderInterface + { + /** @var ContainerBuilder $container */ + Assert::isInstanceOf($container, ContainerBuilder::class); + + $locator = new FileLocator($this, $this->getRootDir() . '/Resources'); + $resolver = new LoaderResolver(array( + new XmlFileLoader($container, $locator), + new YamlFileLoader($container, $locator), + new IniFileLoader($container, $locator), + new PhpFileLoader($container, $locator), + new GlobFileLoader($container, $locator), + new DirectoryLoader($container, $locator), + new ClosureLoader($container), + )); + + return new DelegatingLoader($resolver); + } + + private function isTestEnvironment(): bool + { + return 0 === strpos($this->getEnvironment(), 'test'); + } +} diff --git a/tests/Application/bin/console b/tests/Application/bin/console index abe95b0..619ba73 100755 --- a/tests/Application/bin/console +++ b/tests/Application/bin/console @@ -1,32 +1,31 @@ #!/usr/bin/env php load(__DIR__.'/../.env'); +$input = new ArgvInput(); +if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) { + putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); } -$input = new ArgvInput(); -$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true); -$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true); +if ($input->hasParameterOption('--no-debug', true)) { + putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); +} + +require dirname(__DIR__).'/config/bootstrap.php'; -if ($debug) { +if ($_SERVER['APP_DEBUG']) { umask(0000); if (class_exists(Debug::class)) { @@ -34,6 +33,6 @@ if ($debug) { } } -$kernel = new Kernel($env, $debug); +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $application = new Application($kernel); $application->run($input); diff --git a/tests/Application/composer.json b/tests/Application/composer.json new file mode 100644 index 0000000..326735f --- /dev/null +++ b/tests/Application/composer.json @@ -0,0 +1,5 @@ +{ + "name": "sylius/plugin-skeleton-test-application", + "description": "Sylius application for plugin testing purposes (composer.json needed for project dir resolving)", + "license": "MIT" +} diff --git a/tests/Application/config/bootstrap.php b/tests/Application/config/bootstrap.php new file mode 100644 index 0000000..6bb0207 --- /dev/null +++ b/tests/Application/config/bootstrap.php @@ -0,0 +1,21 @@ +=1.2) +if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) { + $_SERVER += $env; + $_ENV += $env; +} elseif (!class_exists(Dotenv::class)) { + throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); +} else { + // load all the .env files + (new Dotenv())->loadEnv(dirname(__DIR__).'/.env'); +} + +$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; +$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; +$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index b363a5b..73ed52c 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -3,61 +3,61 @@ declare(strict_types=1); return [ - Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], - Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true], - Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], - Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], - Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], - Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true], - Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], - Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], - Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], - Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true], - Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true, 'test' => true], + Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], + Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], + Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], + Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true], + Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], + Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], + Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true], + Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], + Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], + Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], + Sylius\Bundle\LocaleBundle\SyliusLocaleBundle::class => ['all' => true], + Sylius\Bundle\ProductBundle\SyliusProductBundle::class => ['all' => true], + Sylius\Bundle\ChannelBundle\SyliusChannelBundle::class => ['all' => true], + Sylius\Bundle\AttributeBundle\SyliusAttributeBundle::class => ['all' => true], + Sylius\Bundle\TaxationBundle\SyliusTaxationBundle::class => ['all' => true], + Sylius\Bundle\ShippingBundle\SyliusShippingBundle::class => ['all' => true], + Sylius\Bundle\PaymentBundle\SyliusPaymentBundle::class => ['all' => true], + Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true], + Sylius\Bundle\PromotionBundle\SyliusPromotionBundle::class => ['all' => true], + Sylius\Bundle\AddressingBundle\SyliusAddressingBundle::class => ['all' => true], + Sylius\Bundle\InventoryBundle\SyliusInventoryBundle::class => ['all' => true], + Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle::class => ['all' => true], + Sylius\Bundle\UserBundle\SyliusUserBundle::class => ['all' => true], + Sylius\Bundle\CustomerBundle\SyliusCustomerBundle::class => ['all' => true], + Sylius\Bundle\UiBundle\SyliusUiBundle::class => ['all' => true], + Sylius\Bundle\ReviewBundle\SyliusReviewBundle::class => ['all' => true], + Sylius\Bundle\CoreBundle\SyliusCoreBundle::class => ['all' => true], + Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true], + Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], + winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true], + Sonata\CoreBundle\SonataCoreBundle::class => ['all' => true], + Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true], + Sonata\IntlBundle\SonataIntlBundle::class => ['all' => true], + Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true], + JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], + FOS\RestBundle\FOSRestBundle::class => ['all' => true], + Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true], + Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true], + Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true], + Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true], + Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], + WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true], + Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], + Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['all' => true], + Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true], + Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true], + Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true], + Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['all' => true], + Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true], + Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true], + FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true], + Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true], - Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], - Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], - Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], - Sylius\Bundle\LocaleBundle\SyliusLocaleBundle::class => ['all' => true], - Sylius\Bundle\ProductBundle\SyliusProductBundle::class => ['all' => true], - Sylius\Bundle\ChannelBundle\SyliusChannelBundle::class => ['all' => true], - Sylius\Bundle\AttributeBundle\SyliusAttributeBundle::class => ['all' => true], - Sylius\Bundle\TaxationBundle\SyliusTaxationBundle::class => ['all' => true], - Sylius\Bundle\ShippingBundle\SyliusShippingBundle::class => ['all' => true], - Sylius\Bundle\PaymentBundle\SyliusPaymentBundle::class => ['all' => true], - Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true], - Sylius\Bundle\PromotionBundle\SyliusPromotionBundle::class => ['all' => true], - Sylius\Bundle\AddressingBundle\SyliusAddressingBundle::class => ['all' => true], - Sylius\Bundle\InventoryBundle\SyliusInventoryBundle::class => ['all' => true], - Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle::class => ['all' => true], - Sylius\Bundle\UserBundle\SyliusUserBundle::class => ['all' => true], - Sylius\Bundle\CustomerBundle\SyliusCustomerBundle::class => ['all' => true], - Sylius\Bundle\UiBundle\SyliusUiBundle::class => ['all' => true], - Sylius\Bundle\ReviewBundle\SyliusReviewBundle::class => ['all' => true], - Sylius\Bundle\CoreBundle\SyliusCoreBundle::class => ['all' => true], - Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true], - Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], - winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true], - Sonata\CoreBundle\SonataCoreBundle::class => ['all' => true], - Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true], - Sonata\IntlBundle\SonataIntlBundle::class => ['all' => true], - Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true], - JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], - FOS\RestBundle\FOSRestBundle::class => ['all' => true], - Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true], - Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true], - Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true], - Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true], - Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], - WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true], - Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['all' => true], - Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true], - Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true], - Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true], - Sensio\Bundle\DistributionBundle\SensioDistributionBundle::class => ['all' => true], - - Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true], - Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true], - FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true], // Required by SyliusApiBundle - Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true], + Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], + Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], + FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true], + MangoSylius\PaymentFeePlugin\MangoSyliusPaymentFeePlugin::class => ['all' => true], ]; diff --git a/tests/Application/config/packages/sylius.yaml b/tests/Application/config/packages/_sylius.yaml similarity index 50% rename from tests/Application/config/packages/sylius.yaml rename to tests/Application/config/packages/_sylius.yaml index 37bb860..a1b48c6 100644 --- a/tests/Application/config/packages/sylius.yaml +++ b/tests/Application/config/packages/_sylius.yaml @@ -1,20 +1,16 @@ imports: - { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" } + - { resource: "@SyliusAdminBundle/Resources/config/app/config.yml" } - - { resource: "@SyliusShopBundle/Resources/config/app/config.yml" } - { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" } -parameters: - secret: '%kernel.secret%' + - { resource: "@SyliusShopBundle/Resources/config/app/config.yml" } + + - { resource: "@MangoSyliusPaymentFeePlugin/Resources/config/resources.yml" } -liip_imagine: - loaders: - default: - filesystem: - data_root: "%kernel.project_dir%/public/media/image" +parameters: + sylius_core.public_dir: '%kernel.project_dir%/public' -knp_gaufrette: - adapters: - sylius_image: - local: - directory: "%kernel.project_dir%/public/media/image" +sylius_shop: + product_grid: + include_all_descendants: true diff --git a/tests/Application/config/packages/dev/debug.yaml b/tests/Application/config/packages/dev/debug.yaml deleted file mode 100644 index 26d4e53..0000000 --- a/tests/Application/config/packages/dev/debug.yaml +++ /dev/null @@ -1,4 +0,0 @@ -debug: - # Forwards VarDumper Data clones to a centralized server allowing to inspect dumps on CLI or in your browser. - # See the "server:dump" command to start a new server. - dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%" diff --git a/tests/Application/config/packages/dev/easy_log_handler.yaml b/tests/Application/config/packages/dev/easy_log_handler.yaml deleted file mode 100644 index 27bfc60..0000000 --- a/tests/Application/config/packages/dev/easy_log_handler.yaml +++ /dev/null @@ -1,16 +0,0 @@ -services: - EasyCorp\EasyLog\EasyLogHandler: - public: false - arguments: ['%kernel.logs_dir%/%kernel.environment%.log'] - -#// FIXME: How to add this configuration automatically without messing up with the monolog configuration? -#monolog: -# handlers: -# buffered: -# type: buffer -# handler: easylog -# channels: ['!event'] -# level: debug -# easylog: -# type: service -# id: EasyCorp\EasyLog\EasyLogHandler diff --git a/tests/Application/config/packages/dev/framework.yaml b/tests/Application/config/packages/dev/framework.yaml new file mode 100644 index 0000000..4b116de --- /dev/null +++ b/tests/Application/config/packages/dev/framework.yaml @@ -0,0 +1,2 @@ +framework: + profiler: { only_exceptions: false } diff --git a/tests/Application/config/packages/dev/jms_serializer.yaml b/tests/Application/config/packages/dev/jms_serializer.yaml new file mode 100644 index 0000000..353e460 --- /dev/null +++ b/tests/Application/config/packages/dev/jms_serializer.yaml @@ -0,0 +1,7 @@ +jms_serializer: + visitors: + json: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/packages/dev/monolog.yaml b/tests/Application/config/packages/dev/monolog.yaml index b1998da..da2b092 100644 --- a/tests/Application/config/packages/dev/monolog.yaml +++ b/tests/Application/config/packages/dev/monolog.yaml @@ -4,16 +4,6 @@ monolog: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug - channels: ["!event"] - # uncomment to get logging in your browser - # you may have to allow bigger header sizes in your Web server configuration - #firephp: - # type: firephp - # level: info - #chromephp: - # type: chromephp - # level: info - console: - type: console - process_psr_3_messages: false - channels: ["!event", "!doctrine", "!console"] + firephp: + type: firephp + level: info diff --git a/tests/Application/config/packages/dev/swiftmailer.yaml b/tests/Application/config/packages/dev/swiftmailer.yaml index b98158e..f438078 100644 --- a/tests/Application/config/packages/dev/swiftmailer.yaml +++ b/tests/Application/config/packages/dev/swiftmailer.yaml @@ -1,4 +1,2 @@ -# See https://symfony.com/doc/current/email/dev_environment.html swiftmailer: - # send all emails to a specific address - #delivery_addresses: ['me@example.com'] + disable_delivery: true diff --git a/tests/Application/config/packages/dev/web_profiler.yaml b/tests/Application/config/packages/dev/web_profiler.yaml index e92166a..1f1cb2b 100644 --- a/tests/Application/config/packages/dev/web_profiler.yaml +++ b/tests/Application/config/packages/dev/web_profiler.yaml @@ -1,6 +1,3 @@ web_profiler: toolbar: true intercept_redirects: false - -framework: - profiler: { only_exceptions: false } diff --git a/tests/Application/config/packages/doctrine.yaml b/tests/Application/config/packages/doctrine.yaml index be675dc..f51ba5a 100644 --- a/tests/Application/config/packages/doctrine.yaml +++ b/tests/Application/config/packages/doctrine.yaml @@ -7,18 +7,8 @@ parameters: doctrine: dbal: - # configure these for your database server - driver: 'pdo_pgsql' - server_version: '10.5' + driver: 'pdo_mysql' + server_version: '5.7' + charset: UTF8 + url: '%env(resolve:DATABASE_URL)%' - orm: - auto_generate_proxy_classes: '%kernel.debug%' - naming_strategy: doctrine.orm.naming_strategy.underscore - auto_mapping: true - mappings: - App: - is_bundle: false - type: annotation - dir: '%kernel.project_dir%/src/Entity' - prefix: 'App\Entity' - alias: App diff --git a/tests/Application/config/packages/doctrine_migrations.yaml b/tests/Application/config/packages/doctrine_migrations.yaml index 3bf0fbc..c0a1202 100644 --- a/tests/Application/config/packages/doctrine_migrations.yaml +++ b/tests/Application/config/packages/doctrine_migrations.yaml @@ -1,5 +1,5 @@ doctrine_migrations: - dir_name: '%kernel.project_dir%/src/Migrations' - # namespace is arbitrary but should be different from App\Migrations - # as migrations classes should NOT be autoloaded + dir_name: "%kernel.project_dir%/src/Migrations" + + # Namespace is arbitrary but should be different from App\Migrations as migrations classes should NOT be autoloaded namespace: DoctrineMigrations diff --git a/tests/Application/config/packages/fos_rest.yaml b/tests/Application/config/packages/fos_rest.yaml new file mode 100644 index 0000000..a72eef7 --- /dev/null +++ b/tests/Application/config/packages/fos_rest.yaml @@ -0,0 +1,11 @@ +fos_rest: + exception: true + view: + formats: + json: true + xml: true + empty_content: 204 + format_listener: + rules: + - { path: '^/api/.*', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true } + - { path: '^/', stop: true } diff --git a/tests/Application/config/packages/framework.yaml b/tests/Application/config/packages/framework.yaml index 0c66a8e..e74ed81 100644 --- a/tests/Application/config/packages/framework.yaml +++ b/tests/Application/config/packages/framework.yaml @@ -1,35 +1,7 @@ framework: secret: '%env(APP_SECRET)%' - #default_locale: en - #csrf_protection: true - #http_method_override: true - - #esi: true - #fragments: true - php_errors: - log: true - - cache: - # Put the unique name of your app here: the prefix seed - # is used to compute stable namespaces for cache keys. - #prefix_seed: your_vendor_name/app_name - - # The app cache caches to the filesystem by default. - # Other options include: - - # Redis - #app: cache.adapter.redis - #default_redis_provider: redis://localhost - - # APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues) - #app: cache.adapter.apcu - - translator: { fallbacks: ["%locale%", "en"] } form: true csrf_protection: true - validation: { enable_annotations: true } templating: { engines: ["twig"] } - default_locale: "%locale%" session: - storage_id: session.storage.mock_file - test: ~ + handler_id: ~ diff --git a/tests/Application/config/packages/jms_serializer.yaml b/tests/Application/config/packages/jms_serializer.yaml new file mode 100644 index 0000000..64dd8d1 --- /dev/null +++ b/tests/Application/config/packages/jms_serializer.yaml @@ -0,0 +1,4 @@ +jms_serializer: + visitors: + xml: + format_output: '%kernel.debug%' diff --git a/tests/Application/config/packages/liip_imagine.yaml b/tests/Application/config/packages/liip_imagine.yaml new file mode 100644 index 0000000..bb2e7ce --- /dev/null +++ b/tests/Application/config/packages/liip_imagine.yaml @@ -0,0 +1,6 @@ +liip_imagine: + resolvers: + default: + web_path: + web_root: "%kernel.project_dir%/public" + cache_prefix: "media/cache" diff --git a/tests/Application/config/packages/prod/jms_serializer.yaml b/tests/Application/config/packages/prod/jms_serializer.yaml new file mode 100644 index 0000000..bc97faf --- /dev/null +++ b/tests/Application/config/packages/prod/jms_serializer.yaml @@ -0,0 +1,6 @@ +jms_serializer: + visitors: + json: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/packages/prod/monolog.yaml b/tests/Application/config/packages/prod/monolog.yaml index 96dbf96..6461211 100644 --- a/tests/Application/config/packages/prod/monolog.yaml +++ b/tests/Application/config/packages/prod/monolog.yaml @@ -4,22 +4,7 @@ monolog: type: fingers_crossed action_level: error handler: nested - excluded_404s: - # regex: exclude all 404 errors from the logs - - ^/ nested: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug - console: - type: console - process_psr_3_messages: false - channels: ["!event", "!doctrine"] - deprecation: - type: stream - path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log" - deprecation_filter: - type: filter - handler: deprecation - max_level: info - channels: ["php"] diff --git a/tests/Application/config/packages/security.yaml b/tests/Application/config/packages/security.yaml index 9b550a2..830b03d 100644 --- a/tests/Application/config/packages/security.yaml +++ b/tests/Application/config/packages/security.yaml @@ -1,4 +1,3 @@ -# This file is from sylius/sylius/app/config/security.yml parameters: sylius.security.admin_regex: "^/admin" sylius.security.api_regex: "^/api" @@ -30,7 +29,7 @@ security: csrf_parameter: _csrf_admin_security_token csrf_token_id: admin_authenticate remember_me: - secret: "%secret%" + secret: "%env(APP_SECRET)%" path: /admin name: APP_ADMIN_REMEMBER_ME lifetime: 31536000 @@ -70,7 +69,7 @@ security: csrf_parameter: _csrf_shop_security_token csrf_token_id: shop_authenticate remember_me: - secret: "%secret%" + secret: "%env(APP_SECRET)%" name: APP_SHOP_REMEMBER_ME lifetime: 31536000 remember_me_parameter: _remember_me diff --git a/tests/Application/config/packages/security_checker.yaml b/tests/Application/config/packages/security_checker.yaml new file mode 100644 index 0000000..0f9cf00 --- /dev/null +++ b/tests/Application/config/packages/security_checker.yaml @@ -0,0 +1,9 @@ +services: + SensioLabs\Security\SecurityChecker: + public: false + + SensioLabs\Security\Command\SecurityCheckerCommand: + arguments: ['@SensioLabs\Security\SecurityChecker'] + public: false + tags: + - { name: console.command, command: 'security:check' } diff --git a/tests/Application/config/packages/sonata_core.yaml b/tests/Application/config/packages/sonata_core.yaml new file mode 100644 index 0000000..e9a6e89 --- /dev/null +++ b/tests/Application/config/packages/sonata_core.yaml @@ -0,0 +1,4 @@ +sonata_core: + form: + mapping: + enabled: false diff --git a/tests/Application/config/packages/staging/monolog.yaml b/tests/Application/config/packages/staging/monolog.yaml new file mode 100644 index 0000000..6461211 --- /dev/null +++ b/tests/Application/config/packages/staging/monolog.yaml @@ -0,0 +1,10 @@ +monolog: + handlers: + main: + type: fingers_crossed + action_level: error + handler: nested + nested: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: debug diff --git a/tests/Application/config/packages/staging/swiftmailer.yaml b/tests/Application/config/packages/staging/swiftmailer.yaml new file mode 100644 index 0000000..f438078 --- /dev/null +++ b/tests/Application/config/packages/staging/swiftmailer.yaml @@ -0,0 +1,2 @@ +swiftmailer: + disable_delivery: true diff --git a/tests/Application/config/packages/stof_doctrine_extensions.yaml b/tests/Application/config/packages/stof_doctrine_extensions.yaml new file mode 100644 index 0000000..7770f74 --- /dev/null +++ b/tests/Application/config/packages/stof_doctrine_extensions.yaml @@ -0,0 +1,4 @@ +# Read the documentation: https://symfony.com/doc/current/bundles/StofDoctrineExtensionsBundle/index.html +# See the official DoctrineExtensions documentation for more details: https://github.com/Atlantic18/DoctrineExtensions/tree/master/doc/ +stof_doctrine_extensions: + default_locale: '%locale%' diff --git a/tests/Application/config/packages/swiftmailer.yaml b/tests/Application/config/packages/swiftmailer.yaml index cae6508..3bab0d3 100644 --- a/tests/Application/config/packages/swiftmailer.yaml +++ b/tests/Application/config/packages/swiftmailer.yaml @@ -1,3 +1,2 @@ swiftmailer: url: '%env(MAILER_URL)%' - spool: { type: 'memory' } diff --git a/tests/Application/config/packages/test/framework.yaml b/tests/Application/config/packages/test/framework.yaml index d051c84..76d7e5e 100644 --- a/tests/Application/config/packages/test/framework.yaml +++ b/tests/Application/config/packages/test/framework.yaml @@ -1,4 +1,4 @@ framework: - test: true + test: ~ session: storage_id: session.storage.mock_file diff --git a/tests/Application/config/packages/test/monolog.yaml b/tests/Application/config/packages/test/monolog.yaml index 2762653..7e2b9e3 100644 --- a/tests/Application/config/packages/test/monolog.yaml +++ b/tests/Application/config/packages/test/monolog.yaml @@ -3,5 +3,4 @@ monolog: main: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" - level: debug - channels: ["!event"] + level: error diff --git a/tests/Application/config/packages/test/swiftmailer.yaml b/tests/Application/config/packages/test/swiftmailer.yaml index f438078..c438f4b 100644 --- a/tests/Application/config/packages/test/swiftmailer.yaml +++ b/tests/Application/config/packages/test/swiftmailer.yaml @@ -1,2 +1,6 @@ swiftmailer: disable_delivery: true + logging: true + spool: + type: file + path: "%kernel.cache_dir%/spool" diff --git a/tests/Application/config/packages/test/sylius_theme.yaml b/tests/Application/config/packages/test/sylius_theme.yaml new file mode 100644 index 0000000..4d34199 --- /dev/null +++ b/tests/Application/config/packages/test/sylius_theme.yaml @@ -0,0 +1,3 @@ +sylius_theme: + sources: + test: ~ diff --git a/tests/Application/config/packages/test_cached/doctrine.yaml b/tests/Application/config/packages/test_cached/doctrine.yaml new file mode 100644 index 0000000..4952860 --- /dev/null +++ b/tests/Application/config/packages/test_cached/doctrine.yaml @@ -0,0 +1,16 @@ +doctrine: + orm: + entity_managers: + default: + result_cache_driver: + type: memcached + host: localhost + port: 11211 + query_cache_driver: + type: memcached + host: localhost + port: 11211 + metadata_cache_driver: + type: memcached + host: localhost + port: 11211 diff --git a/tests/Application/config/packages/test_cached/fos_rest.yaml b/tests/Application/config/packages/test_cached/fos_rest.yaml new file mode 100644 index 0000000..2b4189d --- /dev/null +++ b/tests/Application/config/packages/test_cached/fos_rest.yaml @@ -0,0 +1,3 @@ +fos_rest: + exception: + debug: true diff --git a/tests/Application/config/packages/test_cached/framework.yaml b/tests/Application/config/packages/test_cached/framework.yaml new file mode 100644 index 0000000..76d7e5e --- /dev/null +++ b/tests/Application/config/packages/test_cached/framework.yaml @@ -0,0 +1,4 @@ +framework: + test: ~ + session: + storage_id: session.storage.mock_file diff --git a/tests/Application/config/packages/test_cached/monolog.yaml b/tests/Application/config/packages/test_cached/monolog.yaml new file mode 100644 index 0000000..7e2b9e3 --- /dev/null +++ b/tests/Application/config/packages/test_cached/monolog.yaml @@ -0,0 +1,6 @@ +monolog: + handlers: + main: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: error diff --git a/tests/Application/config/packages/test_cached/swiftmailer.yaml b/tests/Application/config/packages/test_cached/swiftmailer.yaml new file mode 100644 index 0000000..c438f4b --- /dev/null +++ b/tests/Application/config/packages/test_cached/swiftmailer.yaml @@ -0,0 +1,6 @@ +swiftmailer: + disable_delivery: true + logging: true + spool: + type: file + path: "%kernel.cache_dir%/spool" diff --git a/tests/Application/config/packages/test_cached/sylius_channel.yaml b/tests/Application/config/packages/test_cached/sylius_channel.yaml new file mode 100644 index 0000000..bab83ef --- /dev/null +++ b/tests/Application/config/packages/test_cached/sylius_channel.yaml @@ -0,0 +1,2 @@ +sylius_channel: + debug: true diff --git a/tests/Application/config/packages/test_cached/sylius_theme.yaml b/tests/Application/config/packages/test_cached/sylius_theme.yaml new file mode 100644 index 0000000..4d34199 --- /dev/null +++ b/tests/Application/config/packages/test_cached/sylius_theme.yaml @@ -0,0 +1,3 @@ +sylius_theme: + sources: + test: ~ diff --git a/tests/Application/config/packages/test_cached/twig.yaml b/tests/Application/config/packages/test_cached/twig.yaml new file mode 100644 index 0000000..8c6e0b4 --- /dev/null +++ b/tests/Application/config/packages/test_cached/twig.yaml @@ -0,0 +1,2 @@ +twig: + strict_variables: true diff --git a/tests/Application/config/packages/translation.yaml b/tests/Application/config/packages/translation.yaml index 1edfbe2..1f4f966 100644 --- a/tests/Application/config/packages/translation.yaml +++ b/tests/Application/config/packages/translation.yaml @@ -5,3 +5,4 @@ framework: - '%kernel.project_dir%/translations' fallbacks: - '%locale%' + - 'en' diff --git a/tests/Application/config/packages/twig_extensions.yaml b/tests/Application/config/packages/twig_extensions.yaml new file mode 100644 index 0000000..0881cc9 --- /dev/null +++ b/tests/Application/config/packages/twig_extensions.yaml @@ -0,0 +1,11 @@ +services: + _defaults: + public: false + autowire: true + autoconfigure: true + + # Uncomment any lines below to activate that Twig extension + #Twig\Extensions\ArrayExtension: ~ + #Twig\Extensions\DateExtension: ~ + #Twig\Extensions\IntlExtension: ~ + #Twig\Extensions\TextExtension: ~ diff --git a/tests/Application/config/packages/validator.yaml b/tests/Application/config/packages/validator.yaml index a695e1a..61807db 100644 --- a/tests/Application/config/packages/validator.yaml +++ b/tests/Application/config/packages/validator.yaml @@ -1,3 +1,3 @@ framework: validation: - email_validation_mode: html5 + enable_annotations: true diff --git a/tests/Application/config/routes.yaml b/tests/Application/config/routes.yaml index 7fd9bad..8b13789 100644 --- a/tests/Application/config/routes.yaml +++ b/tests/Application/config/routes.yaml @@ -1,2 +1 @@ -sylius: - resource: "../../../vendor/sylius/sylius/app/config/routing.yml" + diff --git a/tests/Application/config/routes/annotations.yaml b/tests/Application/config/routes/annotations.yaml deleted file mode 100644 index d49a502..0000000 --- a/tests/Application/config/routes/annotations.yaml +++ /dev/null @@ -1,3 +0,0 @@ -controllers: - resource: ../../src/Controller/ - type: annotation diff --git a/tests/Application/config/routes/dev/web_profiler.yaml b/tests/Application/config/routes/dev/web_profiler.yaml index c82beff..3e79dc2 100644 --- a/tests/Application/config/routes/dev/web_profiler.yaml +++ b/tests/Application/config/routes/dev/web_profiler.yaml @@ -1,7 +1,7 @@ -web_profiler_wdt: - resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml' - prefix: /_wdt +_wdt: + resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml" + prefix: /_wdt -web_profiler_profiler: - resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml' - prefix: /_profiler +_profiler: + resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml" + prefix: /_profiler diff --git a/tests/Application/config/routes/liip_imagine.yaml b/tests/Application/config/routes/liip_imagine.yaml new file mode 100644 index 0000000..201cbd5 --- /dev/null +++ b/tests/Application/config/routes/liip_imagine.yaml @@ -0,0 +1,2 @@ +_liip_imagine: + resource: "@LiipImagineBundle/Resources/config/routing.yaml" diff --git a/tests/Application/config/routes/sylius_admin.yaml b/tests/Application/config/routes/sylius_admin.yaml new file mode 100644 index 0000000..1ba48d6 --- /dev/null +++ b/tests/Application/config/routes/sylius_admin.yaml @@ -0,0 +1,3 @@ +sylius_admin: + resource: "@SyliusAdminBundle/Resources/config/routing.yml" + prefix: /admin diff --git a/tests/Application/config/routes/sylius_admin_api.yaml b/tests/Application/config/routes/sylius_admin_api.yaml new file mode 100644 index 0000000..80aed45 --- /dev/null +++ b/tests/Application/config/routes/sylius_admin_api.yaml @@ -0,0 +1,3 @@ +sylius_admin_api: + resource: "@SyliusAdminApiBundle/Resources/config/routing.yml" + prefix: /api diff --git a/tests/Application/config/routes/sylius_shop.yaml b/tests/Application/config/routes/sylius_shop.yaml new file mode 100644 index 0000000..8818568 --- /dev/null +++ b/tests/Application/config/routes/sylius_shop.yaml @@ -0,0 +1,14 @@ +sylius_shop: + resource: "@SyliusShopBundle/Resources/config/routing.yml" + prefix: /{_locale} + requirements: + _locale: ^[a-z]{2}(?:_[A-Z]{2})?$ + +sylius_shop_payum: + resource: "@SyliusShopBundle/Resources/config/routing/payum.yml" + +sylius_shop_default_locale: + path: / + methods: [GET] + defaults: + _controller: sylius.controller.shop.locale_switch:switchAction diff --git a/tests/Application/config/services.yaml b/tests/Application/config/services.yaml index 776e6ce..615506e 100644 --- a/tests/Application/config/services.yaml +++ b/tests/Application/config/services.yaml @@ -1,31 +1,4 @@ -# This file is the entry point to configure your own services. -# Files in the packages/ subdirectory configure your dependencies. - # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: - locale: 'en' - -services: - # default configuration for services in *this* file - _defaults: - autowire: true # Automatically injects dependencies in your services. - autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. - public: false # Allows optimizing the container by removing unused services; this also means - # fetching services directly from the container via $container->get() won't work. - # The best practice is to be explicit about your dependencies anyway. - - # makes classes in src/ available to be used as services - # this creates a service per class whose id is the fully-qualified class name - App\: - resource: '../src/*' - exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}' - - # controllers are imported separately to make sure services can be injected - # as action arguments even if you don't extend any base controller class - App\Controller\: - resource: '../src/Controller' - tags: ['controller.service_arguments'] - - # add more service definitions when explicit configuration is needed - # please note that last definitions always *replace* previous ones + locale: en_US diff --git a/tests/Application/config/services_test.yaml b/tests/Application/config/services_test.yaml new file mode 100644 index 0000000..d9b02e3 --- /dev/null +++ b/tests/Application/config/services_test.yaml @@ -0,0 +1,3 @@ +imports: + - { resource: "../../Behat/Resources/services.xml" } + - { resource: "../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml" } diff --git a/tests/Application/gulpfile.babel.js b/tests/Application/gulpfile.babel.js index 2016a94..5920316 100644 --- a/tests/Application/gulpfile.babel.js +++ b/tests/Application/gulpfile.babel.js @@ -3,49 +3,49 @@ import gulp from 'gulp'; import yargs from 'yargs'; const { argv } = yargs - .options({ - rootPath: { - description: ' path to web assets directory', - type: 'string', - requiresArg: true, - required: false, - }, - nodeModulesPath: { - description: ' path to node_modules directory', - type: 'string', - requiresArg: true, - required: false, - }, - }); + .options({ + rootPath: { + description: ' path to public assets directory', + type: 'string', + requiresArg: true, + required: false, + }, + nodeModulesPath: { + description: ' path to node_modules directory', + type: 'string', + requiresArg: true, + required: false, + }, + }); const config = [ - '--rootPath', - argv.rootPath || '../../../../../../../tests/Application/web/assets', - '--nodeModulesPath', - argv.nodeModulesPath || '../../../../../../../tests/Application/node_modules', + '--rootPath', + argv.rootPath || '../../../../../../../tests/Application/public/assets', + '--nodeModulesPath', + argv.nodeModulesPath || '../../../../../../../tests/Application/node_modules', ]; export const buildAdmin = function buildAdmin() { - return gulp.src('../../vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/gulpfile.babel.js', { read: false }) - .pipe(chug({ args: config, tasks: 'build' })); + return gulp.src('../../vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/gulpfile.babel.js', { read: false }) + .pipe(chug({ args: config, tasks: 'build' })); }; buildAdmin.description = 'Build admin assets.'; export const watchAdmin = function watchAdmin() { - return gulp.src('../../vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/gulpfile.babel.js', { read: false }) - .pipe(chug({ args: config, tasks: 'watch' })); + return gulp.src('../../vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/gulpfile.babel.js', { read: false }) + .pipe(chug({ args: config, tasks: 'watch' })); }; watchAdmin.description = 'Watch admin asset sources and rebuild on changes.'; export const buildShop = function buildShop() { - return gulp.src('../../vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/gulpfile.babel.js', { read: false }) - .pipe(chug({ args: config, tasks: 'build' })); + return gulp.src('../../vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/gulpfile.babel.js', { read: false }) + .pipe(chug({ args: config, tasks: 'build' })); }; buildShop.description = 'Build shop assets.'; export const watchShop = function watchShop() { - return gulp.src('../../vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/gulpfile.babel.js', { read: false }) - .pipe(chug({ args: config, tasks: 'watch' })); + return gulp.src('../../vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/gulpfile.babel.js', { read: false }) + .pipe(chug({ args: config, tasks: 'watch' })); }; watchShop.description = 'Watch shop asset sources and rebuild on changes.'; diff --git a/tests/Application/package.json b/tests/Application/package.json index 01bc4b4..14072b2 100644 --- a/tests/Application/package.json +++ b/tests/Application/package.json @@ -1,55 +1,53 @@ { - "dependencies": { - "babel-polyfill": "^6.26.0", - "jquery": "^3.2.0", - "lightbox2": "^2.9.0", - "semantic-ui-css": "^2.2.0" - }, - "devDependencies": { - "babel-core": "^6.26.3", - "babel-plugin-external-helpers": "^6.22.0", - "babel-plugin-module-resolver": "^3.1.1", - "babel-plugin-transform-object-rest-spread": "^6.26.0", - "babel-plugin-transform-runtime": "^6.23.0", - "babel-preset-env": "^1.7.0", - "babel-register": "^6.26.0", - "dedent": "^0.7.0", - "eslint": "^4.19.1", - "eslint-config-airbnb-base": "^12.1.0", - "eslint-import-resolver-babel-module": "^4.0.0", - "eslint-plugin-import": "^2.12.0", - "fast-async": "^6.3.7", - "gulp": "^4.0.0", - "gulp-chug": "^0.5", - "gulp-concat": "^2.6.0", - "gulp-debug": "^2.1.2", - "gulp-if": "^2.0.0", - "gulp-livereload": "^3.8.1", - "gulp-order": "^1.1.1", - "gulp-sass": "^4.0.1", - "gulp-sourcemaps": "^1.6.0", - "gulp-uglify": "^3.0.1", - "gulp-uglifycss": "^1.0.5", - "merge-stream": "^1.0.0", - "rollup": "^0.60.7", - "rollup-plugin-babel": "^3.0.4", - "rollup-plugin-commonjs": "^9.1.3", - "rollup-plugin-inject": "^2.0.0", - "rollup-plugin-node-resolve": "^3.3.0", - "rollup-plugin-uglify": "^4.0.0", - "upath": "^1.1.0", - "yargs": "^6.4.0" - }, - "scripts": { - "build": "gulp build", - "gulp": "gulp build", - "lint": "yarn lint:js", - "lint:js": "eslint gulpfile.babel.js" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/Sylius/Sylius.git" - }, - "author": "Paweł Jędrzejewski", - "license": "MIT" + "dependencies": { + "babel-polyfill": "^6.26.0", + "jquery": "^3.2.0", + "lightbox2": "^2.9.0", + "semantic-ui-css": "^2.2.0" + }, + "devDependencies": { + "babel-core": "^6.26.3", + "babel-plugin-external-helpers": "^6.22.0", + "babel-plugin-module-resolver": "^3.1.1", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-preset-env": "^1.7.0", + "babel-register": "^6.26.0", + "dedent": "^0.7.0", + "eslint": "^4.19.1", + "eslint-config-airbnb-base": "^12.1.0", + "eslint-import-resolver-babel-module": "^4.0.0", + "eslint-plugin-import": "^2.12.0", + "fast-async": "^6.3.7", + "gulp": "^4.0.0", + "gulp-chug": "^0.5", + "gulp-concat": "^2.6.0", + "gulp-debug": "^2.1.2", + "gulp-if": "^2.0.0", + "gulp-livereload": "^3.8.1", + "gulp-order": "^1.1.1", + "gulp-sass": "^4.0.1", + "gulp-sourcemaps": "^1.6.0", + "gulp-uglifycss": "^1.0.5", + "merge-stream": "^1.0.0", + "rollup": "^0.60.7", + "rollup-plugin-babel": "^3.0.4", + "rollup-plugin-commonjs": "^9.1.3", + "rollup-plugin-inject": "^2.0.0", + "rollup-plugin-node-resolve": "^3.3.0", + "rollup-plugin-uglify": "^4.0.0", + "upath": "^1.1.0", + "yargs": "^6.4.0" + }, + "scripts": { + "build": "gulp build", + "gulp": "gulp build", + "lint": "yarn lint:js", + "lint:js": "eslint gulpfile.babel.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Sylius/Sylius.git" + }, + "author": "Paweł Jędrzejewski", + "license": "MIT" } diff --git a/tests/Application/public/.htaccess b/tests/Application/public/.htaccess new file mode 100644 index 0000000..99ed00d --- /dev/null +++ b/tests/Application/public/.htaccess @@ -0,0 +1,25 @@ +DirectoryIndex app.php + + + RewriteEngine On + + RewriteCond %{HTTP:Authorization} ^(.*) + RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] + + RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ + RewriteRule ^(.*) - [E=BASE:%1] + + RewriteCond %{ENV:REDIRECT_STATUS} ^$ + RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] + + RewriteCond %{REQUEST_FILENAME} -f + RewriteRule .? - [L] + + RewriteRule .? %{ENV:BASE}/index.php [L] + + + + + RedirectMatch 302 ^/$ /index.php/ + + diff --git a/tests/Application/public/favicon.ico b/tests/Application/public/favicon.ico new file mode 100644 index 0000000..592f7a8 Binary files /dev/null and b/tests/Application/public/favicon.ico differ diff --git a/tests/Application/public/index.php b/tests/Application/public/index.php new file mode 100644 index 0000000..dc5a4c7 --- /dev/null +++ b/tests/Application/public/index.php @@ -0,0 +1,27 @@ +handle($request); +$response->send(); +$kernel->terminate($request, $response); diff --git a/tests/Application/src/Controller/.gitignore b/tests/Application/public/media/image/.gitignore similarity index 100% rename from tests/Application/src/Controller/.gitignore rename to tests/Application/public/media/image/.gitignore diff --git a/tests/Application/public/robots.txt b/tests/Application/public/robots.txt new file mode 100644 index 0000000..214e411 --- /dev/null +++ b/tests/Application/public/robots.txt @@ -0,0 +1,4 @@ +# www.robotstxt.org/ +# www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449 + +User-agent: * diff --git a/tests/Application/src/Kernel.php b/tests/Application/src/Kernel.php deleted file mode 100644 index beab826..0000000 --- a/tests/Application/src/Kernel.php +++ /dev/null @@ -1,68 +0,0 @@ -getProjectDir() . '/var/cache/' . $this->environment; - } - - public function getLogDir() - { - return $this->getProjectDir() . '/var/log'; - } - - public function registerBundles() - { - $contents = require $this->getProjectDir() . '/config/bundles.php'; - foreach ($contents as $class => $envs) { - if (isset($envs['all']) || isset($envs[$this->environment])) { - yield new $class(); - } - } - } - - public function getProjectDir(): string - { - return \dirname(__DIR__); - } - - protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) - { - $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php')); - // Feel free to remove the "container.autowiring.strict_mode" parameter - // if you are using symfony/dependency-injection 4.0+ as it's the default behavior - $container->setParameter('container.autowiring.strict_mode', true); - $container->setParameter('container.dumper.inline_class_loader', true); - $confDir = $this->getProjectDir() . '/config'; - - $loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob'); - $loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); - $loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); - $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); - } - - protected function configureRoutes(RouteCollectionBuilder $routes) - { - $confDir = $this->getProjectDir() . '/config'; - - $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob'); - $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob'); - $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob'); - } -} diff --git a/tests/Application/src/Migrations/.gitignore b/tests/Application/src/Migrations/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Application/src/Repository/.gitignore b/tests/Application/src/Repository/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Application/symfony.lock b/tests/Application/symfony.lock deleted file mode 100644 index 1afc8ef..0000000 --- a/tests/Application/symfony.lock +++ /dev/null @@ -1,401 +0,0 @@ -{ - "doctrine/annotations": { - "version": "1.0", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "1.0", - "ref": "cb4152ebcadbe620ea2261da1a1c5a9b8cea7672" - } - }, - "doctrine/cache": { - "version": "v1.7.1" - }, - "doctrine/collections": { - "version": "v1.5.0" - }, - "doctrine/common": { - "version": "v2.9.0" - }, - "doctrine/dbal": { - "version": "v2.8.0" - }, - "doctrine/doctrine-bundle": { - "version": "1.6", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "1.6", - "ref": "ae205d5114e719deb64d2110f56ef910787d1e04" - } - }, - "doctrine/doctrine-cache-bundle": { - "version": "1.3.3" - }, - "doctrine/doctrine-migrations-bundle": { - "version": "1.2", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "1.2", - "ref": "c1431086fec31f17fbcfe6d6d7e92059458facc1" - } - }, - "doctrine/event-manager": { - "version": "v1.0.0" - }, - "doctrine/inflector": { - "version": "v1.3.0" - }, - "doctrine/instantiator": { - "version": "1.1.0" - }, - "doctrine/lexer": { - "version": "v1.0.1" - }, - "doctrine/migrations": { - "version": "v1.8.1" - }, - "doctrine/orm": { - "version": "v2.6.2" - }, - "doctrine/persistence": { - "version": "v1.0.0" - }, - "doctrine/reflection": { - "version": "v1.0.0" - }, - "easycorp/easy-log-handler": { - "version": "1.0", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "1.0", - "ref": "70062abc2cd58794d2a90274502f81b55cd9951b" - } - }, - "egulias/email-validator": { - "version": "2.1.4" - }, - "fig/link-util": { - "version": "1.0.0" - }, - "jdorn/sql-formatter": { - "version": "v1.2.17" - }, - "monolog/monolog": { - "version": "1.23.0" - }, - "nikic/php-parser": { - "version": "v4.0.3" - }, - "ocramius/proxy-manager": { - "version": "2.1.1" - }, - "phpdocumentor/reflection-common": { - "version": "1.0.1" - }, - "phpdocumentor/reflection-docblock": { - "version": "4.3.0" - }, - "phpdocumentor/type-resolver": { - "version": "0.4.0" - }, - "psr/cache": { - "version": "1.0.1" - }, - "psr/container": { - "version": "1.0.0" - }, - "psr/link": { - "version": "1.0.0" - }, - "psr/log": { - "version": "1.0.2" - }, - "psr/simple-cache": { - "version": "1.0.1" - }, - "sensio/framework-extra-bundle": { - "version": "5.2", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "5.2", - "ref": "fb7e19da7f013d0d422fa9bce16f5c510e27609b" - } - }, - "swiftmailer/swiftmailer": { - "version": "v6.1.2" - }, - "symfony/asset": { - "version": "v4.1.3" - }, - "symfony/browser-kit": { - "version": "v4.1.3" - }, - "symfony/cache": { - "version": "v4.1.3" - }, - "symfony/config": { - "version": "v4.1.3" - }, - "symfony/console": { - "version": "3.3", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "3.3", - "ref": "e3868d2f4a5104f19f844fe551099a00c6562527" - } - }, - "symfony/css-selector": { - "version": "v4.1.3" - }, - "symfony/debug": { - "version": "v4.1.3" - }, - "symfony/debug-bundle": { - "version": "4.1", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "4.1", - "ref": "f8863cbad2f2e58c4b65fa1eac892ab189971bea" - } - }, - "symfony/debug-pack": { - "version": "v1.0.6" - }, - "symfony/dependency-injection": { - "version": "v4.1.3" - }, - "symfony/doctrine-bridge": { - "version": "v4.1.3" - }, - "symfony/dom-crawler": { - "version": "v4.1.3" - }, - "symfony/dotenv": { - "version": "v4.1.3" - }, - "symfony/event-dispatcher": { - "version": "v4.1.3" - }, - "symfony/expression-language": { - "version": "v4.1.3" - }, - "symfony/filesystem": { - "version": "v4.1.3" - }, - "symfony/finder": { - "version": "v4.1.3" - }, - "symfony/flex": { - "version": "1.0", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "1.0", - "ref": "e921bdbfe20cdefa3b82f379d1cd36df1bc8d115" - } - }, - "symfony/form": { - "version": "v4.1.3" - }, - "symfony/framework-bundle": { - "version": "3.3", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "3.3", - "ref": "87c585d24de9f43bca80ebcfd5cf5cb39445d95f" - } - }, - "symfony/http-foundation": { - "version": "v4.1.3" - }, - "symfony/http-kernel": { - "version": "v4.1.3" - }, - "symfony/inflector": { - "version": "v4.1.3" - }, - "symfony/intl": { - "version": "v4.1.3" - }, - "symfony/lts": { - "version": "4-dev" - }, - "symfony/maker-bundle": { - "version": "1.0", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "1.0", - "ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f" - } - }, - "symfony/monolog-bridge": { - "version": "v4.1.3" - }, - "symfony/monolog-bundle": { - "version": "3.1", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "3.1", - "ref": "18ebf5a940573a20de06f9c4060101eeb438cf3d" - } - }, - "symfony/options-resolver": { - "version": "v4.1.3" - }, - "symfony/orm-pack": { - "version": "v1.0.5" - }, - "symfony/phpunit-bridge": { - "version": "4.1", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "4.1", - "ref": "1a47f76dcd9d5d4da1fab54fb15450bae3704c5e" - } - }, - "symfony/polyfill-ctype": { - "version": "v1.9.0" - }, - "symfony/polyfill-intl-icu": { - "version": "v1.9.0" - }, - "symfony/polyfill-mbstring": { - "version": "v1.9.0" - }, - "symfony/polyfill-php72": { - "version": "v1.9.0" - }, - "symfony/process": { - "version": "v4.1.3" - }, - "symfony/profiler-pack": { - "version": "v1.0.3" - }, - "symfony/property-access": { - "version": "v4.1.3" - }, - "symfony/property-info": { - "version": "v4.1.3" - }, - "symfony/routing": { - "version": "4.0", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "4.0", - "ref": "cda8b550123383d25827705d05a42acf6819fe4e" - } - }, - "symfony/security": { - "version": "v4.1.3" - }, - "symfony/security-bundle": { - "version": "3.3", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "3.3", - "ref": "f8a63faa0d9521526499c0a8f403c9964ecb0527" - } - }, - "symfony/serializer": { - "version": "v4.1.3" - }, - "symfony/serializer-pack": { - "version": "v1.0.1" - }, - "symfony/stopwatch": { - "version": "v4.1.3" - }, - "symfony/swiftmailer-bundle": { - "version": "2.5", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "2.5", - "ref": "3db029c03e452b4a23f7fc45cec7c922c2247eb8" - } - }, - "symfony/test-pack": { - "version": "v1.0.2" - }, - "symfony/translation": { - "version": "3.3", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "3.3", - "ref": "6bcd6c570c017ea6ae5a7a6a027c929fd3542cd8" - } - }, - "symfony/twig-bridge": { - "version": "v4.1.3" - }, - "symfony/twig-bundle": { - "version": "3.3", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "3.3", - "ref": "f75ac166398e107796ca94cc57fa1edaa06ec47f" - } - }, - "symfony/validator": { - "version": "4.1", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "4.1", - "ref": "0cdc982334f45d554957a6167e030482795bf9d7" - } - }, - "symfony/var-dumper": { - "version": "v4.1.3" - }, - "symfony/web-link": { - "version": "v4.1.3" - }, - "symfony/web-profiler-bundle": { - "version": "3.3", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "3.3", - "ref": "6bdfa1a95f6b2e677ab985cd1af2eae35d62e0f6" - } - }, - "symfony/web-server-bundle": { - "version": "3.3", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "master", - "version": "3.3", - "ref": "dae9b39fd6717970be7601101ce5aa960bf53d9a" - } - }, - "symfony/yaml": { - "version": "v4.1.3" - }, - "twig/twig": { - "version": "v2.5.0" - }, - "webmozart/assert": { - "version": "1.3.0" - }, - "zendframework/zend-code": { - "version": "3.3.1" - }, - "zendframework/zend-eventmanager": { - "version": "3.2.1" - } -} diff --git a/tests/Application/src/Entity/.gitignore b/tests/Application/templates/.gitignore similarity index 100% rename from tests/Application/src/Entity/.gitignore rename to tests/Application/templates/.gitignore diff --git a/tests/Application/templates/base.html.twig b/tests/Application/templates/base.html.twig deleted file mode 100644 index 043f42d..0000000 --- a/tests/Application/templates/base.html.twig +++ /dev/null @@ -1,12 +0,0 @@ - - - - - {% block title %}Welcome!{% endblock %} - {% block stylesheets %}{% endblock %} - - - {% block body %}{% endblock %} - {% block javascripts %}{% endblock %} - - diff --git a/tests/Application/templates/bundles/SyliusAdminBundle/Order/Show/Summary/_totals.html.twig b/tests/Application/templates/bundles/SyliusAdminBundle/Order/Show/Summary/_totals.html.twig new file mode 100644 index 0000000..d8abcf0 --- /dev/null +++ b/tests/Application/templates/bundles/SyliusAdminBundle/Order/Show/Summary/_totals.html.twig @@ -0,0 +1,95 @@ +{% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %} + + +{% set orderPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT') %} +{% set orderShippingPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT') %} +{% set itemPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT') %} +{% set shippingAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::SHIPPING_ADJUSTMENT') %} +{% set taxAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::TAX_ADJUSTMENT') %} + +{% set orderShippingPromotions = sylius_aggregate_adjustments(order.getAdjustmentsRecursively(orderShippingPromotionAdjustment)) %} + + + + + {{ 'sylius.ui.tax_total'|trans }}: + {{ money.format(order.taxTotal, order.currencyCode) }} + + + {{ 'sylius.ui.items_total'|trans }}: + {{ money.format(order.itemsTotal, order.currencyCode) }} + + + + + {% if not order.adjustments(shippingAdjustment).isEmpty() %} +
+
{{ 'sylius.ui.shipping'|trans }}:
+ {% for adjustment in order.adjustments(shippingAdjustment) %} +
+
{{ money.format(adjustment.amount, order.currencyCode) }}
+
+
+ {{ adjustment.label }}: +
+
+
+ {% endfor %} +
+ {% else %} +

{{ 'sylius.ui.no_shipping_charges'|trans }}

+ {% endif %} + + {% if not orderShippingPromotions is empty %} + +
+
{{ 'sylius.ui.shipping_discount'|trans }}:
+ {% for label, amount in orderShippingPromotions %} +
+
+ {{ money.format(amount, order.currencyCode) }} +
+
+ {% endfor %} +
+ + {% endif %} + + {{ 'sylius.ui.shipping_total'|trans }}: + {{ money.format(order.shippingTotal, order.currencyCode) }} + + + + + {{ 'sylius.ui.order_total'|trans }}: + {{ money.format(order.total, order.currencyCode) }} + + + +{% set paymentFeeAdjustment = constant('MangoSylius\\PaymentFeePlugin\\Model\\AdjustmentInterface::PAYMENT_ADJUSTMENT') %} + +{% set paymentFeeAdjustments = order.getAdjustmentsRecursively(paymentFeeAdjustment) %} +{% if paymentFeeAdjustments is not empty %} + + + +
+ {% for paymentFeeLabel, paymentFeeAmount in sylius_aggregate_adjustments(paymentFeeAdjustments) %} +
+
+ {{ paymentFeeLabel }} +
+ {{ money.format(paymentFeeAmount, order.currencyCode) }} +
+
+
+ {% endfor %} +
+ + + + {{ 'mango-sylius.ui.paymentFee_total'|trans }}: + {{ money.format(order.getAdjustmentsTotal(paymentFeeAdjustment) ,order.currencyCode) }} + + +{% endif %} diff --git a/tests/Application/templates/bundles/SyliusAdminBundle/PaymentMethod/_form.html.twig b/tests/Application/templates/bundles/SyliusAdminBundle/PaymentMethod/_form.html.twig new file mode 100644 index 0000000..a5a4d03 --- /dev/null +++ b/tests/Application/templates/bundles/SyliusAdminBundle/PaymentMethod/_form.html.twig @@ -0,0 +1,65 @@ +{% import '@SyliusUi/Macro/flags.html.twig' as flags %} + +{{ form_errors(form) }} + +
+

{{ 'sylius.ui.details'|trans }}

+ {{ form_errors(form) }} + +
+ {{ form_row(form.code) }} + {{ form_row(form.position) }} +
+ {{ form_row(form.enabled) }} + {{ form_row(form.channels) }} +
+ +
+

{{ 'sylius.ui.gateway_configuration'|trans }}

+ {{ form_row(form.gatewayConfig.factoryName) }} + {% if form.gatewayConfig.config is defined %} + {% for field in form.gatewayConfig.config %} + {% if loop.index is odd %}
{% endif %} + {{ form_row(field) }} + {% if loop.index is even %}
{% endif %} + {% endfor %} + {% endif %} +
+ +
+ {% for locale, translationForm in form.translations %} +
+ + {{ flags.fromLocaleCode(locale) }} {{ locale|sylius_locale_name }} +
+
+ {{ form_row(translationForm.name) }} + {{ form_row(translationForm.description) }} +
+

+ {{ 'sylius.ui.the_instructions_below_will_be_displayed_to_the_customer'|trans }}. +

+
+ {{ form_row(translationForm.instructions) }} +
+ {% endfor %} +
+ +
+

{{ 'sylius.ui.taxes'|trans }}

+ {{ form_row(form.taxCategory) }} +

{{ 'mango-sylius.ui.payment_charges'|trans }}

+ {{ form_row(form.calculator) }} + {% for name, calculatorConfigurationPrototype in form.vars.prototypes %} +
+
+ {% endfor %} +
+ {% if form.calculatorConfiguration is defined %} + {% for field in form.calculatorConfiguration %} + {{ form_row(field) }} + {% endfor %} + {% endif %} +
+
diff --git a/tests/Application/tests/.gitignore b/tests/Application/tests/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Application/web b/tests/Application/web deleted file mode 120000 index d70ebaa..0000000 --- a/tests/Application/web +++ /dev/null @@ -1 +0,0 @@ -public \ No newline at end of file diff --git a/tests/Behat/Context/Ui/Admin/ManagingAdminPaymentMethodWithExtraFeeContext.php b/tests/Behat/Context/Ui/Admin/ManagingAdminPaymentMethodWithExtraFeeContext.php new file mode 100644 index 0000000..9a7cde9 --- /dev/null +++ b/tests/Behat/Context/Ui/Admin/ManagingAdminPaymentMethodWithExtraFeeContext.php @@ -0,0 +1,40 @@ +updatePage = $updatePage; + } + + /** + * @When I add an extra fee of :arg1$ + */ + public function iAddAnExtraFeeOf($arg1) + { + $this->updatePage->changeExtraFee($arg1); + } + + /** + * @Then this payment method have an extra fee of :arg1$ + */ + public function thisPaymentMethodHaveAExtraFeeOnIt($arg1) + { + Assert::eq($this->updatePage->getExtraFee(), $arg1); + } + +} diff --git a/tests/Behat/Context/Ui/Shop/WelcomeContext.php b/tests/Behat/Context/Ui/Shop/WelcomeContext.php deleted file mode 100644 index 6c9b172..0000000 --- a/tests/Behat/Context/Ui/Shop/WelcomeContext.php +++ /dev/null @@ -1,80 +0,0 @@ -staticWelcomePage = $staticWelcomePage; - $this->dynamicWelcomePage = $dynamicWelcomePage; - } - - /** - * @When a customer with an unknown name visits static welcome page - */ - public function customerWithUnknownNameVisitsStaticWelcomePage(): void - { - $this->staticWelcomePage->open(); - } - - /** - * @When a customer named :name visits static welcome page - */ - public function namedCustomerVisitsStaticWelcomePage(string $name): void - { - $this->staticWelcomePage->open(['name' => $name]); - } - - /** - * @Then they should be statically greeted with :greeting - */ - public function theyShouldBeStaticallyGreetedWithGreeting(string $greeting): void - { - Assert::same($this->staticWelcomePage->getGreeting(), $greeting); - } - - /** - * @When a customer with an unknown name visits dynamic welcome page - */ - public function customerWithUnknownNameVisitsDynamicWelcomePage(): void - { - $this->dynamicWelcomePage->open(); - } - - /** - * @When a customer named :name visits dynamic welcome page - */ - public function namedCustomerVisitsDynamicWelcomePage(string $name): void - { - $this->dynamicWelcomePage->open(['name' => $name]); - } - - /** - * @Then they should be dynamically greeted with :greeting - */ - public function theyShouldBeDynamicallyGreetedWithGreeting(string $greeting): void - { - Assert::same($this->dynamicWelcomePage->getGreeting(), $greeting); - } -} diff --git a/tests/Behat/Page/Shop/DynamicWelcomePage.php b/tests/Behat/Page/Shop/DynamicWelcomePage.php deleted file mode 100644 index e7278e1..0000000 --- a/tests/Behat/Page/Shop/DynamicWelcomePage.php +++ /dev/null @@ -1,44 +0,0 @@ -getSession()->getPage()->waitFor(3, function (): string { - $greeting = $this->getElement('greeting')->getText(); - - if ('Loading...' === $greeting) { - return ''; - } - - return $greeting; - }); - } - - /** - * {@inheritdoc} - */ - public function getRouteName(): string - { - return 'acme_sylius_example_dynamic_welcome'; - } - - /** - * {@inheritdoc} - */ - protected function getDefinedElements(): array - { - return array_merge(parent::getDefinedElements(), [ - 'greeting' => '#greeting', - ]); - } -} diff --git a/tests/Behat/Page/Shop/StaticWelcomePage.php b/tests/Behat/Page/Shop/StaticWelcomePage.php deleted file mode 100644 index 3be5144..0000000 --- a/tests/Behat/Page/Shop/StaticWelcomePage.php +++ /dev/null @@ -1,36 +0,0 @@ -getElement('greeting')->getText(); - } - - /** - * {@inheritdoc} - */ - public function getRouteName(): string - { - return 'acme_sylius_example_static_welcome'; - } - - /** - * {@inheritdoc} - */ - protected function getDefinedElements(): array - { - return array_merge(parent::getDefinedElements(), [ - 'greeting' => '#greeting', - ]); - } -} diff --git a/tests/Behat/Page/Shop/WelcomePageInterface.php b/tests/Behat/Page/Shop/WelcomePageInterface.php deleted file mode 100644 index f442504..0000000 --- a/tests/Behat/Page/Shop/WelcomePageInterface.php +++ /dev/null @@ -1,15 +0,0 @@ -getElement('extra_fee')->setValue($extraFeePrice); + } + + public function getExtraFee() + { + return $this->getElement('extra_fee')->getValue(); + } + + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + 'extra_fee' => '.calculatorConfiguration input', + ]); + } +} diff --git a/tests/Behat/Pages/Admin/PaymentMethod/UpdatePageInterface.php b/tests/Behat/Pages/Admin/PaymentMethod/UpdatePageInterface.php new file mode 100644 index 0000000..aaf2eff --- /dev/null +++ b/tests/Behat/Pages/Admin/PaymentMethod/UpdatePageInterface.php @@ -0,0 +1,14 @@ + - - - + - - - - - + + - - - + + sylius_admin_channel_update + + + + + + + diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml index 914463a..63bd754 100644 --- a/tests/Behat/Resources/suites.yml +++ b/tests/Behat/Resources/suites.yml @@ -1,10 +1,2 @@ -# Put your Behat suites definitions here - -default: - suites: - greeting_customer: - contexts_services: - - acme_sylius_example.context.ui.shop.welcome - - filters: - tags: "@greeting_customer" +imports: + - suites/ui/payment_method_with_fee.yml diff --git a/tests/Behat/Resources/suites/ui/payment_method_with_fee.yml b/tests/Behat/Resources/suites/ui/payment_method_with_fee.yml new file mode 100644 index 0000000..ee86724 --- /dev/null +++ b/tests/Behat/Resources/suites/ui/payment_method_with_fee.yml @@ -0,0 +1,52 @@ + +default: + suites: + set_payment_method_extra_fee: + contexts: + - sylius.behat.context.hook.doctrine_orm + + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.currency + - 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.product_taxon + - sylius.behat.context.setup.promotion + - sylius.behat.context.setup.admin_security + - sylius.behat.context.setup.shop_security + - sylius.behat.context.setup.shipping + - sylius.behat.context.setup.taxation + - sylius.behat.context.setup.taxonomy + - sylius.behat.context.setup.zone + - sylius.behat.context.setup.admin_user + - sylius.behat.context.setup.user + + - sylius.behat.context.transform.address + - sylius.behat.context.transform.channel + - sylius.behat.context.transform.country + - sylius.behat.context.transform.currency + - 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.product_variant + - sylius.behat.context.transform.promotion + - sylius.behat.context.transform.shipping_method + - sylius.behat.context.transform.tax_category + - sylius.behat.context.transform.taxon + - sylius.behat.context.transform.user + - sylius.behat.context.transform.zone + + - sylius.behat.context.transform.shared_storage + + - sylius.behat.context.ui.admin.notification + + - sylius.behat.context.ui.admin.managing_payment_methods + + - sylius.behat.context.ui.admin.payment_method_with_fee + + filters: + tags: "@set_payment_method_extra_fee && @ui"