diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..552ed9c --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +* @BitBagCommerce +* @Sylius/core-team \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a3fe2d7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,139 @@ +name: Build + +on: + push: ~ + release: + types: [created] + +jobs: + tests: + runs-on: ubuntu-latest + + name: "PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}" + + strategy: + fail-fast: false + matrix: + php: [7.4, 8.0] + node: [10.x] + mysql: [5.7, 8.0] + + exclude: + - # Segmentation fault while clearing cache + php: 8.0 + mysql: 5.7 + + env: + APP_ENV: test + DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}" + + steps: + - + uses: actions/checkout@v2 + + - + name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + ini-values: date.timezone=Europe/Warsaw, opcache.enable=1, opcache.enable_cli=1, opcache.memory_consumption=256, opcache.max_accelerated_files=32531, opcache.interned_strings_buffer=8, opcache.validate_timestamps=0, opcache.save_comments=1, opcache.fast_shutdown=0 + extensions: intl, gd, opcache, mysql, pdo_mysql, :xdebug + tools: symfony + coverage: none + + - + name: Setup Node + uses: actions/setup-node@v1 + with: + node-version: "${{ matrix.node }}" + + - + name: Shutdown default MySQL + run: sudo service mysql stop + + - + name: Setup MySQL + uses: mirromutth/mysql-action@v1.1 + with: + mysql version: "${{ matrix.mysql }}" + mysql root password: "root" + + - + name: Output PHP version for Symfony CLI + run: php -v | head -n 1 | awk '{ print $2 }' > .php-version + + - + name: Install certificates + run: symfony server:ca:install + + - + name: Run Chrome Headless + run: google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --disable-web-security --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1 > /dev/null 2>&1 & + + - + name: Run webserver + run: (cd tests/Application && symfony server:start --port=8080 --dir=public --daemon) + + - + name: Get Composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - + name: Cache Composer + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-${{ matrix.php }}-composer- + - + name: Install PHP dependencies + run: composer install --no-interaction + + - + name: Get Yarn cache directory + id: yarn-cache + run: echo "::set-output name=dir::$(yarn cache dir)" + + - + name: Cache Yarn + uses: actions/cache@v2 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: ${{ runner.os }}-node-${{ matrix.node }}-yarn-${{ hashFiles('**/package.json **/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-node-${{ matrix.node }}-yarn- + - + name: Install JS dependencies + run: (cd tests/Application && yarn install) + + - + name: Prepare test application database + run: | + (cd tests/Application && bin/console doctrine:database:create -vvv) + (cd tests/Application && bin/console doctrine:schema:create -vvv) + - + name: Prepare test application assets + run: | + (cd tests/Application && bin/console assets:install public -vvv) + (cd tests/Application && yarn build) + - + name: Prepare test application cache + run: (cd tests/Application && bin/console cache:warmup -vvv) + + - + name: Load fixtures in test application + run: (cd tests/Application && bin/console sylius:fixtures:load -n) + + - + name: Validate composer.json + run: composer validate --ansi --strict + + - + name: Validate database schema + run: (cd tests/Application && bin/console doctrine:schema:validate) + + - + name: Run Behat + run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun \ No newline at end of file diff --git a/README.md b/README.md index 08a0edc..9aec8a8 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,52 @@ -

- - - -
- - - - - - - - - - - - - - - -

- -

-

- -## Overview - -This plugin was made on top of our ShippingExport abstraction layer. It's goal is to allow exporting DHL24PL shipments to external -web API in Sylius platform based apps. Each time new shipment for a configured -DHL gateway is placed you will see a new shipment in the shipping export tab. - -## Support - -We work on amazing eCommerce projects on top of Sylius and other great Symfony based solutions, like eZ Platform, Akeneo or Pimcore. -Need some help or additional resources for a project? Write us an email on mikolaj.krol@bitbag.pl or visit -[our website](https://bitbag.shop/)! :rocket: - -## Demo - -We created a demo app with some useful use-cases of the plugin! Visit [demo.bitbag.shop](https://demo.bitbag.shop) to take a look at it. +# [![](https://bitbag.io/wp-content/uploads/2021/10/SyliusDHL24PLShippingExportPlugin.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_dhl24) + +# BitBag SyliusDHL24PlShippingExportPlugin + +---- + +[![](https://img.shields.io/packagist/l/bitbag/dhl24-pl-shipping-export-plugin.svg) ](https://packagist.org/packages/bitbag/dhl24-pl-shipping-export-plugin "License") [ ![](https://img.shields.io/packagist/v/bitbag/dhl24-pl-shipping-export-plugin.svg) ](https://packagist.org/packages/bitbag/dhl24-pl-shipping-export-plugin "Version") [ ![](https://img.shields.io/travis/BitBagCommerce/SyliusDHL24PlShippingExportPlugin/master.svg) ](http://travis-ci.org/BitBagCommerce/SyliusDHL24PlShippingExportPlugin "Build status") [ ![](https://img.shields.io/scrutinizer/quality/g/BitBagCommerce/SyliusDhl24PlShippingExportPlugin.svg) ](https://scrutinizer-ci.com/g/BitBagCommerce/SyliusDHL24PlShippingExportPlugin/ "Scrutinizer") [![](https://poser.pugx.org/bitbag/dhl24-pl-shipping-export-plugin/downloads)](https://packagist.org/packages/bitbag/dhl24-pl-shipping-export-plugin "Total Downloads") [![Slack](https://img.shields.io/badge/community%20chat-slack-FF1493.svg)](http://sylius-devs.slack.com) [![Support](https://img.shields.io/badge/support-contact%20author-blue])](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_dhl24) + +

+ +

