diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 50e4bd60..0353bee3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,25 +20,24 @@ jobs: strategy: fail-fast: false matrix: - php: ["8.0"] - symfony: ["^5.4", "^6.0"] - sylius: ["~1.11.0", "~1.12.0"] - node: ["^14.17.x"] - mysql: ["5.7", "8.0"] - + php: [ "8.0", "8.1", "8.2", "8.3" ] + symfony: [ "^5.4", "^6.0" ] + sylius: [ "~1.12.0", "~1.13.0" ] + node: [ "18.x", "20.x" ] + mysql: [ "8.0" ] exclude: - - # Segmentation fault while clearing cache - php: 8.0 - mysql: 5.7 - - sylius: ~1.11.0 - symfony: ^6.0 + - sylius: "~1.13.0" + php: "8.0" + - sylius: "~1.12.0" + php: "8.0" + symfony: "^6.4" env: APP_ENV: test DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -49,7 +48,7 @@ jobs: coverage: none - name: Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: "${{ matrix.node }}" @@ -152,11 +151,21 @@ jobs: - name: Run PHPSpec run: vendor/bin/phpspec run --ansi -f progress --no-interaction + - name: Run PHPUnit + run: vendor/bin/phpunit --colors=always + + - + name: Run PHPStan + run: vendor/bin/phpstan analyse -c phpstan.neon.dist -l 8 src/ + + - name: Run ECS + run: vendor/bin/ecs + - name: Run Behat run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun - name: Upload Behat logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: Behat logs @@ -164,13 +173,13 @@ jobs: if-no-files-found: ignore - name: Upload test log logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: Var logs path: tests/Application/var/log/ if-no-files-found: ignore - + - name: Failed build Slack notification uses: rtCamp/action-slack-notify@v2 if: ${{ failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }} diff --git a/README.md b/README.md index 3f55b34a..cd1eb2bc 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ This plugin allows users to create multiple carts for their own use. # Installation --- -The SyliusMulticartPlugin installation process can be found **[here](./doc/01-installation.md).** +The SyliusMulticartPlugin installation process can be found **[here](./doc/installation.md).** # Testing --- diff --git a/composer.json b/composer.json index 3541c519..ddb86d3b 100644 --- a/composer.json +++ b/composer.json @@ -9,17 +9,17 @@ "license": "MIT", "require": { "php": "^8.0", - "sylius/sylius": "~1.11.0 || ~1.12.0" + "sylius/sylius": "~1.12.0 || ~1.13.0" }, "require-dev": { - "behat/behat": "^3.6.1", + "behat/behat": "^3.7", "behat/mink-selenium2-driver": "^1.4", - "bitbag/coding-standard": "^1.0", + "bitbag/coding-standard": "^3.0", "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-debug-extension": "^2.0", "friends-of-behat/mink-extension": "^2.4", "friends-of-behat/page-object-extension": "^0.3", "friends-of-behat/suite-settings-extension": "^1.0", @@ -28,10 +28,10 @@ "lchrusciel/api-test-case": "^5.2", "phpspec/phpspec": "^7.0", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "0.12.85", - "phpstan/phpstan-doctrine": "0.12.33", - "phpstan/phpstan-strict-rules": "^0.12.0", - "phpstan/phpstan-webmozart-assert": "0.12.12", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-doctrine": "^1.3", + "phpstan/phpstan-strict-rules": "^1.3.0", + "phpstan/phpstan-webmozart-assert": "^1.2.0", "phpunit/phpunit": "^9.5", "sylius-labs/coding-standard": "^4.0", "symfony/browser-kit": "^5.4 || ^6.0", @@ -39,9 +39,10 @@ "symfony/dotenv": "^5.4 || ^6.0", "symfony/intl": "^5.4 || ^6.0", "symfony/web-profiler-bundle": "^5.4 || ^6.0", - "symfony/webpack-encore-bundle": "^1.13", - "vimeo/psalm": "4.12", - "polishsymfonycommunity/symfony-mocker-container": "^1.0" + "symfony/webpack-encore-bundle": "^1.16", + "vimeo/psalm": "4.27", + "polishsymfonycommunity/symfony-mocker-container": "^1.0", + "doctrine/dbal": "^2.7 || ^3.0" }, "config": { "sort-packages": true, @@ -51,11 +52,6 @@ "symfony/thanks": false } }, - "extra": { - "branch-alias": { - "dev-master": "1.10-dev" - } - }, "autoload": { "psr-4": { "BitBag\\SyliusMultiCartPlugin\\": "src/", @@ -79,6 +75,7 @@ ] }, "conflict": { - "doctrine/dbal": "^3.0" + "behat/mink-selenium2-driver": ">=1.7.0", + "doctrine/persistence": "<3.0" } } diff --git a/doc/01-installation.md b/doc/01-installation.md deleted file mode 100644 index 3ad075c4..00000000 --- a/doc/01-installation.md +++ /dev/null @@ -1,285 +0,0 @@ -# BitBag SyliusMulticartPlugin -## Installation -1. *We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.* -2. Require plugin with composer: - ```bash - composer require bitbag/multi-cart-plugin - ``` -3. Add plugin dependencies to your `config/bundles.php` file: - ```php - return [ - ... - BitBag\SyliusMulticartPlugin\BitBagSyliusMulticartPlugin::class => ['all' => true], - ]; - ``` -4. Add traits to your Customer entity class, when You don't use annotation. - ```php - - - - - - - - - - - - ``` - For an example, check [/vendor/bitbag/multicart-plugin/src/Resources/config/doctrine/Customer.orm.xml]() file. - Override Customer resource: - - ```yaml - # config/packages/_sylius.yaml - ... - sylius_customer: - resources: - customer: - classes: - model: App\Entity\Customer\Customer - ``` -5. Add traits to your Order entity class, when You don't use annotation. - ```php - - - - - - - ``` - Override Order resource: - ```yaml - # config/packages/_sylius.yaml - ... - sylius_order: - resources: - order: - classes: - model: App\Entity\Order\Order - ``` -6. Add traits to your OrderItem entity class, when You don't use annotation. - ```php - id = $id; - $this->quantity = $quantity; - $this->name = $name; - $this->formattedUnitPrice = $formattedUnitPrice; - } - } - ``` - Or this way if you use annotations: - ```php - id = $id; - $this->quantity = $quantity; - $this->name = $name; - $this->formattedUnitPrice = $formattedUnitPrice; - } - } - } - ``` - If you don't use annotations, define new Entity mapping inside your src/Resources/config/doctrine directory. - ```xml - - - - - - - - ``` - Override OrderItem resource: - ```yaml - # config/packages/_sylius.yaml - ... - sylius_order: - resources: - order_item: - classes: - model: App\Entity\Order\OrderItem - ``` -7. Add an import to Sylius configuration: - ```yaml - # config/packages/_sylius.yaml - @@ -29,7 +303,7 @@ - # ... - - { resource: "@BitBagSyliusMultiCartPlugin/Resources/config/config.yml" } - ``` -8. Import routing in your `config/routes.yaml` file: - ```yaml - # config/routes.yaml - @@ -38,13 +312,13 @@ - resource: "@BitBagSyliusMultiCartPlugin/Resources/config/routing.yml" - ``` -9. Update your database - ```bash - $ bin/console doctrine:migrations:migrate - ``` -10. Add plugin assets to your project - -We recommend you to use Webpack (Encore), for which we have prepared four different instructions on how to add this plugin's assets to your project: - -- [Import webpack config](./01.1-webpack-config.md)* -- [Add entry to existing config](./01.2-webpack-entry.md) -- [Import entries in your entry.js files](./01.3-import-entry.md) -- [Your own custom config](./01.4-custom-solution.md) - -* Default option for plugin development - - -However, if you are not using Webpack, here are instructions on how to add optimized and compressed assets directly to your project templates: - -- [Non webpack solution](./01.5-non-webpack.md) diff --git a/doc/installation.md b/doc/installation.md new file mode 100644 index 00000000..96f9a8a0 --- /dev/null +++ b/doc/installation.md @@ -0,0 +1,289 @@ +# Installation + +## Overview: +GENERAL +- [Requirements](#requirements) +- [Composer](#composer) +- [Basic configuration](#basic-configuration) +--- +BACKEND +- [Entities](#entities) + - [Attribute mapping](#attribute-mapping) + - [XML mapping](#xml-mapping) +- [Repositories](#repositories) +--- +FRONTEND +- [Templates](#templates) +- [Webpack](#webpack) +--- +ADDITIONAL +- [Known Issues](#known-issues) +--- + +## Requirements: +We work on stable, supported and up-to-date versions of packages. We recommend you to do the same. + +| Package | Version | +|---------------|-----------------| +| PHP | \>=8.0 | +| sylius/sylius | 1.12.x - 1.13.x | +| MySQL | \>= 5.7 | +| NodeJS | \>= 18.x | + +## Composer: +```bash +composer require bitbag/multicart-plugin --no-scripts +``` + +## Basic configuration: +Add plugin dependencies to your `config/bundles.php` file: + +```php +# config/bundles.php + +return [ + ... + BitBag\SyliusMultiCartPlugin\BitBagSyliusMultiCartPlugin::class => ['all' => true], +]; +``` + +Import required config in your `config/packages/_sylius.yaml` file: + +```yaml +# config/packages/_sylius.yaml + +imports: + ... + - { resource: "@BitBagSyliusMultiCartPlugin/Resources/config/config.yml" } +``` + +Add routing to your `config/routes.yaml` file: +```yaml +# config/routes.yaml + +bitbag_sylius_multi_cart: + resource: "@BitBagSyliusMultiCartPlugin/Resources/config/routing.yml" +``` + +## Entities +You can implement entity configuration by using both xml-mapping and attribute-mapping. Depending on your preference, choose either one or the other: +### Attribute mapping +- [Attribute mapping configuration](installation/attribute-mapping.md) +### XML mapping +- [XML mapping configuration](installation/xml-mapping.md) + +## Repositories +Add repository with following trait: +```php +createQueryBuilder('o') + ->andWhere('o.state = :state') + ->andWhere('o.channel = :channel') + ->andWhere('o.customer = :customer') + ->setParameter('state', OrderInterface::STATE_CART) + ->setParameter('channel', $channel) + ->setParameter('customer', $customer) + ->addOrderBy('o.cartNumber', 'DESC') + ->getQuery() + ->getResult() + ; + } + + public function findCartsGraterOrEqualNumber( + ChannelInterface $channel, + CustomerInterface $customer, + int $cartNumber, + ): array { + return $this->createQueryBuilder('o') + ->andWhere('o.state = :state') + ->andWhere('o.channel = :channel') + ->andWhere('o.customer = :customer') + ->andWhere('o.cartNumber >= :cartNumber') + ->setParameter('state', OrderInterface::STATE_CART) + ->setParameter('channel', $channel) + ->setParameter('customer', $customer) + ->setParameter('cartNumber', $cartNumber) + ->addOrderBy('o.cartNumber', 'ASC') + ->getQuery() + ->getResult() + ; + } + + public function findBiggestCartNumber( + ChannelInterface $channel, + CustomerInterface $customer, + ): int { + return (int) $this->createQueryBuilder('o') + ->select('MAX(o.cartNumber)') + ->andWhere('o.state = :state') + ->andWhere('o.channel = :channel') + ->andWhere('o.customer = :customer') + ->setParameter('state', OrderInterface::STATE_CART) + ->setParameter('channel', $channel) + ->setParameter('customer', $customer) + ->addOrderBy('o.createdAt', 'DESC') + ->getQuery() + ->getSingleScalarResult() + ; + } + + public function countCarts(ChannelInterface $channel, ?CustomerInterface $customer): int + { + return (int) $this->createQueryBuilder('o') + ->select('COUNT(o.id)') + ->andWhere('o.state = :state') + ->andWhere('o.channel = :channel') + ->andWhere('o.customer = :customer') + ->setParameter('state', OrderInterface::STATE_CART) + ->setParameter('channel', $channel) + ->setParameter('customer', $customer) + ->addOrderBy('o.createdAt', 'DESC') + ->getQuery() + ->getSingleScalarResult() + ; + } + + public function findLatestNotEmptyActiveCart( + ChannelInterface $channel, + CustomerInterface $customer, + ): ?OrderInterface { + return $this->createQueryBuilder('o') + ->andWhere('o.state = :state') + ->andWhere('o.channel = :channel') + ->andWhere('o.customer = :customer') + ->andWhere('o.cartNumber = :activeCart') + ->setParameter('state', OrderInterface::STATE_CART) + ->setParameter('channel', $channel) + ->setParameter('customer', $customer) + ->setParameter('activeCart', $customer->getActiveCart()) + ->addOrderBy('o.createdAt', 'DESC') + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult() + ; + } +} +``` + +Override `config/packages/_sylius.yaml` configuration: +```yaml +# config/packages/_sylius.yaml + +sylius_order: + resources: + order: + classes: + ... + repository: App\Repository\OrderRepository +``` + +### Update your database +First, please run legacy-versioned migrations by using command: +```bash +bin/console doctrine:migrations:migrate +``` + +After migration, please create a new diff migration and update database: +```bash +bin/console doctrine:migrations:diff +bin/console doctrine:migrations:migrate +``` +**Note:** If you are running it on production, add the `-e prod` flag to this command. + +### Clear application cache by using command: +```bash +bin/console cache:clear +``` +**Note:** If you are running it on production, add the `-e prod` flag to this command. + +## Templates +Copy required templates into correct directories in your project. + +**ShopBundle** (`templates/bundles/SyliusShopBundle`): +``` +vendor/bitbag/multicart-plugin/tests/Application/templates/bundles/SyliusShopBundle/Cart/summary.html.twig + +vendor/bitbag/multicart-plugin/tests/Application/templates/bundles/SyliusShopBundle/Cart/Summary/_header.html.twig +vendor/bitbag/multicart-plugin/tests/Application/templates/bundles/SyliusShopBundle/Cart/Summary/_items.html.twig +vendor/bitbag/multicart-plugin/tests/Application/templates/bundles/SyliusShopBundle/Cart/Summary/_totals.html.twig + +vendor/bitbag/multicart-plugin/tests/Application/templates/bundles/SyliusShopBundle/Cart/Widget/_button.html.twig +vendor/bitbag/multicart-plugin/tests/Application/templates/bundles/SyliusShopBundle/Cart/Widget/_popup.html.twig +vendor/bitbag/multicart-plugin/tests/Application/templates/bundles/SyliusShopBundle/Cart/Widget/_popup_carts.html.twig +vendor/bitbag/multicart-plugin/tests/Application/templates/bundles/SyliusShopBundle/Cart/Widget/_popup_items.html.twig +``` + +## Webpack +### Webpack.config.js + +Please setup your `webpack.config.js` file to require the plugin's webpack configuration. To do so, please put the line below somewhere on top of your webpack.config.js file: +```js +const [bitbagMulticartShop] = require('./vendor/bitbag/multicart-plugin/webpack.config') +``` +As next step, please add the imported consts into final module exports: +```js +module.exports = [..., bitbagMulticartShop]; +``` + +### Assets +Add the asset configuration into `config/packages/assets.yaml`: +```yaml +framework: + assets: + packages: + ... + multicart_shop: + json_manifest_path: '%kernel.project_dir%/public/build/bitbag/multicart/shop/manifest.json' +``` + +### Webpack Encore +Add the webpack configuration into `config/packages/webpack_encore.yaml`: + +```yaml +webpack_encore: + output_path: '%kernel.project_dir%/public/build/default' + builds: + ... + multicart_shop: '%kernel.project_dir%/public/build/bitbag/multicart/shop' +``` + +### Encore functions +Add encore functions to your templates: + +SyliusShopBundle: +```php +{# @SyliusShopBundle/_scripts.html.twig #} +{{ encore_entry_script_tags('bitbag-multicart-shop', null, 'multicart_shop') }} + +{# @SyliusShopBundle/_styles.html.twig #} +{{ encore_entry_link_tags('bitbag-multicart-shop', null, 'multicart_shop') }} +``` + +### Run commands +```bash +yarn install +yarn encore dev # or prod, depends on your environment +``` + +## Known issues +### Translations not displaying correctly +For incorrectly displayed translations, execute the command: +```bash +bin/console cache:clear +``` diff --git a/doc/installation/attribute-mapping.md b/doc/installation/attribute-mapping.md new file mode 100644 index 00000000..c43da133 --- /dev/null +++ b/doc/installation/attribute-mapping.md @@ -0,0 +1,61 @@ +# Attribute-mapping + +Check the mapping settings in `config/packages/doctrine.yaml` and, if necessary, change them accordingly. +```yaml +doctrine: + ... + orm: + ... + mappings: + App: + ... + type: attribute +``` + +Extend entities with parameters and methods using attributes and traits: + +- `Customer` entity: + +```php + + + + + + +``` + +- `Order` entity: + +`src/Resources/config/doctrine/Order.orm.xml` + +```xml + + + + + + +``` + +Override `config/packages/_sylius.yaml` configuration: +```yaml +# config/_sylius.yaml + +sylius_order: + resources: + order: + classes: + model: App\Entity\Order + +sylius_customer: + resources: + customer: + classes: + model: App\Entity\Customer +``` diff --git a/ecs.php b/ecs.php index 74fa67e6..0e36d84e 100644 --- a/ecs.php +++ b/ecs.php @@ -8,15 +8,19 @@ declare(strict_types=1); -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symplify\EasyCodingStandard\ValueObject\Option; +use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer; +use Symplify\EasyCodingStandard\Config\ECSConfig; -return static function (ContainerConfigurator $containerConfigurator): void { - $containerConfigurator->import('vendor/bitbag/coding-standard/ecs.php'); - - $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::PATHS, [ +return static function (ECSConfig $ecsConfig): void { + $ecsConfig->paths([ __DIR__ . '/src', - __DIR__ . '/tests', + __DIR__ . '/tests/Behat', + __DIR__ . '/ecs.php', + ]); + + $ecsConfig->import('vendor/sylius-labs/coding-standard/ecs.php'); + + $ecsConfig->skip([ + VisibilityRequiredFixer::class => ['*Spec.php'], ]); }; diff --git a/package.json b/package.json index 9c1b38ea..81bc2abf 100644 --- a/package.json +++ b/package.json @@ -9,4 +9,4 @@ "dist": "yarn encore production --config-name bitbag-plugin-dist" }, "dependencies": {} -} \ No newline at end of file +} diff --git a/phpstan.neon b/phpstan.neon.dist similarity index 80% rename from phpstan.neon rename to phpstan.neon.dist index 2d625f6d..04f9584b 100644 --- a/phpstan.neon +++ b/phpstan.neon.dist @@ -1,8 +1,13 @@ parameters: + level: 8 + + paths: + - src + reportUnmatchedIgnoredErrors: false checkMissingIterableValueType: false - excludes_analyse: + excludePaths: # Makes PHPStan crash - 'src/DependencyInjection/Configuration.php' @@ -11,4 +16,6 @@ parameters: - 'tests/Application/src/**.php' ignoreErrors: + - identifier: missingType.iterableValue + - identifier: missingType.generics - '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./' diff --git a/spec/Creator/DefaultCustomerCartCreatorSpec.php b/spec/Creator/DefaultCustomerCartCreatorSpec.php index f57c821b..1c05c2da 100644 --- a/spec/Creator/DefaultCustomerCartCreatorSpec.php +++ b/spec/Creator/DefaultCustomerCartCreatorSpec.php @@ -18,11 +18,9 @@ use PhpSpec\ObjectBehavior; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Core\Model\ChannelInterface; -use Sylius\Component\Currency\Context\CurrencyNotFoundException; use Sylius\Component\Customer\Context\CustomerContextInterface; use Sylius\Component\Order\Context\CartContextInterface; use Sylius\Component\Order\Context\CartNotFoundException; -use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; class DefaultCustomerCartCreatorSpec extends ObjectBehavior diff --git a/spec/DTO/AjaxPartialCartSpec.php b/spec/DTO/AjaxPartialCartSpec.php index 6f43c8c8..1f85be64 100644 --- a/spec/DTO/AjaxPartialCartSpec.php +++ b/spec/DTO/AjaxPartialCartSpec.php @@ -11,8 +11,8 @@ namespace spec\BitBag\SyliusMultiCartPlugin\DTO; use BitBag\SyliusMultiCartPlugin\DTO\AjaxPartialCart; -use BitBag\SyliusMultiCartPlugin\Entity\OrderItem; use PhpSpec\ObjectBehavior; +use Sylius\Component\Core\Model\OrderItem; final class AjaxPartialCartSpec extends ObjectBehavior { diff --git a/spec/Entity/CustomerSpec.php b/spec/Entity/CustomerSpec.php deleted file mode 100644 index 59a4c533..00000000 --- a/spec/Entity/CustomerSpec.php +++ /dev/null @@ -1,35 +0,0 @@ -shouldHaveType(Customer::class); - } - - function it_is_implementing_customer_interface(): void - { - $this->shouldHaveType(CustomerInterface::class); - } - - function it_sets_and_gets_active_cart(): void - { - $this->setActiveCart(1); - - $this->getActiveCart()->shouldReturn(1); - } -} diff --git a/spec/Entity/OrderSpec.php b/spec/Entity/OrderSpec.php deleted file mode 100644 index b104970d..00000000 --- a/spec/Entity/OrderSpec.php +++ /dev/null @@ -1,35 +0,0 @@ -shouldHaveType(Order::class); - } - - function it_is_implementing_order_interface(): void - { - $this->shouldHaveType(OrderInterface::class); - } - - function it_sets_and_gets_cart_number(): void - { - $this->setCartNumber(1); - - $this->getCartNumber()->shouldReturn(1); - } -} diff --git a/spec/Factory/AjaxPartialCartFactorySpec.php b/spec/Factory/AjaxPartialCartFactorySpec.php index bea7921c..8be1d573 100644 --- a/spec/Factory/AjaxPartialCartFactorySpec.php +++ b/spec/Factory/AjaxPartialCartFactorySpec.php @@ -16,12 +16,9 @@ use BitBag\SyliusMultiCartPlugin\Factory\AjaxPartialCartFactoryInterface; use BitBag\SyliusMultiCartPlugin\Factory\OrderItemFactoryInterface; use BitBag\SyliusMultiCartPlugin\MoneyFormatter\MoneyFormatterInterface; +use BitBag\SyliusMultiCartPlugin\View\OrderItemView; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Common\Collections\Collection; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; -use Sylius\Component\Core\Model\OrderItemInterface as BaseOrderItemInterface; -use BitBag\SyliusMultiCartPlugin\Entity\OrderItem; use Sylius\Component\Core\Model\OrderItemInterface; final class AjaxPartialCartFactorySpec extends ObjectBehavior @@ -51,7 +48,7 @@ function it_creates_partial_cart_from_order( OrderItemInterface $orderItem, MoneyFormatterInterface $convertAndFormatMoneyHelper, OrderItemFactoryInterface $ajaxPartialCartItemFactory, - OrderItem $multicartOrderItem + OrderItemView $multicartOrderItem ): void { $order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); diff --git a/spec/Factory/OrderItemFactorySpec.php b/spec/Factory/OrderItemFactorySpec.php index b15774a4..e2be4f08 100644 --- a/spec/Factory/OrderItemFactorySpec.php +++ b/spec/Factory/OrderItemFactorySpec.php @@ -13,10 +13,10 @@ use BitBag\SyliusMultiCartPlugin\Factory\OrderItemFactory; use BitBag\SyliusMultiCartPlugin\Factory\OrderItemFactoryInterface; use BitBag\SyliusMultiCartPlugin\MoneyFormatter\MoneyFormatterInterface; +use BitBag\SyliusMultiCartPlugin\View\OrderItemView; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Sylius\Component\Core\Model\OrderItem as BaseOrderItem; -use BitBag\SyliusMultiCartPlugin\Entity\OrderItem; final class OrderItemFactorySpec extends ObjectBehavior { @@ -49,6 +49,6 @@ function it_creates_partial_cart_item_from_order_item( $convertAndFormatMoneyHelper->formatMoney(Argument::type('integer'))->willReturn('converted_string'); - $this->fromOrderItem($orderItem)->shouldHaveType(OrderItem::class); + $this->fromOrderItem($orderItem)->shouldHaveType(OrderItemView::class); } } diff --git a/spec/MoneyConverter/MoneyConverterSpec.php b/spec/MoneyConverter/MoneyConverterSpec.php index 9d765a4d..19537def 100644 --- a/spec/MoneyConverter/MoneyConverterSpec.php +++ b/spec/MoneyConverter/MoneyConverterSpec.php @@ -12,11 +12,8 @@ use BitBag\SyliusMultiCartPlugin\MoneyConverter\MoneyConverter; use BitBag\SyliusMultiCartPlugin\MoneyConverter\MoneyConverterInterface; -use BitBag\SyliusMultiCartPlugin\MoneyFormatter\MoneyFormatter; -use BitBag\SyliusMultiCartPlugin\MoneyFormatter\MoneyFormatterInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; -use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface as BaseMoneyFormatterInterface; use Sylius\Component\Core\Context\ShopperContext; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Currency\Converter\CurrencyConverterInterface; diff --git a/spec/MoneyFormatter/MoneyFormatterSpec.php b/spec/MoneyFormatter/MoneyFormatterSpec.php index cafce63c..389c7947 100644 --- a/spec/MoneyFormatter/MoneyFormatterSpec.php +++ b/spec/MoneyFormatter/MoneyFormatterSpec.php @@ -15,9 +15,7 @@ use Prophecy\Argument; use BitBag\SyliusMultiCartPlugin\MoneyFormatter\MoneyFormatterInterface; use Sylius\Component\Core\Context\ShopperContext; -use Sylius\Component\Core\Model\ChannelInterface; use BitBag\SyliusMultiCartPlugin\MoneyConverter\MoneyConverterInterface; -use Sylius\Component\Currency\Model\CurrencyInterface; use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface as BaseMoneyFormatterInterface; final class MoneyFormatterSpec extends ObjectBehavior diff --git a/spec/Remover/CartRemoverSpec.php b/spec/Remover/CartRemoverSpec.php index 5fdbf188..5c34978e 100644 --- a/spec/Remover/CartRemoverSpec.php +++ b/spec/Remover/CartRemoverSpec.php @@ -17,12 +17,10 @@ use BitBag\SyliusMultiCartPlugin\Repository\OrderRepositoryInterface; use Doctrine\ORM\EntityManagerInterface; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Customer\Context\CustomerContextInterface; use Sylius\Component\Order\Context\CartNotFoundException; -use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; class CartRemoverSpec extends ObjectBehavior diff --git a/src/Cart/Context/CustomerAndChannelBasedMultiCartContext.php b/src/Cart/Context/CustomerAndChannelBasedMultiCartContext.php index 5fbdac73..f5cad1fe 100644 --- a/src/Cart/Context/CustomerAndChannelBasedMultiCartContext.php +++ b/src/Cart/Context/CustomerAndChannelBasedMultiCartContext.php @@ -10,9 +10,11 @@ namespace BitBag\SyliusMultiCartPlugin\Cart\Context; +use BitBag\SyliusMultiCartPlugin\Entity\CustomerInterface; use BitBag\SyliusMultiCartPlugin\Repository\OrderRepositoryInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Channel\Context\ChannelNotFoundException; +use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Customer\Context\CustomerContextInterface; use Sylius\Component\Order\Context\CartContextInterface; use Sylius\Component\Order\Context\CartNotFoundException; @@ -33,7 +35,7 @@ public function __construct( CustomerContextInterface $customerContext, ChannelContextInterface $channelContext, OrderRepositoryInterface $orderRepository, - TranslatorInterface $translator + TranslatorInterface $translator, ) { $this->customerContext = $customerContext; $this->channelContext = $channelContext; @@ -44,24 +46,26 @@ public function __construct( public function getCart(): OrderInterface { try { + /** @var ChannelInterface $channel */ $channel = $this->channelContext->getChannel(); } catch (ChannelNotFoundException $exception) { throw new CartNotFoundException( - $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_as_there_is_no_current_channel') + $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_as_there_is_no_current_channel'), ); } + /** @var CustomerInterface|null $customer */ $customer = $this->customerContext->getCustomer(); if (null === $customer) { throw new CartNotFoundException( - $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_as_there_is_no_logged_in_user') + $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_as_there_is_no_logged_in_user'), ); } $cart = $this->orderRepository->findLatestNotEmptyActiveCart($channel, $customer); if (null === $cart) { throw new CartNotFoundException( - $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_for_currently_logged_in_user') + $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_for_currently_logged_in_user'), ); } diff --git a/src/Cart/Context/ShopBasedMultiCartContext.php b/src/Cart/Context/ShopBasedMultiCartContext.php index 8e31c555..055719c4 100644 --- a/src/Cart/Context/ShopBasedMultiCartContext.php +++ b/src/Cart/Context/ShopBasedMultiCartContext.php @@ -17,6 +17,7 @@ use Sylius\Component\Core\Context\ShopperContextInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Currency\Context\CurrencyNotFoundException; +use Sylius\Component\Currency\Model\CurrencyInterface; use Sylius\Component\Locale\Context\LocaleNotFoundException; use Sylius\Component\Order\Context\CartContextInterface; use Sylius\Component\Order\Context\CartNotFoundException; @@ -36,7 +37,7 @@ final class ShopBasedMultiCartContext implements CartContextInterface public function __construct( CartContextInterface $cartContext, ShopperContextInterface $shopperContext, - CartCustomizerInterface $cartCustomizer + CartCustomizerInterface $cartCustomizer, ) { $this->cartContext = $cartContext; $this->shopperContext = $shopperContext; @@ -50,7 +51,7 @@ public function getCart(): BaseOrderInterface } $cart = $this->cartContext->getCart(); - /** @var OrderInterface $cart */ + /** @var OrderInterface|null $cart */ Assert::isInstanceOf($cart, OrderInterface::class); try { @@ -58,7 +59,9 @@ public function getCart(): BaseOrderInterface $channel = $this->shopperContext->getChannel(); $cart->setChannel($channel); - $cart->setCurrencyCode($channel->getBaseCurrency()->getCode()); + /** @var CurrencyInterface $currency */ + $currency = $channel->getBaseCurrency(); + $cart->setCurrencyCode($currency->getCode()); $cart->setLocaleCode($this->shopperContext->getLocaleCode()); } catch (ChannelNotFoundException | CurrencyNotFoundException | LocaleNotFoundException $exception) { throw new CartNotFoundException('Sylius was not able to prepare the cart.', $exception); diff --git a/src/Controller/CartContentAction.php b/src/Controller/CartContentAction.php index 5960d7d5..f9a4845c 100644 --- a/src/Controller/CartContentAction.php +++ b/src/Controller/CartContentAction.php @@ -62,7 +62,7 @@ private function prepareContent(string $template, OrderInterface $cart): string $template, [ 'cart' => $cart, - ] + ], ); } } diff --git a/src/Controller/ChangeActiveCartAction.php b/src/Controller/ChangeActiveCartAction.php index cf3d7ead..8c502d9a 100644 --- a/src/Controller/ChangeActiveCartAction.php +++ b/src/Controller/ChangeActiveCartAction.php @@ -18,7 +18,7 @@ final class ChangeActiveCartAction private CartSwitcherInterface $switcher; public function __construct( - CartSwitcherInterface $switcher + CartSwitcherInterface $switcher, ) { $this->switcher = $switcher; } diff --git a/src/Controller/DeleteCartAction.php b/src/Controller/DeleteCartAction.php index 26aa0a6a..336eb44e 100644 --- a/src/Controller/DeleteCartAction.php +++ b/src/Controller/DeleteCartAction.php @@ -18,7 +18,7 @@ final class DeleteCartAction private CartRemoverInterface $remover; public function __construct( - CartRemoverInterface $remover + CartRemoverInterface $remover, ) { $this->remover = $remover; } diff --git a/src/Controller/GetActiveCartAction.php b/src/Controller/GetActiveCartAction.php index 74ec90ee..67df4160 100644 --- a/src/Controller/GetActiveCartAction.php +++ b/src/Controller/GetActiveCartAction.php @@ -28,7 +28,7 @@ final class GetActiveCartAction public function __construct( CartContextInterface $cartContext, SerializerInterface $serializer, - AjaxPartialCartFactoryInterface $ajaxPartialCartFactory + AjaxPartialCartFactoryInterface $ajaxPartialCartFactory, ) { $this->cartContext = $cartContext; $this->serializer = $serializer; diff --git a/src/Controller/NewCartAction.php b/src/Controller/NewCartAction.php index a9dff696..aafaa198 100644 --- a/src/Controller/NewCartAction.php +++ b/src/Controller/NewCartAction.php @@ -22,7 +22,7 @@ final class NewCartAction public function __construct( DefaultCustomerCartCreatorInterface $cartCreator, - EntityManagerInterface $entityManager + EntityManagerInterface $entityManager, ) { $this->cartCreator = $cartCreator; $this->entityManager = $entityManager; diff --git a/src/Controller/ShowCartsAction.php b/src/Controller/ShowCartsAction.php index 280d947a..e020b591 100644 --- a/src/Controller/ShowCartsAction.php +++ b/src/Controller/ShowCartsAction.php @@ -32,7 +32,7 @@ public function __construct( CustomerContextInterface $customerContext, ChannelContextInterface $channelContext, OrderRepositoryInterface $orderRepository, - Environment $twig + Environment $twig, ) { $this->customerContext = $customerContext; $this->channelContext = $channelContext; @@ -57,7 +57,7 @@ public function __invoke(string $template): Response 'customer' => $customer, 'carts' => $carts, 'counted' => $counted, - ] + ], ); return new Response($content); diff --git a/src/Creator/DefaultCustomerCartCreator.php b/src/Creator/DefaultCustomerCartCreator.php index 1fb4532c..b4dec985 100644 --- a/src/Creator/DefaultCustomerCartCreator.php +++ b/src/Creator/DefaultCustomerCartCreator.php @@ -42,7 +42,7 @@ public function __construct( CustomerContextInterface $customerContext, OrderRepositoryInterface $orderRepository, ChannelContextInterface $channelContext, - TranslatorInterface $translator + TranslatorInterface $translator, ) { $this->shopBasedMultiCartContext = $shopBasedMultiCartContext; $this->entityManager = $entityManager; @@ -64,7 +64,7 @@ public function createNewCart(): void if (self::MAX_CART_COUNT === $carts) { throw new CartNotFoundException( - $this->translator->trans('bitbag_sylius_multicart_plugin.ui.max_cart_number_reached') + $this->translator->trans('bitbag_sylius_multicart_plugin.ui.max_cart_number_reached'), ); } diff --git a/src/Customizer/CartCustomizer.php b/src/Customizer/CartCustomizer.php index 1d1dfdc6..2a316d1b 100644 --- a/src/Customizer/CartCustomizer.php +++ b/src/Customizer/CartCustomizer.php @@ -20,7 +20,7 @@ final class CartCustomizer implements CartCustomizerInterface private OrderRepositoryInterface $orderRepository; public function __construct( - OrderRepositoryInterface $orderRepository + OrderRepositoryInterface $orderRepository, ) { $this->orderRepository = $orderRepository; } @@ -40,7 +40,7 @@ public function copyDefaultToBillingAddress(OrderInterface $cart, CustomerInterf public function increaseCartNumberOnCart( ChannelInterface $channel, CustomerInterface $customer, - OrderInterface $cart + OrderInterface $cart, ): void { $counter = $this->orderRepository->findBiggestCartNumber($channel, $customer); diff --git a/src/Customizer/CartCustomizerInterface.php b/src/Customizer/CartCustomizerInterface.php index 3051aadc..d7979add 100644 --- a/src/Customizer/CartCustomizerInterface.php +++ b/src/Customizer/CartCustomizerInterface.php @@ -21,6 +21,6 @@ public function copyDefaultToBillingAddress(OrderInterface $cart, CustomerInterf public function increaseCartNumberOnCart( ChannelInterface $channel, CustomerInterface $customer, - OrderInterface $cart + OrderInterface $cart, ): void; } diff --git a/src/DTO/AjaxPartialCart.php b/src/DTO/AjaxPartialCart.php index 57944f0f..eaaaeb26 100644 --- a/src/DTO/AjaxPartialCart.php +++ b/src/DTO/AjaxPartialCart.php @@ -10,7 +10,7 @@ namespace BitBag\SyliusMultiCartPlugin\DTO; -use BitBag\SyliusMultiCartPlugin\Entity\OrderItem; +use Sylius\Component\Core\Model\OrderItem; class AjaxPartialCart { @@ -30,7 +30,7 @@ public function __construct( string $formattedItemsTotal, ?string $currency, array $items, - int $itemsCount + int $itemsCount, ) { $this->cartNumber = $cartNumber; $this->formattedItemsTotal = $formattedItemsTotal; diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php deleted file mode 100644 index c6695985..00000000 --- a/src/Entity/Customer.php +++ /dev/null @@ -1,18 +0,0 @@ -moneyFormatter = $moneyFormatter; $this->ajaxPartialCartItemFactory = $ajaxPartialCartItemFactory; @@ -39,7 +39,7 @@ public function fromOrder(OrderInterface $order): AjaxPartialCart $this->moneyFormatter->formatMoney($order->getItemsTotal()), $order->getCurrencyCode(), $this->createCartItems($orderItems)->toArray(), - $orderItems->count() + $orderItems->count(), ); } diff --git a/src/Factory/OrderItemFactory.php b/src/Factory/OrderItemFactory.php index ca79d4e7..d321b741 100644 --- a/src/Factory/OrderItemFactory.php +++ b/src/Factory/OrderItemFactory.php @@ -10,8 +10,8 @@ namespace BitBag\SyliusMultiCartPlugin\Factory; -use BitBag\SyliusMultiCartPlugin\Entity\OrderItem; use BitBag\SyliusMultiCartPlugin\MoneyFormatter\MoneyFormatterInterface; +use BitBag\SyliusMultiCartPlugin\View\OrderItemView; use Sylius\Component\Core\Model\OrderItemInterface; class OrderItemFactory implements OrderItemFactoryInterface @@ -23,11 +23,14 @@ public function __construct(MoneyFormatterInterface $convertAndFormatMoneyHelper $this->convertAndFormatMoneyHelper = $convertAndFormatMoneyHelper; } - public function fromOrderItem(OrderItemInterface $orderItem): OrderItem + public function fromOrderItem(OrderItemInterface $orderItem): OrderItemView { - return new OrderItem( + /** @var string $productName */ + $productName = $orderItem->getProductName(); + + return new OrderItemView( $orderItem->getId(), - $orderItem->getProductName(), + $productName, $orderItem->getQuantity(), $this->convertAndFormatMoneyHelper->formatMoney($orderItem->getUnitPrice()), ); diff --git a/src/Factory/OrderItemFactoryInterface.php b/src/Factory/OrderItemFactoryInterface.php index 7a857b73..6ae09ea0 100644 --- a/src/Factory/OrderItemFactoryInterface.php +++ b/src/Factory/OrderItemFactoryInterface.php @@ -10,10 +10,10 @@ namespace BitBag\SyliusMultiCartPlugin\Factory; -use BitBag\SyliusMultiCartPlugin\Entity\OrderItem; +use BitBag\SyliusMultiCartPlugin\View\OrderItemView; use Sylius\Component\Core\Model\OrderItemInterface; interface OrderItemFactoryInterface { - public function fromOrderItem(OrderItemInterface $orderItem): OrderItem; + public function fromOrderItem(OrderItemInterface $orderItem): OrderItemView; } diff --git a/src/Entity/CustomerTrait.php b/src/Model/CustomerTrait.php similarity index 92% rename from src/Entity/CustomerTrait.php rename to src/Model/CustomerTrait.php index 8e1c57c8..c38343be 100644 --- a/src/Entity/CustomerTrait.php +++ b/src/Model/CustomerTrait.php @@ -8,7 +8,7 @@ declare(strict_types=1); -namespace BitBag\SyliusMultiCartPlugin\Entity; +namespace BitBag\SyliusMultiCartPlugin\Model; trait CustomerTrait { diff --git a/src/Entity/OrderItemTrait.php b/src/Model/OrderItemTrait.php similarity index 92% rename from src/Entity/OrderItemTrait.php rename to src/Model/OrderItemTrait.php index 6f485cbc..6b836fa7 100644 --- a/src/Entity/OrderItemTrait.php +++ b/src/Model/OrderItemTrait.php @@ -8,7 +8,7 @@ declare(strict_types=1); -namespace BitBag\SyliusMultiCartPlugin\Entity; +namespace BitBag\SyliusMultiCartPlugin\Model; trait OrderItemTrait { diff --git a/src/Entity/OrderTrait.php b/src/Model/OrderTrait.php similarity index 92% rename from src/Entity/OrderTrait.php rename to src/Model/OrderTrait.php index e33123fe..fc8fe1d7 100644 --- a/src/Entity/OrderTrait.php +++ b/src/Model/OrderTrait.php @@ -8,7 +8,7 @@ declare(strict_types=1); -namespace BitBag\SyliusMultiCartPlugin\Entity; +namespace BitBag\SyliusMultiCartPlugin\Model; trait OrderTrait { diff --git a/src/MoneyConverter/MoneyConverter.php b/src/MoneyConverter/MoneyConverter.php index dc9249d6..257e3b87 100644 --- a/src/MoneyConverter/MoneyConverter.php +++ b/src/MoneyConverter/MoneyConverter.php @@ -13,6 +13,7 @@ use Sylius\Component\Core\Context\ShopperContext; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Currency\Converter\CurrencyConverterInterface; +use Sylius\Component\Currency\Model\CurrencyInterface; class MoneyConverter implements MoneyConverterInterface { @@ -22,7 +23,7 @@ class MoneyConverter implements MoneyConverterInterface public function __construct( ShopperContext $shopperContext, - CurrencyConverterInterface $currencyConverter + CurrencyConverterInterface $currencyConverter, ) { $this->shopperContext = $shopperContext; $this->currencyConverter = $currencyConverter; @@ -32,13 +33,16 @@ public function convertMoney(int $amount): int { /** @var ChannelInterface $channel */ $channel = $this->shopperContext->getChannel(); - $baseCurrency = $channel->getBaseCurrency()->getCode(); + /** @var CurrencyInterface $currency */ + $currency = $channel->getBaseCurrency(); + /** @var string $baseCurrency */ + $baseCurrency = $currency->getCode(); $currencyCode = $this->shopperContext->getCurrencyCode(); return $this->currencyConverter->convert( $amount, $baseCurrency, - $currencyCode + $currencyCode, ); } } diff --git a/src/MoneyFormatter/MoneyFormatter.php b/src/MoneyFormatter/MoneyFormatter.php index e1be4b76..09d1936f 100644 --- a/src/MoneyFormatter/MoneyFormatter.php +++ b/src/MoneyFormatter/MoneyFormatter.php @@ -25,7 +25,7 @@ class MoneyFormatter implements MoneyFormatterInterface public function __construct( BaseMoneyFormatterInterface $moneyFormatter, ShopperContext $shopperContext, - MoneyConverterInterface $currencyConverter + MoneyConverterInterface $currencyConverter, ) { $this->moneyFormatter = $moneyFormatter; $this->shopperContext = $shopperContext; @@ -39,7 +39,7 @@ public function formatMoney(int $amount): string return $this->moneyFormatter->format( $convertedAmount, - $currencyCode + $currencyCode, ); } } diff --git a/src/Remover/CartRemover.php b/src/Remover/CartRemover.php index 38bd2e09..40de4883 100644 --- a/src/Remover/CartRemover.php +++ b/src/Remover/CartRemover.php @@ -16,6 +16,7 @@ use BitBag\SyliusMultiCartPlugin\Repository\OrderRepositoryInterface; use Doctrine\ORM\EntityManagerInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; +use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Customer\Context\CustomerContextInterface; use Sylius\Component\Order\Context\CartNotFoundException; use Symfony\Contracts\Translation\TranslatorInterface; @@ -37,7 +38,7 @@ public function __construct( CustomerContextInterface $customerContext, OrderRepositoryInterface $orderRepository, EntityManagerInterface $entityManager, - TranslatorInterface $translator + TranslatorInterface $translator, ) { $this->channelContext = $channelContext; $this->customerContext = $customerContext; @@ -48,11 +49,12 @@ public function __construct( public function removeCart(int $cartNumber): void { - /** @var CustomerInterface|null $customer */ + /** @var CustomerInterface $customer */ $customer = $this->customerContext->getCustomer(); $this->validateCustomerIsNotNull($customer); $this->validateRemovableCart($cartNumber, $customer); + /** @var ChannelInterface $channel */ $channel = $this->channelContext->getChannel(); $carts = $this->orderRepository->findCartsGraterOrEqualNumber( @@ -74,16 +76,16 @@ public function removeCart(int $cartNumber): void $this->entityManager->flush(); } - private function validateCustomerIsNotNull($customer): void + private function validateCustomerIsNotNull(?CustomerInterface $customer): void { if (null === $customer) { throw new CartNotFoundException( - $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_as_there_is_no_logged_in_user') + $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_as_there_is_no_logged_in_user'), ); } } - private function validateRemovableCart(int $cartNumber, $customer): void + private function validateRemovableCart(int $cartNumber, CustomerInterface $customer): void { if ($cartNumber === $customer->getActiveCart()) { throw new UnableToDeleteCartException('bitbag_sylius_multicart_plugin.ui.cant_delete_active_cart'); diff --git a/src/Repository/OrderRepositoryInterface.php b/src/Repository/OrderRepositoryInterface.php index 55d4f42c..39ea3e3b 100644 --- a/src/Repository/OrderRepositoryInterface.php +++ b/src/Repository/OrderRepositoryInterface.php @@ -15,6 +15,7 @@ use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface as BaseOrderRepositoryInterface; +/** @phpstan-ignore-next-line - extends generic interface */ interface OrderRepositoryInterface extends BaseOrderRepositoryInterface { public function findCarts(ChannelInterface $channel, ?CustomerInterface $customer): array; @@ -22,7 +23,7 @@ public function findCarts(ChannelInterface $channel, ?CustomerInterface $custome public function findCartsGraterOrEqualNumber( ChannelInterface $channel, CustomerInterface $customer, - int $cartNumber + int $cartNumber, ): array; public function findBiggestCartNumber(ChannelInterface $channel, CustomerInterface $customer): int; diff --git a/src/Resources/config/config.yml b/src/Resources/config/config.yml index c514ad06..0544db7f 100644 --- a/src/Resources/config/config.yml +++ b/src/Resources/config/config.yml @@ -1,3 +1,2 @@ imports: - { resource: "@BitBagSyliusMultiCartPlugin/Resources/config/services.yml" } - - { resource: "@BitBagSyliusMultiCartPlugin/Resources/config/resources.yml" } \ No newline at end of file diff --git a/src/Resources/config/doctrine/OrderItem.orm.xml b/src/Resources/config/doctrine/OrderItem.orm.xml deleted file mode 100644 index c6695ef1..00000000 --- a/src/Resources/config/doctrine/OrderItem.orm.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - diff --git a/src/Resources/config/resources.yml b/src/Resources/config/resources.yml deleted file mode 100644 index 93c0c560..00000000 --- a/src/Resources/config/resources.yml +++ /dev/null @@ -1,12 +0,0 @@ -sylius_order: - resources: - order: - classes: - model: BitBag\SyliusMultiCartPlugin\Entity\Order - repository: BitBag\SyliusMultiCartPlugin\Repository\OrderRepository - -sylius_customer: - resources: - customer: - classes: - model: BitBag\SyliusMultiCartPlugin\Entity\Customer \ No newline at end of file diff --git a/src/Resources/config/services/factory.yml b/src/Resources/config/services/factory.yml index 6c25c219..f02d2a12 100644 --- a/src/Resources/config/services/factory.yml +++ b/src/Resources/config/services/factory.yml @@ -1,7 +1,7 @@ services: BitBag\SyliusMultiCartPlugin\Factory\AjaxPartialCartFactoryInterface: alias: 'bitbag_sylius_multi_cart_plugin.helper.ajax_partial_cart' - + bitbag_sylius_multi_cart_plugin.factory.ajax_partial_cart: class: BitBag\SyliusMultiCartPlugin\Factory\AjaxPartialCartFactory arguments: @@ -9,13 +9,14 @@ services: - '@bitbag_sylius_multi_cart_plugin.factory.order_item_factory' tags: - { name: 'controller.service_arguments' } - + BitBag\SyliusMultiCartPlugin\Factory\OrderItemFactoryInterface: alias: 'bitbag_sylius_multi_cart_plugin.helper.ajax_partial_cart_item' - + bitbag_sylius_multi_cart_plugin.factory.order_item_factory: class: BitBag\SyliusMultiCartPlugin\Factory\OrderItemFactory arguments: - '@bitbag_sylius_multi_cart_plugin.formatter.money_formatter' tags: - { name: 'controller.service_arguments' } + diff --git a/src/Switcher/CartSwitcher.php b/src/Switcher/CartSwitcher.php index f35eca3a..ec33397a 100644 --- a/src/Switcher/CartSwitcher.php +++ b/src/Switcher/CartSwitcher.php @@ -27,7 +27,7 @@ class CartSwitcher implements CartSwitcherInterface public function __construct( CustomerContextInterface $customerContext, EntityManagerInterface $entityManager, - TranslatorInterface $translator + TranslatorInterface $translator, ) { $this->customerContext = $customerContext; $this->entityManager = $entityManager; @@ -40,7 +40,7 @@ public function switchCart(int $cartNumber): void $customer = $this->customerContext->getCustomer(); if (null === $customer) { throw new CartNotFoundException( - $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_as_there_is_no_logged_in_user') + $this->translator->trans('bitbag_sylius_multicart_plugin.ui.sylius_was_not_able_to_find_the_cart_as_there_is_no_logged_in_user'), ); } diff --git a/src/Entity/OrderItem.php b/src/View/OrderItemView.php similarity index 72% rename from src/Entity/OrderItem.php rename to src/View/OrderItemView.php index b4d5674e..3cd41584 100644 --- a/src/Entity/OrderItem.php +++ b/src/View/OrderItemView.php @@ -8,11 +8,13 @@ declare(strict_types=1); -namespace BitBag\SyliusMultiCartPlugin\Entity; +namespace BitBag\SyliusMultiCartPlugin\View; +use BitBag\SyliusMultiCartPlugin\Entity\OrderItemInterface; +use BitBag\SyliusMultiCartPlugin\Model\OrderItemTrait; use Sylius\Component\Order\Model\OrderItem as BaseOrderItem; -class OrderItem extends BaseOrderItem implements OrderItemInterface +class OrderItemView extends BaseOrderItem implements OrderItemInterface { use OrderItemTrait; @@ -20,12 +22,12 @@ public function __construct( int $id, string $name, int $quantity, - string $formattedUnitPrice + string $formattedUnitPrice, ) { parent::__construct(); $this->id = $id; - $this->quantity = $quantity; $this->name = $name; + $this->quantity = $quantity; $this->formattedUnitPrice = $formattedUnitPrice; } } diff --git a/.env.test b/tests/Application/.env.test similarity index 100% rename from .env.test rename to tests/Application/.env.test diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 281e9a09..6ffa1ec7 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -62,4 +62,8 @@ Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['all' => true], Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['all' => true], + League\FlysystemBundle\FlysystemBundle::class => ['all' => true], + Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], + BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/packages/_sylius.yaml b/tests/Application/config/packages/_sylius.yaml index 0ca00981..5b1a4e35 100644 --- a/tests/Application/config/packages/_sylius.yaml +++ b/tests/Application/config/packages/_sylius.yaml @@ -15,3 +15,16 @@ parameters: sylius_shop: product_grid: include_all_descendants: true + +sylius_order: + resources: + order: + classes: + model: Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Order + repository: Tests\BitBag\SyliusMultiCartPlugin\Application\src\Repository\OrderRepository + +sylius_customer: + resources: + customer: + classes: + model: Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Customer diff --git a/tests/Application/config/packages/doctrine.yaml b/tests/Application/config/packages/doctrine.yaml index f51ba5a2..4f9f3ef7 100644 --- a/tests/Application/config/packages/doctrine.yaml +++ b/tests/Application/config/packages/doctrine.yaml @@ -12,3 +12,14 @@ doctrine: 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: xml + dir: '%kernel.project_dir%/src/Resources/config/doctrine' + prefix: 'Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity' + diff --git a/tests/Application/config/sylius/1.12/packages/test/mailer.yaml b/tests/Application/config/packages/test/mailer.yaml similarity index 100% rename from tests/Application/config/sylius/1.12/packages/test/mailer.yaml rename to tests/Application/config/packages/test/mailer.yaml diff --git a/tests/Application/config/sylius/1.11/bundles.php b/tests/Application/config/sylius/1.11/bundles.php deleted file mode 100644 index ff4fe7eb..00000000 --- a/tests/Application/config/sylius/1.11/bundles.php +++ /dev/null @@ -1,16 +0,0 @@ - ['all' => true], - Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true], - SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], - Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], -]; diff --git a/tests/Application/config/sylius/1.11/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.11/packages/dev/jms_serializer.yaml deleted file mode 100644 index 2f32a9b1..00000000 --- a/tests/Application/config/sylius/1.11/packages/dev/jms_serializer.yaml +++ /dev/null @@ -1,12 +0,0 @@ -jms_serializer: - visitors: - json_serialization: - options: - - JSON_PRETTY_PRINT - - JSON_UNESCAPED_SLASHES - - JSON_PRESERVE_ZERO_FRACTION - json_deserialization: - options: - - JSON_PRETTY_PRINT - - JSON_UNESCAPED_SLASHES - - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.11/packages/dev/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/dev/swiftmailer.yaml deleted file mode 100644 index 30eca8af..00000000 --- a/tests/Application/config/sylius/1.11/packages/dev/swiftmailer.yaml +++ /dev/null @@ -1,2 +0,0 @@ -swiftmailer: - disable_delivery: true diff --git a/tests/Application/config/sylius/1.11/packages/jms_serializer.yaml b/tests/Application/config/sylius/1.11/packages/jms_serializer.yaml deleted file mode 100644 index ed7bc613..00000000 --- a/tests/Application/config/sylius/1.11/packages/jms_serializer.yaml +++ /dev/null @@ -1,4 +0,0 @@ -jms_serializer: - visitors: - xml_serialization: - format_output: '%kernel.debug%' diff --git a/tests/Application/config/sylius/1.11/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.11/packages/prod/jms_serializer.yaml deleted file mode 100644 index c2881820..00000000 --- a/tests/Application/config/sylius/1.11/packages/prod/jms_serializer.yaml +++ /dev/null @@ -1,10 +0,0 @@ -jms_serializer: - visitors: - json_serialization: - options: - - JSON_UNESCAPED_SLASHES - - JSON_PRESERVE_ZERO_FRACTION - json_deserialization: - options: - - JSON_UNESCAPED_SLASHES - - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.11/packages/security.yaml b/tests/Application/config/sylius/1.11/packages/security.yaml deleted file mode 100644 index ddd4c2d1..00000000 --- a/tests/Application/config/sylius/1.11/packages/security.yaml +++ /dev/null @@ -1,148 +0,0 @@ -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/authentication-token" - provider: sylius_shop_user_provider - stateless: true - anonymous: true - json_login: - check_path: "%sylius.security.new_api_route%/shop/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.11/packages/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/swiftmailer.yaml deleted file mode 100644 index 73bba275..00000000 --- a/tests/Application/config/sylius/1.11/packages/swiftmailer.yaml +++ /dev/null @@ -1,2 +0,0 @@ -swiftmailer: - url: '%env(MAILER_URL)%' diff --git a/tests/Application/config/sylius/1.11/packages/test/security.yaml b/tests/Application/config/sylius/1.11/packages/test/security.yaml deleted file mode 100644 index e6c3df68..00000000 --- a/tests/Application/config/sylius/1.11/packages/test/security.yaml +++ /dev/null @@ -1,3 +0,0 @@ -security: - encoders: - sha512: sha512 diff --git a/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml deleted file mode 100644 index aaac242b..00000000 --- a/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml +++ /dev/null @@ -1,6 +0,0 @@ -swiftmailer: - disable_delivery: true - logging: true - spool: - type: file - path: "%kernel.cache_dir%/spool" diff --git a/tests/Application/config/sylius/1.11/packages/test_cached/security.yaml b/tests/Application/config/sylius/1.11/packages/test_cached/security.yaml deleted file mode 100644 index e6c3df68..00000000 --- a/tests/Application/config/sylius/1.11/packages/test_cached/security.yaml +++ /dev/null @@ -1,3 +0,0 @@ -security: - encoders: - sha512: sha512 diff --git a/tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml deleted file mode 100644 index aaac242b..00000000 --- a/tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml +++ /dev/null @@ -1,6 +0,0 @@ -swiftmailer: - disable_delivery: true - logging: true - spool: - type: file - path: "%kernel.cache_dir%/spool" diff --git a/tests/Application/config/sylius/1.12/bundles.php b/tests/Application/config/sylius/1.12/bundles.php deleted file mode 100644 index c1a8b604..00000000 --- a/tests/Application/config/sylius/1.12/bundles.php +++ /dev/null @@ -1,16 +0,0 @@ - ['all' => true], - Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], - BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], - SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], -]; diff --git a/tests/Application/config/sylius/1.12/packages/mailer.yaml b/tests/Application/config/sylius/1.12/packages/mailer.yaml deleted file mode 100644 index 0a0697c8..00000000 --- a/tests/Application/config/sylius/1.12/packages/mailer.yaml +++ /dev/null @@ -1,3 +0,0 @@ -framework: - mailer: - dsn: '%env(MAILER_DSN)%' diff --git a/tests/Application/config/sylius/1.12/packages/security.yaml b/tests/Application/config/sylius/1.12/packages/security.yaml index 842b093c..71d89cd9 100644 --- a/tests/Application/config/sylius/1.12/packages/security.yaml +++ b/tests/Application/config/sylius/1.12/packages/security.yaml @@ -94,11 +94,7 @@ security: invalidate_session: false dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - - image_resolver: - pattern: ^/media/cache/resolve + pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false access_control: @@ -107,6 +103,8 @@ security: - { path: "%sylius.security.shop_regex%/_partial", role: PUBLIC_ACCESS, ips: [127.0.0.1, ::1] } - { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS } + - { path: "%sylius.security.admin_regex%/forgotten-password", role: PUBLIC_ACCESS } + - { path: "%sylius.security.admin_regex%/login", role: PUBLIC_ACCESS } - { path: "%sylius.security.shop_regex%/login", role: PUBLIC_ACCESS } diff --git a/tests/Application/config/sylius/1.13/bundles.php b/tests/Application/config/sylius/1.13/bundles.php new file mode 100644 index 00000000..5d54121b --- /dev/null +++ b/tests/Application/config/sylius/1.13/bundles.php @@ -0,0 +1,7 @@ + ['all' => true], +]; diff --git a/tests/Application/config/sylius/1.13/packages/security.yaml b/tests/Application/config/sylius/1.13/packages/security.yaml new file mode 100644 index 00000000..6745ae80 --- /dev/null +++ b/tests/Application/config/sylius/1.13/packages/security.yaml @@ -0,0 +1,124 @@ +security: + enable_authenticator_manager: 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 + + password_hashers: + 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 + enable_csrf: true + 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 + + new_api_admin_user: + pattern: "%sylius.security.new_api_admin_regex%/.*" + provider: sylius_api_admin_user_provider + stateless: true + entry_point: jwt + json_login: + check_path: "%sylius.security.new_api_admin_route%/administrators/token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + jwt: true + + new_api_shop_user: + pattern: "%sylius.security.new_api_shop_regex%/.*" + provider: sylius_api_shop_user_provider + stateless: true + entry_point: jwt + json_login: + check_path: "%sylius.security.new_api_shop_route%/customers/token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + jwt: true + + 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 + enable_csrf: true + 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_homepage + invalidate_session: false + + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + + image_resolver: + pattern: ^/media/cache/resolve + security: false + + access_control: + - { path: "%sylius.security.admin_regex%/_partial", role: PUBLIC_ACCESS, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.admin_regex%/_partial", role: ROLE_NO_ACCESS } + - { path: "%sylius.security.shop_regex%/_partial", role: PUBLIC_ACCESS, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS } + + - { path: "%sylius.security.admin_regex%/login", role: PUBLIC_ACCESS } + - { path: "%sylius.security.shop_regex%/login", role: PUBLIC_ACCESS } + + - { path: "%sylius.security.shop_regex%/register", role: PUBLIC_ACCESS } + - { path: "%sylius.security.shop_regex%/verify", role: PUBLIC_ACCESS } + + - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } + - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_route%/administrators/reset-password", role: PUBLIC_ACCESS } + - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.new_api_admin_route%/administrators/token", role: PUBLIC_ACCESS } + - { path: "%sylius.security.new_api_user_account_regex%/.*", role: ROLE_USER } + - { path: "%sylius.security.new_api_shop_route%/customers/token", role: PUBLIC_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: PUBLIC_ACCESS } \ No newline at end of file diff --git a/tests/Application/config/symfony/4.4/packages/framework.yaml b/tests/Application/config/symfony/4.4/packages/framework.yaml deleted file mode 100644 index 62f82d35..00000000 --- a/tests/Application/config/symfony/4.4/packages/framework.yaml +++ /dev/null @@ -1,2 +0,0 @@ -framework: - templating: { engines: ["twig"] } diff --git a/tests/Application/package.json b/tests/Application/package.json index 28f8e12f..36e6c1f0 100644 --- a/tests/Application/package.json +++ b/tests/Application/package.json @@ -1,15 +1,15 @@ { "dependencies": { - "babel-polyfill": "^6.26.0", + "@babel/polyfill": "^7.0.0", "chart.js": "^3.7.1", - "jquery": "^3.4.0", + "jquery": "^3.5.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": "^1.7.0", + "@symfony/webpack-encore": "^1.6.1", "babel-core": "^6.26.3", "babel-plugin-external-helpers": "^6.22.0", "babel-plugin-module-resolver": "^3.1.1", @@ -21,22 +21,21 @@ "eslint-config-airbnb-base": "^12.1.0", "eslint-import-resolver-babel-module": "^4.0.0", "eslint-plugin-import": "^2.11.0", - "fast-async": "^6.3.7", "merge-stream": "^1.0.0", - "node-sass": "^4.14", - "sass-loader": "^7.0.1", - "upath": "^1.1.0", - "yargs": "^6.4.0" + "sass": "^1.39.2", + "sass-loader": "^12.1.0" }, "scripts": { "dev": "yarn encore dev", "watch": "yarn encore dev --watch", - "prod": "yarn encore prod" + "prod": "yarn encore prod", + "lint": "yarn lint:js", + "lint:js": "eslint gulpfile.babel.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Sylius/Sylius.git" }, - "repository": "git+https://github.com/Sylius/Sylius.git", "author": "Paweł Jędrzejewski", - "license": "MIT", - "name": "Application", - "version": "1.0.0", - "main": "index.js" + "license": "MIT" } diff --git a/tests/Application/src/Entity/Customer.php b/tests/Application/src/Entity/Customer.php new file mode 100644 index 00000000..976714af --- /dev/null +++ b/tests/Application/src/Entity/Customer.php @@ -0,0 +1,14 @@ +addOrderBy('o.cartNumber', 'DESC') ->getQuery() ->getResult() - ; + ; } public function findCartsGraterOrEqualNumber( ChannelInterface $channel, CustomerInterface $customer, - int $cartNumber + int $cartNumber, ): array { return $this->createQueryBuilder('o') ->andWhere('o.state = :state') @@ -49,12 +51,12 @@ public function findCartsGraterOrEqualNumber( ->addOrderBy('o.cartNumber', 'ASC') ->getQuery() ->getResult() - ; + ; } public function findBiggestCartNumber( ChannelInterface $channel, - CustomerInterface $customer + CustomerInterface $customer, ): int { return (int) $this->createQueryBuilder('o') ->select('MAX(o.cartNumber)') @@ -67,7 +69,7 @@ public function findBiggestCartNumber( ->addOrderBy('o.createdAt', 'DESC') ->getQuery() ->getSingleScalarResult() - ; + ; } public function countCarts(ChannelInterface $channel, ?CustomerInterface $customer): int @@ -83,12 +85,12 @@ public function countCarts(ChannelInterface $channel, ?CustomerInterface $custom ->addOrderBy('o.createdAt', 'DESC') ->getQuery() ->getSingleScalarResult() - ; + ; } public function findLatestNotEmptyActiveCart( ChannelInterface $channel, - CustomerInterface $customer + CustomerInterface $customer, ): ?OrderInterface { return $this->createQueryBuilder('o') ->andWhere('o.state = :state') @@ -103,6 +105,6 @@ public function findLatestNotEmptyActiveCart( ->setMaxResults(1) ->getQuery() ->getOneOrNullResult() - ; + ; } } diff --git a/src/Resources/config/doctrine/Customer.orm.xml b/tests/Application/src/Resources/config/doctrine/Customer.orm.xml similarity index 74% rename from src/Resources/config/doctrine/Customer.orm.xml rename to tests/Application/src/Resources/config/doctrine/Customer.orm.xml index 513c8581..486338f1 100644 --- a/src/Resources/config/doctrine/Customer.orm.xml +++ b/tests/Application/src/Resources/config/doctrine/Customer.orm.xml @@ -1,14 +1,9 @@ - - - - - - + + - - \ No newline at end of file + diff --git a/src/Resources/config/doctrine/Order.orm.xml b/tests/Application/src/Resources/config/doctrine/Order.orm.xml similarity index 74% rename from src/Resources/config/doctrine/Order.orm.xml rename to tests/Application/src/Resources/config/doctrine/Order.orm.xml index 9fba58e1..a38f0b17 100644 --- a/src/Resources/config/doctrine/Order.orm.xml +++ b/tests/Application/src/Resources/config/doctrine/Order.orm.xml @@ -1,14 +1,9 @@ - - - - - - + + - - \ No newline at end of file + diff --git a/tests/Behat/Context/Api/MultiCartContext.php b/tests/Behat/Context/Api/MultiCartContext.php index 8076e270..8904e112 100644 --- a/tests/Behat/Context/Api/MultiCartContext.php +++ b/tests/Behat/Context/Api/MultiCartContext.php @@ -16,15 +16,9 @@ use BitBag\SyliusMultiCartPlugin\Controller\DeleteCartAction; use BitBag\SyliusMultiCartPlugin\Controller\NewCartAction; use BitBag\SyliusMultiCartPlugin\Entity\CustomerInterface; -use BitBag\SyliusMultiCartPlugin\Entity\OrderInterface; use BitBag\SyliusMultiCartPlugin\Repository\OrderRepositoryInterface; -use Doctrine\Common\Collections\ArrayCollection; -use FriendsOfBehat\PageObjectExtension\Page\Page; use Sylius\Behat\Service\SharedStorageInterface; -use Sylius\Bundle\CoreBundle\Doctrine\ORM\OrderRepository; use Sylius\Component\Channel\Context\ChannelContextInterface; -use Sylius\Component\Core\Model\OrderItemInterface; -use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\Component\Customer\Context\CustomerContextInterface; use Sylius\Component\Order\Context\CartContextInterface; @@ -66,7 +60,7 @@ public function __construct( NewCartAction $newCartAction, DeleteCartAction $deleteCartAction, ChangeActiveCartAction $changeActiveCartAction, - CartContextInterface $cartContext + CartContextInterface $cartContext, ) { $this->router = $router; $this->orderRepository = $orderRepository; @@ -127,7 +121,7 @@ public function userChangesActiveCartShouldBe(int $cartNumber): void if ($cartNumber !== $customer->getActiveCart()) { throw new \Exception( - sprintf('Current active cart number is not %s', $cartNumber) + sprintf('Current active cart number is not %s', $cartNumber), ); } } @@ -146,7 +140,7 @@ public function userShouldHaveAppropriateNumberOfCarts(int $number): void if ($number !== $countCarts) { throw new \Exception( - sprintf('Number of carts is not equal %s', $number) + sprintf('Number of carts is not equal %s', $number), ); } } @@ -171,7 +165,6 @@ public function countAllOrderItems(int $number): void $allCarts = $this->orderRepository->findCarts($channel, $customer); - $allCartsItemsNumber = []; foreach ($allCarts as $specificCart) { @@ -179,7 +172,6 @@ public function countAllOrderItems(int $number): void $cartItems = $specificCart->countItems(); $allCartsItemsNumber[] = $cartItems; - } Assert::eq(array_sum($allCartsItemsNumber), $number); diff --git a/tests/Behat/Service/TokenAwareSecurityStorage.php b/tests/Behat/Service/TokenAwareSecurityStorage.php index 265888f4..36cfa7fc 100644 --- a/tests/Behat/Service/TokenAwareSecurityStorage.php +++ b/tests/Behat/Service/TokenAwareSecurityStorage.php @@ -15,7 +15,6 @@ use Sylius\Component\User\Model\UserInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\SessionFactoryInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -41,7 +40,8 @@ public function __construct( CookieSetterInterface $cookieSetter, TokenStorageInterface $tokenStorage, string $firewallContextName, - ?SessionFactoryInterface $sessionFactory = null) { + ?SessionFactoryInterface $sessionFactory = null, + ) { $this->requestStack = $requestStack; $this->cookieSetter = $cookieSetter; $this->tokenStorage = $tokenStorage; diff --git a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_counts_carts.yaml b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_counts_carts.yaml index d85670f2..46701e4c 100644 --- a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_counts_carts.yaml +++ b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_counts_carts.yaml @@ -18,7 +18,7 @@ Sylius\Component\Locale\Model\Locale: locale_en_us: code: "en_US" -BitBag\SyliusMultiCartPlugin\Entity\Customer: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Customer: customer: firstName: "Bruce" lastName: "Wayne" @@ -26,7 +26,7 @@ BitBag\SyliusMultiCartPlugin\Entity\Customer: emailCanonical: "batman@wayne-enterprise.com" activeCart: "1" -BitBag\SyliusMultiCartPlugin\Entity\Order: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Order: order_1: customer: "@customer" currency_code: "EUR" diff --git a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_do_not_finds_carts.yaml b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_do_not_finds_carts.yaml index 53d0f1b3..71a6880b 100644 --- a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_do_not_finds_carts.yaml +++ b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_do_not_finds_carts.yaml @@ -30,7 +30,7 @@ Sylius\Component\Locale\Model\Locale: locale_de_de: code: "de_DE" -BitBag\SyliusMultiCartPlugin\Entity\Customer: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Customer: customer_1: firstName: "Bruce" lastName: "Wayne" @@ -44,7 +44,7 @@ BitBag\SyliusMultiCartPlugin\Entity\Customer: emailCanonical: "cat@woman-DC.com" activeCart: "1" -BitBag\SyliusMultiCartPlugin\Entity\Order: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Order: order_1: customer: "@customer_1" currency_code: "EUR" diff --git a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_do_not_finds_carts_greater_or_equal_number.yaml b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_do_not_finds_carts_greater_or_equal_number.yaml index 3400aef8..d59ffb2e 100644 --- a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_do_not_finds_carts_greater_or_equal_number.yaml +++ b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_do_not_finds_carts_greater_or_equal_number.yaml @@ -30,7 +30,7 @@ Sylius\Component\Locale\Model\Locale: locale_de_de: code: "de_DE" -BitBag\SyliusMultiCartPlugin\Entity\Customer: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Customer: customer_1: firstName: "Bruce" lastName: "Wayne" @@ -44,7 +44,7 @@ BitBag\SyliusMultiCartPlugin\Entity\Customer: emailCanonical: "cat@woman-DC.com" activeCart: "1" -BitBag\SyliusMultiCartPlugin\Entity\Order: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Order: order_1: customer: "@customer_1" currency_code: "EUR" diff --git a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_find_latest_not_empty_active_cart.yaml b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_find_latest_not_empty_active_cart.yaml index 3400aef8..d59ffb2e 100644 --- a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_find_latest_not_empty_active_cart.yaml +++ b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_find_latest_not_empty_active_cart.yaml @@ -30,7 +30,7 @@ Sylius\Component\Locale\Model\Locale: locale_de_de: code: "de_DE" -BitBag\SyliusMultiCartPlugin\Entity\Customer: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Customer: customer_1: firstName: "Bruce" lastName: "Wayne" @@ -44,7 +44,7 @@ BitBag\SyliusMultiCartPlugin\Entity\Customer: emailCanonical: "cat@woman-DC.com" activeCart: "1" -BitBag\SyliusMultiCartPlugin\Entity\Order: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Order: order_1: customer: "@customer_1" currency_code: "EUR" diff --git a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts.yaml b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts.yaml index ba19a372..8b85435b 100644 --- a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts.yaml +++ b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts.yaml @@ -30,7 +30,7 @@ Sylius\Component\Locale\Model\Locale: locale_de_de: code: "de_DE" -BitBag\SyliusMultiCartPlugin\Entity\Customer: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Customer: customer_1: firstName: "Bruce" lastName: "Wayne" @@ -44,7 +44,7 @@ BitBag\SyliusMultiCartPlugin\Entity\Customer: emailCanonical: "cat@woman-DC.com" activeCart: "1" -BitBag\SyliusMultiCartPlugin\Entity\Order: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Order: order_1: customer: "@customer_1" currency_code: "EUR" diff --git a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts_greater_or_equal_number_for_channel_de.yaml b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts_greater_or_equal_number_for_channel_de.yaml index 88880ce4..e4b0ebc2 100644 --- a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts_greater_or_equal_number_for_channel_de.yaml +++ b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts_greater_or_equal_number_for_channel_de.yaml @@ -30,7 +30,7 @@ Sylius\Component\Locale\Model\Locale: locale_de_de: code: "de_DE" -BitBag\SyliusMultiCartPlugin\Entity\Customer: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Customer: customer_1: firstName: "Bruce" lastName: "Wayne" @@ -44,7 +44,7 @@ BitBag\SyliusMultiCartPlugin\Entity\Customer: emailCanonical: "cat@woman-DC.com" activeCart: "1" -BitBag\SyliusMultiCartPlugin\Entity\Order: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Order: order_1: customer: "@customer_1" currency_code: "EUR" diff --git a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts_greater_or_equal_number_for_channel_us.yaml b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts_greater_or_equal_number_for_channel_us.yaml index 88880ce4..e4b0ebc2 100644 --- a/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts_greater_or_equal_number_for_channel_us.yaml +++ b/tests/PHPUnit/Integration/DataFixtures/ORM/OrderRepositoryTest/test_it_finds_carts_greater_or_equal_number_for_channel_us.yaml @@ -30,7 +30,7 @@ Sylius\Component\Locale\Model\Locale: locale_de_de: code: "de_DE" -BitBag\SyliusMultiCartPlugin\Entity\Customer: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Customer: customer_1: firstName: "Bruce" lastName: "Wayne" @@ -44,7 +44,7 @@ BitBag\SyliusMultiCartPlugin\Entity\Customer: emailCanonical: "cat@woman-DC.com" activeCart: "1" -BitBag\SyliusMultiCartPlugin\Entity\Order: +Tests\BitBag\SyliusMultiCartPlugin\Application\src\Entity\Order: order_1: customer: "@customer_1" currency_code: "EUR"