+ +At BitBag we do believe in open source. However, we are able to do it just because of our awesome clients, who are kind enough to share some parts of our work with the community. Therefore, if you feel like there is a possibility for us to work together, feel free to reach out. You will find out more about our professional services, technologies, and contact details at [https://bitbag.io/](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_cms). + +Like what we do? Want to join us? Check out our job listings on our [career page](https://bitbag.io/career/?utm_source=github&utm_medium=referral&utm_campaign=career). Not familiar with Symfony & Sylius yet, but still want to start with us? Join our [academy](https://bitbag.io/pl/akademia?utm_source=github&utm_medium=url&utm_campaign=akademia)! + +## Table of Content + +*** + +* [Overview](#overview) +* [Support](#we-are-here-to-help) +* [About us](#about-us) + * [Community](#community) +* [Demo](#demo-sylius-shop) +* [License](#license) +* [Contact](#contact) + +# Overview + +*** + +This plugin allows you to generate shipping labels for DHL24. + +- [Installation](#instalation) +- [Customization](#customization) + +## We are here to help + +This **open-source plugin was developed to help the Sylius community**. If you have any additional questions, would like help with installing or configuring the plugin, or need any assistance with your Sylius project - let us know! + +[![](https://bitbag.io/wp-content/uploads/2020/10/button-contact.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_cms) + + +## Instalation + +*** + +Run composer to install DHL24ShippingExportPlugin: ```bash $ composer require bitbag/dhl24-pl-shipping-export-plugin @@ -52,8 +61,19 @@ return [ ]; ``` +Add config file to your _sylius.yaml + +```yaml +imports: +... + + - { resource: "@BitBagSyliusShippingExportPlugin/Resources/config/config.yml" } +``` + ## Customization +*** + ### Available services you can [decorate](https://symfony.com/doc/current/service_container/service_decoration.html) and forms you can [extend](http://symfony.com/doc/current/form/create_form_type_extension.html) Run the below command to see what Symfony services are shared with this plugin: @@ -61,21 +81,93 @@ Run the below command to see what Symfony services are shared with this plugin: $ bin/console debug:container bitbag_sylius_dhl24pl_plugin ``` -## Testing -```bash -$ composer install -$ cd tests/Application -$ yarn install -$ yarn run gulp -$ bin/console assets:install -e test -$ bin/console doctrine:database:create -e test -$ bin/console doctrine:schema:create -e test -$ bin/console server:run 127.0.0.1:8080 -e test -$ open http://localhost:8080 -$ bin/behat -$ bin/phpspec run -``` +# About us + +--- + +BitBag is a company of people who **love what they do** and do it right. We fulfill the eCommerce technology stack with **Sylius**, Shopware, Akeneo, and Pimcore for PIM, eZ Platform for CMS, and VueStorefront for PWA. Our goal is to provide real digital transformation with an agile solution that scales with the **clients’ needs**. Our main area of expertise includes eCommerce consulting and development for B2C, B2B, and Multi-vendor Marketplaces.
+We are advisers in the first place. We start each project with a diagnosis of problems, and an analysis of the needs and **goals** that the client wants to achieve.
+We build **unforgettable**, consistent digital customer journeys on top of the **best technologies**. Based on a detailed analysis of the goals and needs of a given organization, we create dedicated systems and applications that let businesses grow.
+Our team is fluent in **Polish, English, German and, French**. That is why our cooperation with clients from all over the world is smooth. + +**Some numbers from BitBag regarding Sylius:** +- 50+ **experts** including consultants, UI/UX designers, Sylius trained front-end and back-end developers, +- 120+ projects **delivered** on top of Sylius, +- 25+ **countries** of BitBag’s customers, +- 4+ **years** in the Sylius ecosystem. + +**Our services:** +- Business audit/Consulting in the field of **strategy** development, +- Data/shop **migration**, +- Headless **eCommerce**, +- Personalized **software** development, +- **Project** maintenance and long term support, +- Technical **support**. + +**Key clients:** Mollie, Guave, P24, Folkstar, i-LUNCH, Elvi Project, WestCoast Gifts. + +--- + +If you need some help with Sylius development, don't be hesitated to contact us directly. You can fill the form on [this site](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_cms) or send us an e-mail at hello@bitbag.io! + +--- + +[![](https://bitbag.io/wp-content/uploads/2021/08/sylius-badges-transparent-wide.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_cms) + + +## Community + +---- + +For online communication, we invite you to chat with us & other users on [Sylius Slack](https://sylius-devs.slack.com/). + +# Demo Sylius Shop + +--- + +We created a demo app with some useful use-cases of plugins! +Visit [sylius-demo.bitbag.io](https://sylius-demo.bitbag.io/) to take a look at it. The admin can be accessed under +[sylius-demo.bitbag.io/admin/login](https://sylius-demo.bitbag.io/admin/login) link and `bitbag: bitbag` credentials. +Plugins that we have used in the demo: + +| BitBag's Plugin | GitHub | Sylius' Store| +| ------ | ------ | ------| +| ACL Plugin | *Private. Available after the purchasing.*| https://plugins.sylius.com/plugin/access-control-layer-plugin/| +| Braintree Plugin | https://github.com/BitBagCommerce/SyliusBraintreePlugin |https://plugins.sylius.com/plugin/braintree-plugin/| +| CMS Plugin | https://github.com/BitBagCommerce/SyliusCmsPlugin | https://plugins.sylius.com/plugin/cmsplugin/| +| Elasticsearch Plugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin | https://plugins.sylius.com/plugin/2004/| +| Mailchimp Plugin | https://github.com/BitBagCommerce/SyliusMailChimpPlugin | https://plugins.sylius.com/plugin/mailchimp/ | +| Multisafepay Plugin | https://github.com/BitBagCommerce/SyliusMultiSafepayPlugin | +| Wishlist Plugin | https://github.com/BitBagCommerce/SyliusWishlistPlugin | https://plugins.sylius.com/plugin/wishlist-plugin/| +| **Sylius' Plugin** | **GitHub** | **Sylius' Store** | +| Admin Order Creation Plugin | https://github.com/Sylius/AdminOrderCreationPlugin | https://plugins.sylius.com/plugin/admin-order-creation-plugin/ | +| Invoicing Plugin | https://github.com/Sylius/InvoicingPlugin | https://plugins.sylius.com/plugin/invoicing-plugin/ | +| Refund Plugin | https://github.com/Sylius/RefundPlugin | https://plugins.sylius.com/plugin/refund-plugin/ | + +**If you need an overview of Sylius' capabilities, schedule a consultation with our expert.** + +[![](https://bitbag.io/wp-content/uploads/2020/10/button_free_consulatation-1.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_cms) + +## Additional resources for developers + +--- +To learn more about our contribution workflow and more, we encourage you to use the following resources: +* [Sylius Documentation](https://docs.sylius.com/en/latest/) +* [Sylius Contribution Guide](https://docs.sylius.com/en/latest/contributing/) +* [Sylius Online Course](https://sylius.com/online-course/) + + +## License + +--- + +This plugin's source code is completely free and released under the terms of the MIT license. + +[//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen.) + +## Contact -## Contribution +--- +If you want to contact us, the best way is to fill the form on [our website](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_cms) or send us an e-mail to hello@bitbag.io with your question(s). We guarantee that we answer as soon as we can! -Learn more about our contribution workflow on http://docs.sylius.org/en/latest/contributing/. +[![](https://bitbag.io/wp-content/uploads/2021/08/badges-bitbag.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_cms) diff --git a/behat.yml.dist b/behat.yml.dist index 9f33a12..d00205d 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -4,19 +4,25 @@ imports: default: extensions: - Lakion\Behat\MinkDebugExtension: + DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~ + + FriendsOfBehat\MinkDebugExtension: directory: etc/build clean_start: false screenshot: true Behat\MinkExtension: files_path: "%paths.base%/vendor/sylius/sylius/src/Sylius/Behat/Resources/fixtures/" - base_url: "http://localhost:8080/" + base_url: "http://127.0.0.1:8080/" default_session: symfony - javascript_session: chrome + javascript_session: chrome_headless sessions: symfony: symfony: ~ + chrome_headless: + chrome: + api_url: http://127.0.0.1:9222 + validate_certificate: false chrome: selenium2: browser: chrome @@ -30,6 +36,8 @@ default: - "start-fullscreen" - "start-maximized" - "no-sandbox" + extra_capabilities: + unexpectedAlertBehaviour: accept firefox: selenium2: browser: firefox diff --git a/composer.json b/composer.json index 72fc668..902f74e 100644 --- a/composer.json +++ b/composer.json @@ -2,56 +2,49 @@ "name": "bitbag/dhl24-pl-shipping-export-plugin", "type": "sylius-plugin", "description": "DHL24 PL shipping export plugin for Sylius based applications.", - "license": "MIT", - "authors": [ - { - "name": "Mikołaj Król", - "email": "mikolaj.krol@bitbag.pl" - }, - { - "name": "Damian Murawski", - "email": "damian.murawski@bitbag.pl" - } + "keywords": [ + "sylius", + "sylius-plugin" ], + "license": "MIT", "require": { - "php": "^7.3", - "ext-soap": "*", - - "sylius/sylius": "^1.7", - "bitbag/shipping-export-plugin": "^1.3" + "php": "^7.4 || ^8.0", + "bitbag/shipping-export-plugin": "^1.5", + "sylius/sylius": "~1.9.0 || ~1.10.0", + "ext-soap": "*" }, "require-dev": { - "behat/behat": "^3.6", - "behat/mink": "^1.7", - "behat/mink-browserkit-driver": "^1.3", - "behat/mink-extension": "^2.2", - "behat/mink-selenium2-driver": "^1.3", + "behat/behat": "^3.6.1", + "behat/mink-selenium2-driver": "^1.4", + "dmore/behat-chrome-extension": "^1.3", + "dmore/chrome-mink-driver": "^2.7", + "friends-of-behat/mink": "^1.8", + "friends-of-behat/mink-browserkit-driver": "^1.4", + "friends-of-behat/mink-debug-extension": "^2.0.0", + "friends-of-behat/mink-extension": "^2.4", "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.2", - "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", - "sensiolabs/security-checker": "^5.0", - "sylius-labs/coding-standard": "^3.0", - "symfony/browser-kit": "^4.4", - "symfony/debug-bundle": "^4.4", - "symfony/dotenv": "^4.4", - "symfony/intl": "^4.4", - "symfony/web-profiler-bundle": "^4.4", - "symfony/web-server-bundle": "^4.4" + "friends-of-behat/symfony-extension": "^2.1", + "friends-of-behat/variadic-extension": "^1.3", + "friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev", + "phpspec/phpspec": "^7.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "0.12.85", + "phpstan/phpstan-doctrine": "0.12.33", + "phpstan/phpstan-strict-rules": "^0.12.0", + "phpstan/phpstan-webmozart-assert": "0.12.12", + "phpunit/phpunit": "^9.5", + "sensiolabs/security-checker": "^6.0", + "sylius-labs/coding-standard": "^4.1", + "symfony/browser-kit": "^4.4 || ^5.2", + "symfony/debug-bundle": "^4.4 || ^5.2", + "symfony/dotenv": "^4.4 || ^5.2", + "symfony/intl": "^4.4 || ^5.2", + "symfony/web-profiler-bundle": "^4.4 || ^5.2", + "vimeo/psalm": "4.7.1" }, - "conflict": { - "symfony/symfony": "4.1.8", - "symfony/browser-kit": "4.1.8", - "symfony/dependency-injection": "4.1.8", - "symfony/dom-crawler": "4.1.8", - "symfony/routing": "4.1.8" + "config": { + "sort-packages": true }, "prefer-stable": true, "autoload": { @@ -61,6 +54,8 @@ } }, "autoload-dev": { - "classmap": ["tests/Application/Kernel.php"] + "classmap": [ + "tests/Application/Kernel.php" + ] } } diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..bf40cc9 --- /dev/null +++ b/ecs.php @@ -0,0 +1,14 @@ +import('vendor/sylius-labs/coding-standard/ecs.php'); + + $containerConfigurator->parameters()->set(Option::SKIP, [ + VisibilityRequiredFixer::class => ['*Spec.php'], + ]); +}; diff --git a/src/Api/ShippingLabelFetcher.php b/src/Api/ShippingLabelFetcher.php new file mode 100644 index 0000000..1df4ba6 --- /dev/null +++ b/src/Api/ShippingLabelFetcher.php @@ -0,0 +1,61 @@ +flashBag = $flashBag; + $this->webClient = $webClient; + $this->soapClient = $soapClient; + } + + public function createShipment($shippingGateway, $shipment): void + { + try { + $this->webClient->setShippingGateway($shippingGateway); + $this->webClient->setShipment($shipment); + $requestData = $this->webClient->getRequestData(); + + $this->response = $this->soapClient->createShipment($requestData, $shippingGateway->getConfigValue('wsdl')); + } catch (\SoapFault $exception) { + $this->flashBag->add( + 'error', + sprintf( + 'DHL24 Web Service for #%s order: %s', + $shipment->getOrder()->getNumber(), + $exception->getMessage() + ) + ); + + return; + } + } + + public function getLabelContent(): ?string + { + if (!isset($this->response->createShipmentResult)) { + return ''; + } + + $this->flashBag->add('success', 'bitbag.ui.shipment_data_has_been_exported'); // Add success notification + + return base64_decode($this->response->createShipmentResult->label->labelContent); + } +} diff --git a/src/Api/ShippingLabelFetcherInterface.php b/src/Api/ShippingLabelFetcherInterface.php new file mode 100644 index 0000000..90ab36d --- /dev/null +++ b/src/Api/ShippingLabelFetcherInterface.php @@ -0,0 +1,12 @@ +webClient = $webClient; - $this->soapClient = $soapClient; + /** @var string */ + private $shippingLabelsPath; + + private ShippingLabelFetcherInterface $shippingLabelFetcher; + + public function __construct( + Filesystem $filesystem, + ShippingExportRepository $shippingExportRepository, + string $shippingLabelsPath, + ShippingLabelFetcherInterface $shippingLabelFetcher + ) { + $this->filesystem = $filesystem; + $this->shippingExportRepository = $shippingExportRepository; + $this->shippingLabelsPath = $shippingLabelsPath; + $this->shippingLabelFetcher = $shippingLabelFetcher; } - public function exportShipment(ExportShipmentEvent $exportShipmentEvent): void + public function exportShipment(ResourceControllerEvent $event): void { - $shippingExport = $exportShipmentEvent->getShippingExport(); + /** @var ShippingExportInterface $shippingExport */ + $shippingExport = $event->getSubject(); + Assert::isInstanceOf($shippingExport, ShippingExportInterface::class); + $shippingGateway = $shippingExport->getShippingGateway(); + Assert::notNull($shippingGateway); - if ($shippingGateway->getCode() !== self::DHL_GATEWAY_CODE) { + if (self::DHL_GATEWAY_CODE !== $shippingGateway->getCode()) { return; } $shipment = $shippingExport->getShipment(); - $this->webClient->setShippingGateway($shippingGateway); - $this->webClient->setShipment($shipment); - - try { - $requestData = $this->webClient->getRequestData(); - $response = $this->soapClient->createShipment($requestData, $shippingGateway->getConfigValue('wsdl')); - } catch (\Exception $exception) { - $exportShipmentEvent->addErrorFlash(sprintf( - 'DHL24 Web Service for #%s order: %s', - $shipment->getOrder()->getNumber(), - $exception->getMessage())); + $this->shippingLabelFetcher->createShipment($shippingGateway, $shipment); + $labelContent = $this->shippingLabelFetcher->getLabelContent(); + if (empty($labelContent)) { return; } + $this->saveShippingLabel($shippingExport, $labelContent, 'pdf'); // Save label + $this->markShipmentAsExported($shippingExport); // Mark shipment as "Exported" + } - $labelContent = base64_decode($response->createShipmentResult->label->labelContent); - $extension = self::BASE_LABEL_EXTENSION; + public function saveShippingLabel( + ShippingExportInterface $shippingExport, + string $labelContent, + string $labelExtension + ): void { + $labelPath = $this->shippingLabelsPath + . '/' . $this->getFilename($shippingExport) + . '.' . $labelExtension; - if ('ZBLP' === $response->createShipmentResult->label->labelType) { - $extension = 'zpl'; - } + $this->filesystem->dumpFile($labelPath, $labelContent); + $shippingExport->setLabelPath($labelPath); + + $this->shippingExportRepository->add($shippingExport); + } + + private function getFilename(ShippingExportInterface $shippingExport): string + { + $shipment = $shippingExport->getShipment(); + Assert::notNull($shipment); + + $order = $shipment->getOrder(); + Assert::notNull($order); + + $orderNumber = $order->getNumber(); + + $shipmentId = $shipment->getId(); + + return implode( + '_', + [ + $shipmentId, + preg_replace('~[^A-Za-z0-9]~', '', $orderNumber), + ] + ); + } + + private function markShipmentAsExported(ShippingExportInterface $shippingExport): void + { + $shippingExport->setState(ShippingExportInterface::STATE_EXPORTED); + $shippingExport->setExportedAt(new \DateTime()); - $exportShipmentEvent->saveShippingLabel($labelContent, $extension); - $exportShipmentEvent->addSuccessFlash(); - $exportShipmentEvent->exportShipment(); + $this->shippingExportRepository->add($shippingExport); } } diff --git a/src/Resources/config/config.yml b/src/Resources/config/config.yml new file mode 100644 index 0000000..7ff61b4 --- /dev/null +++ b/src/Resources/config/config.yml @@ -0,0 +1,2 @@ +imports: + - { resource: services.yaml } diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index b1ac669..29d0a39 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -7,13 +7,22 @@ services: tags: - { name: bitbag.shipping_gateway_configuration_type, type: 'dhl24_pl', label: "DHL24 PL" } - bitbag.dhl24_pl_shipping_export_plugin.event_listener.dhl_shipping_export: - class: BitBag\SyliusDhl24PlShippingExportPlugin\EventListener\ShippingExportEventListener + bitbag.dhl24_pl_shipping_export_plugin.api.shipping_label_fetcher: + class: BitBag\SyliusDhl24PlShippingExportPlugin\Api\ShippingLabelFetcher arguments: + - '@session.flash_bag' - '@bitbag.dhl24_pl_shipping_export_plugin.api.web_client' - '@bitbag.dhl24_pl_shipping_export_plugin.api.soap_client' + + bitbag.dhl24_pl_shipping_export_plugin.event_listener.dhl_shipping_export: + class: BitBag\SyliusDhl24PlShippingExportPlugin\EventListener\ShippingExportEventListener + arguments: + - '@filesystem' + - '@bitbag.repository.shipping_export' + - '%bitbag.shipping_labels_path%' + - '@bitbag.dhl24_pl_shipping_export_plugin.api.shipping_label_fetcher' tags: - - { name: kernel.event_listener, event: 'bitbag.export_shipment', method: exportShipment } + - { name: kernel.event_listener, event: 'bitbag.shipping_export.export_shipment', method: exportShipment } bitbag.dhl24_pl_shipping_export_plugin.api.web_client: class: BitBag\SyliusDhl24PlShippingExportPlugin\Api\WebClient diff --git a/tests/Application/.babelrc b/tests/Application/.babelrc old mode 100755 new mode 100644 diff --git a/tests/Application/.env b/tests/Application/.env old mode 100755 new mode 100644 index 1465c68..fbb2f64 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -12,9 +12,15 @@ APP_SECRET=EDITME # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls -DATABASE_URL=mysql://root@127.0.0.1/sylius_%kernel.environment%?serverVersion=5.5 +DATABASE_URL=mysql://root@127.0.0.1/sylius_dhl24pl_plugin_%kernel.environment%?serverVersion=5.7 ###< doctrine/doctrine-bundle ### +###> lexik/jwt-authentication-bundle ### +JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem +JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem +JWT_PASSPHRASE=acme_plugin_development +###< lexik/jwt-authentication-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=" diff --git a/tests/Application/.env.test b/tests/Application/.env.test old mode 100755 new mode 100644 diff --git a/tests/Application/.eslintrc.js b/tests/Application/.eslintrc.js old mode 100755 new mode 100644 diff --git a/tests/Application/.gitignore b/tests/Application/.gitignore old mode 100755 new mode 100644 diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php old mode 100755 new mode 100644 index 9404b95..a2e3535 --- a/tests/Application/Kernel.php +++ b/tests/Application/Kernel.php @@ -5,24 +5,14 @@ namespace Tests\BitBag\SyliusDhl24PlShippingExportPlugin\Application; use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer; +use Sylius\Bundle\CoreBundle\Application\Kernel as SyliusKernel; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; -use Symfony\Component\Config\Loader\DelegatingLoader; use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\Loader\ClosureLoader; -use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; -use Symfony\Component\DependencyInjection\Loader\GlobFileLoader; -use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\HttpKernel\Config\FileLocator; +use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\Routing\RouteCollectionBuilder; -use Webmozart\Assert\Assert; final class Kernel extends BaseKernel { @@ -42,33 +32,37 @@ public function getLogDir(): string 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(); + foreach ($this->getConfigurationDirectories() as $confDir) { + $bundlesFile = $confDir . '/bundles.php'; + if (false === is_file($bundlesFile)) { + continue; } + yield from $this->registerBundlesFromFile($bundlesFile); } } protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void { - $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php')); + foreach ($this->getConfigurationDirectories() as $confDir) { + $bundlesFile = $confDir . '/bundles.php'; + if (false === is_file($bundlesFile)) { + continue; + } + $container->addResource(new FileResource($bundlesFile)); + } + $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'); + foreach ($this->getConfigurationDirectories() as $confDir) { + $this->loadContainerConfiguration($loader, $confDir); + } } 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'); + foreach ($this->getConfigurationDirectories() as $confDir) { + $this->loadRoutesConfiguration($routes, $confDir); + } } protected function getContainerBaseClass(): string @@ -80,27 +74,52 @@ protected function getContainerBaseClass(): string return parent::getContainerBaseClass(); } - protected function getContainerLoader(ContainerInterface $container): LoaderInterface + private function isTestEnvironment(): bool { - /** @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); + return 0 === strpos($this->getEnvironment(), 'test'); } - private function isTestEnvironment(): bool + private function loadContainerConfiguration(LoaderInterface $loader, string $confDir): void { - return 0 === strpos($this->getEnvironment(), 'test'); + $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'); + } + + private function loadRoutesConfiguration(RouteCollectionBuilder $routes, string $confDir): void + { + $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'); + } + + /** + * @return BundleInterface[] + */ + private function registerBundlesFromFile(string $bundlesFile): iterable + { + $contents = require $bundlesFile; + foreach ($contents as $class => $envs) { + if (isset($envs['all']) || isset($envs[$this->environment])) { + yield new $class(); + } + } + } + + /** + * @return string[] + */ + private function getConfigurationDirectories(): iterable + { + yield $this->getProjectDir() . '/config'; + $syliusConfigDir = $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION; + if (is_dir($syliusConfigDir)) { + yield $syliusConfigDir; + } + $symfonyConfigDir = $this->getProjectDir() . '/config/symfony/' . BaseKernel::MAJOR_VERSION . '.' . BaseKernel::MINOR_VERSION; + if (is_dir($symfonyConfigDir)) { + yield $symfonyConfigDir; + } } } diff --git a/tests/Application/composer.json b/tests/Application/composer.json old mode 100755 new mode 100644 diff --git a/tests/Application/config/bootstrap.php b/tests/Application/config/bootstrap.php old mode 100755 new mode 100644 index 6bb0207..e23eca0 --- a/tests/Application/config/bootstrap.php +++ b/tests/Application/config/bootstrap.php @@ -1,21 +1,23 @@ =1.2) -if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) { +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'); + (new Dotenv(true))->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'; +$_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 old mode 100755 new mode 100644 index 8ced1cd..c3a8028 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -7,7 +7,6 @@ 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], @@ -40,19 +39,20 @@ 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], 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], BitBag\SyliusShippingExportPlugin\BitBagSyliusShippingExportPlugin::class => ['all' => true], BitBag\SyliusDhl24PlShippingExportPlugin\BitBagDhl24PlShippingExportPlugin::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], + Sylius\Behat\Application\SyliusTestPlugin\SyliusTestPlugin::class => ['test' => true, 'test_cached' => true], + ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], + Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], + Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], + SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/packages/_sylius.yaml b/tests/Application/config/packages/_sylius.yaml old mode 100755 new mode 100644 index cd52772..4733eb5 --- a/tests/Application/config/packages/_sylius.yaml +++ b/tests/Application/config/packages/_sylius.yaml @@ -2,14 +2,17 @@ imports: - { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" } - { resource: "@SyliusAdminBundle/Resources/config/app/config.yml" } - - { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" } - { resource: "@SyliusShopBundle/Resources/config/app/config.yml" } + - { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" } + - { resource: "@BitBagSyliusShippingExportPlugin/Resources/config/config.yml" } parameters: sylius_core.public_dir: '%kernel.project_dir%/public' + bitbag.shipping_gateway.validation_groups: [ 'bitbag' ] + bitbag.shipping_labels_path: '%kernel.project_dir%/shipping_labels' sylius_shop: product_grid: diff --git a/tests/Application/config/packages/dev/framework.yaml b/tests/Application/config/packages/dev/framework.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/dev/jms_serializer.yaml b/tests/Application/config/packages/dev/jms_serializer.yaml deleted file mode 100755 index 353e460..0000000 --- a/tests/Application/config/packages/dev/jms_serializer.yaml +++ /dev/null @@ -1,7 +0,0 @@ -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 old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/dev/routing.yaml b/tests/Application/config/packages/dev/routing.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/dev/swiftmailer.yaml b/tests/Application/config/packages/dev/swiftmailer.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/dev/web_profiler.yaml b/tests/Application/config/packages/dev/web_profiler.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/doctrine.yaml b/tests/Application/config/packages/doctrine.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/doctrine_migrations.yaml b/tests/Application/config/packages/doctrine_migrations.yaml old mode 100755 new mode 100644 index c0a1202..cdbc01a --- a/tests/Application/config/packages/doctrine_migrations.yaml +++ b/tests/Application/config/packages/doctrine_migrations.yaml @@ -1,5 +1,4 @@ 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 - namespace: DoctrineMigrations + storage: + table_storage: + table_name: sylius_migrations diff --git a/tests/Application/config/packages/fos_rest.yaml b/tests/Application/config/packages/fos_rest.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/framework.yaml b/tests/Application/config/packages/framework.yaml old mode 100755 new mode 100644 index e74ed81..9b44501 --- a/tests/Application/config/packages/framework.yaml +++ b/tests/Application/config/packages/framework.yaml @@ -2,6 +2,5 @@ framework: secret: '%env(APP_SECRET)%' form: true csrf_protection: true - templating: { engines: ["twig"] } session: handler_id: ~ diff --git a/tests/Application/config/packages/jms_serializer.yaml b/tests/Application/config/packages/jms_serializer.yaml deleted file mode 100755 index 64dd8d1..0000000 --- a/tests/Application/config/packages/jms_serializer.yaml +++ /dev/null @@ -1,4 +0,0 @@ -jms_serializer: - visitors: - xml: - format_output: '%kernel.debug%' diff --git a/tests/Application/config/packages/lexik_jwt_authentication.yaml b/tests/Application/config/packages/lexik_jwt_authentication.yaml new file mode 100644 index 0000000..edfb69d --- /dev/null +++ b/tests/Application/config/packages/lexik_jwt_authentication.yaml @@ -0,0 +1,4 @@ +lexik_jwt_authentication: + secret_key: '%env(resolve:JWT_SECRET_KEY)%' + public_key: '%env(resolve:JWT_PUBLIC_KEY)%' + pass_phrase: '%env(JWT_PASSPHRASE)%' diff --git a/tests/Application/config/packages/liip_imagine.yaml b/tests/Application/config/packages/liip_imagine.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/prod/doctrine.yaml b/tests/Application/config/packages/prod/doctrine.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/prod/jms_serializer.yaml b/tests/Application/config/packages/prod/jms_serializer.yaml deleted file mode 100755 index bc97faf..0000000 --- a/tests/Application/config/packages/prod/jms_serializer.yaml +++ /dev/null @@ -1,6 +0,0 @@ -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 old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/routing.yaml b/tests/Application/config/packages/routing.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/security_checker.yaml b/tests/Application/config/packages/security_checker.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/staging/monolog.yaml b/tests/Application/config/packages/staging/monolog.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/staging/swiftmailer.yaml b/tests/Application/config/packages/staging/swiftmailer.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/stof_doctrine_extensions.yaml b/tests/Application/config/packages/stof_doctrine_extensions.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/swiftmailer.yaml b/tests/Application/config/packages/swiftmailer.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test/framework.yaml b/tests/Application/config/packages/test/framework.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test/monolog.yaml b/tests/Application/config/packages/test/monolog.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test/security.yaml b/tests/Application/config/packages/test/security.yaml new file mode 100644 index 0000000..21cc377 --- /dev/null +++ b/tests/Application/config/packages/test/security.yaml @@ -0,0 +1,3 @@ +security: + encoders: + sha512: sha512 diff --git a/tests/Application/config/packages/test/swiftmailer.yaml b/tests/Application/config/packages/test/swiftmailer.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test/sylius_theme.yaml b/tests/Application/config/packages/test/sylius_theme.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test/sylius_uploader.yaml b/tests/Application/config/packages/test/sylius_uploader.yaml new file mode 100644 index 0000000..ab9d6ca --- /dev/null +++ b/tests/Application/config/packages/test/sylius_uploader.yaml @@ -0,0 +1,3 @@ +services: + Sylius\Component\Core\Generator\ImagePathGeneratorInterface: + class: Sylius\Behat\Service\Generator\UploadedImagePathGenerator diff --git a/tests/Application/config/packages/test/web_profiler.yaml b/tests/Application/config/packages/test/web_profiler.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test_cached/doctrine.yaml b/tests/Application/config/packages/test_cached/doctrine.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test_cached/fos_rest.yaml b/tests/Application/config/packages/test_cached/fos_rest.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test_cached/framework.yaml b/tests/Application/config/packages/test_cached/framework.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test_cached/monolog.yaml b/tests/Application/config/packages/test_cached/monolog.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test_cached/security.yaml b/tests/Application/config/packages/test_cached/security.yaml new file mode 100644 index 0000000..21cc377 --- /dev/null +++ b/tests/Application/config/packages/test_cached/security.yaml @@ -0,0 +1,3 @@ +security: + encoders: + sha512: sha512 diff --git a/tests/Application/config/packages/test_cached/swiftmailer.yaml b/tests/Application/config/packages/test_cached/swiftmailer.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test_cached/sylius_channel.yaml b/tests/Application/config/packages/test_cached/sylius_channel.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test_cached/sylius_theme.yaml b/tests/Application/config/packages/test_cached/sylius_theme.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/test_cached/sylius_uploader.yaml b/tests/Application/config/packages/test_cached/sylius_uploader.yaml new file mode 100644 index 0000000..cfa727e --- /dev/null +++ b/tests/Application/config/packages/test_cached/sylius_uploader.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: "../test/sylius_uploader.yaml" } diff --git a/tests/Application/config/packages/test_cached/twig.yaml b/tests/Application/config/packages/test_cached/twig.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/translation.yaml b/tests/Application/config/packages/translation.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/twig.yaml b/tests/Application/config/packages/twig.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/packages/twig_extensions.yaml b/tests/Application/config/packages/twig_extensions.yaml deleted file mode 100755 index 0881cc9..0000000 --- a/tests/Application/config/packages/twig_extensions.yaml +++ /dev/null @@ -1,11 +0,0 @@ -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 old mode 100755 new mode 100644 diff --git a/tests/Application/config/routes.yaml b/tests/Application/config/routes.yaml old mode 100755 new mode 100644 index 86130e0..438d85f --- a/tests/Application/config/routes.yaml +++ b/tests/Application/config/routes.yaml @@ -1,3 +1,3 @@ -bitbag_sylius_shipping_export_plugin: +bitbag_shipping_export_plugin: resource: "@BitBagSyliusShippingExportPlugin/Resources/config/routing.yml" prefix: /admin diff --git a/tests/Application/config/routes/dev/twig.yaml b/tests/Application/config/routes/dev/twig.yaml deleted file mode 100755 index f4ee839..0000000 --- a/tests/Application/config/routes/dev/twig.yaml +++ /dev/null @@ -1,3 +0,0 @@ -_errors: - resource: '@TwigBundle/Resources/config/routing/errors.xml' - prefix: /_error diff --git a/tests/Application/config/routes/dev/web_profiler.yaml b/tests/Application/config/routes/dev/web_profiler.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/routes/liip_imagine.yaml b/tests/Application/config/routes/liip_imagine.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/routes/sylius_admin.yaml b/tests/Application/config/routes/sylius_admin.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/routes/sylius_api.yaml b/tests/Application/config/routes/sylius_api.yaml new file mode 100644 index 0000000..ae01ffc --- /dev/null +++ b/tests/Application/config/routes/sylius_api.yaml @@ -0,0 +1,3 @@ +sylius_api: + resource: "@SyliusApiBundle/Resources/config/routing.yml" + prefix: "%sylius.security.new_api_route%" diff --git a/tests/Application/config/routes/sylius_shop.yaml b/tests/Application/config/routes/sylius_shop.yaml old mode 100755 new mode 100644 index 8818568..92eeae0 --- a/tests/Application/config/routes/sylius_shop.yaml +++ b/tests/Application/config/routes/sylius_shop.yaml @@ -2,7 +2,7 @@ sylius_shop: resource: "@SyliusShopBundle/Resources/config/routing.yml" prefix: /{_locale} requirements: - _locale: ^[a-z]{2}(?:_[A-Z]{2})?$ + _locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$ sylius_shop_payum: resource: "@SyliusShopBundle/Resources/config/routing/payum.yml" diff --git a/tests/Application/config/routes/test/routing.yaml b/tests/Application/config/routes/test/routing.yaml new file mode 100644 index 0000000..0ca57d9 --- /dev/null +++ b/tests/Application/config/routes/test/routing.yaml @@ -0,0 +1,5 @@ +sylius_test_plugin_main: + path: /test/main + controller: FrameworkBundle:Template:template + defaults: + template: "@SyliusTestPlugin/main.html.twig" diff --git a/tests/Application/config/routes/test_cached/routing.yaml b/tests/Application/config/routes/test_cached/routing.yaml new file mode 100644 index 0000000..0ca57d9 --- /dev/null +++ b/tests/Application/config/routes/test_cached/routing.yaml @@ -0,0 +1,5 @@ +sylius_test_plugin_main: + path: /test/main + controller: FrameworkBundle:Template:template + defaults: + template: "@SyliusTestPlugin/main.html.twig" diff --git a/tests/Application/config/services.yaml b/tests/Application/config/services.yaml old mode 100755 new mode 100644 diff --git a/tests/Application/config/services_test.yaml b/tests/Application/config/services_test.yaml old mode 100755 new mode 100644 index b0bb222..9edf553 --- a/tests/Application/config/services_test.yaml +++ b/tests/Application/config/services_test.yaml @@ -1,3 +1,8 @@ imports: - { resource: "../../Behat/Resources/services.yml" } - { resource: "../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml" } + +# workaround needed for strange "test.client.history" problem +# see https://github.com/FriendsOfBehat/SymfonyExtension/issues/88 +services: + Symfony\Component\BrowserKit\AbstractBrowser: '@test.client' diff --git a/tests/Application/config/sylius/1.10/bundles.php b/tests/Application/config/sylius/1.10/bundles.php new file mode 100644 index 0000000..bd33f4a --- /dev/null +++ b/tests/Application/config/sylius/1.10/bundles.php @@ -0,0 +1,6 @@ + ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], +]; diff --git a/tests/Application/config/sylius/1.10/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.10/packages/dev/jms_serializer.yaml new file mode 100644 index 0000000..2f32a9b --- /dev/null +++ b/tests/Application/config/sylius/1.10/packages/dev/jms_serializer.yaml @@ -0,0 +1,12 @@ +jms_serializer: + visitors: + json_serialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.10/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.10/packages/prod/jms_serializer.yaml new file mode 100644 index 0000000..c288182 --- /dev/null +++ b/tests/Application/config/sylius/1.10/packages/prod/jms_serializer.yaml @@ -0,0 +1,10 @@ +jms_serializer: + visitors: + json_serialization: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.10/packages/security.yaml b/tests/Application/config/sylius/1.10/packages/security.yaml new file mode 100644 index 0000000..1062810 --- /dev/null +++ b/tests/Application/config/sylius/1.10/packages/security.yaml @@ -0,0 +1,148 @@ +parameters: + sylius.security.admin_regex: "^/%sylius_admin.path_name%" + sylius.security.api_regex: "^/api" + sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++" + sylius.security.new_api_route: "/new-api" + sylius.security.new_api_regex: "^%sylius.security.new_api_route%" + sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin" + sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%" + sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/shop" + sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%" + +security: + always_authenticate_before_granting: true + providers: + sylius_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_api_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_chain_provider: + chain: + providers: [sylius_api_shop_user_provider, sylius_api_admin_user_provider] + + encoders: + Sylius\Component\User\Model\UserInterface: argon2i + firewalls: + admin: + switch_user: true + context: admin + pattern: "%sylius.security.admin_regex%" + provider: sylius_admin_user_provider + form_login: + provider: sylius_admin_user_provider + login_path: sylius_admin_login + check_path: sylius_admin_login_check + failure_path: sylius_admin_login + default_target_path: sylius_admin_dashboard + use_forward: false + use_referer: true + csrf_token_generator: security.csrf.token_manager + csrf_parameter: _csrf_admin_security_token + csrf_token_id: admin_authenticate + remember_me: + secret: "%env(APP_SECRET)%" + path: "/%sylius_admin.path_name%" + name: APP_ADMIN_REMEMBER_ME + lifetime: 31536000 + remember_me_parameter: _remember_me + logout: + path: sylius_admin_logout + target: sylius_admin_login + anonymous: true + + new_api_admin_user: + pattern: "%sylius.security.new_api_route%/admin-user-authentication-token" + provider: sylius_admin_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/admin-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api_shop_user: + pattern: "%sylius.security.new_api_route%/shop-user-authentication-token" + provider: sylius_shop_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/shop-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api: + pattern: "%sylius.security.new_api_regex%/*" + provider: sylius_api_chain_provider + stateless: true + anonymous: lazy + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + shop: + switch_user: { role: ROLE_ALLOWED_TO_SWITCH } + context: shop + pattern: "%sylius.security.shop_regex%" + provider: sylius_shop_user_provider + form_login: + success_handler: sylius.authentication.success_handler + failure_handler: sylius.authentication.failure_handler + provider: sylius_shop_user_provider + login_path: sylius_shop_login + check_path: sylius_shop_login_check + failure_path: sylius_shop_login + default_target_path: sylius_shop_homepage + use_forward: false + use_referer: true + csrf_token_generator: security.csrf.token_manager + csrf_parameter: _csrf_shop_security_token + csrf_token_id: shop_authenticate + remember_me: + secret: "%env(APP_SECRET)%" + name: APP_SHOP_REMEMBER_ME + lifetime: 31536000 + remember_me_parameter: _remember_me + logout: + path: sylius_shop_logout + target: sylius_shop_login + invalidate_session: false + success_handler: sylius.handler.shop_user_logout + anonymous: true + + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + + access_control: + - { path: "%sylius.security.admin_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.admin_regex%/_partial", role: ROLE_NO_ACCESS } + - { path: "%sylius.security.shop_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS } + + - { path: "%sylius.security.admin_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.api_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.shop_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + + - { path: "%sylius.security.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.shop_regex%/verify", role: IS_AUTHENTICATED_ANONYMOUSLY } + + - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } + - { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY } diff --git a/tests/Application/config/sylius/1.9/bundles.php b/tests/Application/config/sylius/1.9/bundles.php new file mode 100644 index 0000000..66f523d --- /dev/null +++ b/tests/Application/config/sylius/1.9/bundles.php @@ -0,0 +1,8 @@ + ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], + FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true], + Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true], +]; diff --git a/tests/Application/config/sylius/1.9/packages/_sylius.yaml b/tests/Application/config/sylius/1.9/packages/_sylius.yaml new file mode 100644 index 0000000..1674a97 --- /dev/null +++ b/tests/Application/config/sylius/1.9/packages/_sylius.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" } diff --git a/tests/Application/config/packages/security.yaml b/tests/Application/config/sylius/1.9/packages/security.yaml old mode 100755 new mode 100644 similarity index 58% rename from tests/Application/config/packages/security.yaml rename to tests/Application/config/sylius/1.9/packages/security.yaml index 830b03d..8161bda --- a/tests/Application/config/packages/security.yaml +++ b/tests/Application/config/sylius/1.9/packages/security.yaml @@ -1,16 +1,31 @@ parameters: - sylius.security.admin_regex: "^/admin" + sylius.security.admin_regex: "^/%sylius_admin.path_name%" sylius.security.api_regex: "^/api" - sylius.security.shop_regex: "^/(?!admin|api/.*|api$|media/.*)[^/]++" + sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++" + sylius.security.new_api_route: "/new-api" + sylius.security.new_api_regex: "^%sylius.security.new_api_route%" + sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin" + sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%" + sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/shop" + sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%" security: + always_authenticate_before_granting: true providers: sylius_admin_user_provider: id: sylius.admin_user_provider.email_or_name_based + sylius_api_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based sylius_shop_user_provider: id: sylius.shop_user_provider.email_or_name_based + sylius_api_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_chain_provider: + chain: + providers: [sylius_api_shop_user_provider, sylius_api_admin_user_provider] + encoders: - Sylius\Component\User\Model\UserInterface: sha512 + Sylius\Component\User\Model\UserInterface: argon2i firewalls: admin: switch_user: true @@ -30,7 +45,7 @@ security: csrf_token_id: admin_authenticate remember_me: secret: "%env(APP_SECRET)%" - path: /admin + path: "/%sylius_admin.path_name%" name: APP_ADMIN_REMEMBER_ME lifetime: 31536000 remember_me_parameter: _remember_me @@ -43,6 +58,45 @@ security: pattern: "%sylius.security.api_regex%/oauth/v2/token" security: false + new_api_admin_user: + pattern: "%sylius.security.new_api_route%/admin-user-authentication-token" + provider: sylius_admin_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/admin-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api_shop_user: + pattern: "%sylius.security.new_api_route%/shop-user-authentication-token" + provider: sylius_shop_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/shop-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api: + pattern: "%sylius.security.new_api_regex%/*" + provider: sylius_api_chain_provider + stateless: true + anonymous: lazy + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + api: pattern: "%sylius.security.api_regex%/.*" provider: sylius_admin_user_provider @@ -100,3 +154,6 @@ security: - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } - { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS } - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY } diff --git a/tests/Application/config/routes/sylius_admin_api.yaml b/tests/Application/config/sylius/1.9/routes/sylius_admin_api.yaml old mode 100755 new mode 100644 similarity index 100% rename from tests/Application/config/routes/sylius_admin_api.yaml rename to tests/Application/config/sylius/1.9/routes/sylius_admin_api.yaml diff --git a/tests/Application/gulpfile.babel.js b/tests/Application/gulpfile.babel.js old mode 100755 new mode 100644 diff --git a/tests/Application/package.json b/tests/Application/package.json old mode 100755 new mode 100644 index b373489..b27949d --- a/tests/Application/package.json +++ b/tests/Application/package.json @@ -2,12 +2,14 @@ "dependencies": { "babel-polyfill": "^6.26.0", "chart.js": "^2.9.3", - "jquery": "^3.2.0", + "jquery": "^3.4.0", + "jquery.dirtyforms": "^2.0.0", "lightbox2": "^2.9.0", "semantic-ui-css": "^2.2.0", "slick-carousel": "^1.8.1" }, "devDependencies": { + "@symfony/webpack-encore": "^0.28.0", "babel-core": "^6.26.3", "babel-plugin-external-helpers": "^6.22.0", "babel-plugin-module-resolver": "^3.1.1", @@ -18,25 +20,26 @@ "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", + "eslint-plugin-import": "^2.11.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-livereload": "^4.0.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": "^0.60.2", "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", + "sass-loader": "^7.0.1", "upath": "^1.1.0", "yargs": "^6.4.0" }, diff --git a/tests/Application/public/.htaccess b/tests/Application/public/.htaccess old mode 100755 new mode 100644 diff --git a/tests/Application/public/favicon.ico b/tests/Application/public/favicon.ico old mode 100755 new mode 100644 diff --git a/tests/Application/public/index.php b/tests/Application/public/index.php old mode 100755 new mode 100644 index 366456a..d52ac01 --- a/tests/Application/public/index.php +++ b/tests/Application/public/index.php @@ -1,10 +1,12 @@