diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 5f0cbb18..8cf63de2 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -1,188 +1,217 @@
name: Build
on:
- push:
- branches-ignore:
- - 'dependabot/**'
- pull_request: ~
- release:
- types: [ created ]
- schedule:
- - cron: "0 1 * * 6" # Run at 1am every Saturday
- workflow_dispatch: ~
+ push:
+ branches-ignore:
+ - 'dependabot/**'
+ pull_request: ~
+ release:
+ types: [created]
+ schedule:
+ -
+ cron: "0 1 * * 6" # Run at 1am every Saturday
+ workflow_dispatch: ~
jobs:
- tests:
- runs-on: ubuntu-20.04
-
- name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}"
-
- strategy:
- fail-fast: false
- matrix:
- php: ["8.0", "8.1"]
- symfony: ["^5.4", "^6.0"]
- sylius: ["~1.11.0", "~1.12.0", "1.13.x-dev"]
- node: ["^14.17.x"]
- mysql: ["8.0"]
-
- exclude:
- - sylius: ~1.11.0
- symfony: "^6.0"
- - sylius: 1.13.x-dev.11.0
- symfony: "^5.4"
- php: "8.0"
- - sylius: 1.13.x-dev.11.0
- symfony: "^5.4"
- php: "8.1"
- - sylius: 1.13.x-dev.11.0
- symfony: "^6.0"
- php: "8.0"
- 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 }}"
- extensions: intl
- 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: Configure sysctl limits
- run: |
- sudo swapoff -a
- sudo sysctl -w vm.swappiness=1
- sudo sysctl -w fs.file-max=262144
- sudo sysctl -w vm.max_map_count=262144
-
- - 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 --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: Restrict Symfony version
- if: matrix.symfony != ''
- run: |
- composer global config --no-plugins allow-plugins.symfony/flex true
- composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10"
- composer config extra.symfony.require "${{ matrix.symfony }}"
-
- - name: Restrict Sylius version
- if: matrix.sylius != ''
- run: composer require "sylius/sylius:${{ matrix.sylius }}" --no-update --no-scripts --no-interaction
-
- - name: 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: Copy package.json.dist to package.json
- if: matrix.sylius != ''
- run: (cd tests/Application && cp package.json.\${{ matrix.sylius }}.dist package.json)
-
- - 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 prod)
-
- - 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 PHPSpec
- run: vendor/bin/phpspec run --ansi -f progress --no-interaction
-
- - 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
- if: failure()
- with:
- name: Behat logs
- path: etc/build/
- if-no-files-found: ignore
-
- - name: Upload test log logs
- uses: actions/upload-artifact@v2
- 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') }}
- env:
- SLACK_CHANNEL: ${{ secrets.FAILED_BUILD_SLACK_CHANNEL }}
- SLACK_COLOR: ${{ job.status }}
- SLACK_ICON: https://github.com/rtCamp.png?size=48
- SLACK_MESSAGE: ':x:'
- SLACK_TITLE: Failed build on ${{ github.event.repository.name }} repository
- SLACK_USERNAME: ${{ secrets.FAILED_BUILD_SLACK_USERNAME }}
- SLACK_WEBHOOK: ${{ secrets.FAILED_BUILD_SLACK_WEBHOOK }}
\ No newline at end of file
+ tests:
+ runs-on: ubuntu-20.04
+
+ name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }},
+ MySQL ${{ matrix.mysql }}, State Machine Adapter ${{ matrix.state_machine_adapter }}"
+
+ strategy:
+ fail-fast: false
+ matrix:
+ php: ["8.1"]
+ symfony: ["^5.4", "^6.0"]
+ sylius: ["~1.12.0", "~1.13.0"]
+ node: ["^14.17.x"]
+ mysql: ["8.0"]
+ state_machine_adapter: ["winzou_state_machine", "symfony_workflow"]
+
+ exclude:
+ -
+ sylius: ~1.12.0
+ state_machine_adapter: "symfony_workflow"
+ 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 }}"
+ extensions: intl
+ 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: Configure sysctl limits
+ run: |
+ sudo swapoff -a
+ sudo sysctl -w vm.swappiness=1
+ sudo sysctl -w fs.file-max=262144
+ sudo sysctl -w vm.max_map_count=262144
+
+ -
+ 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 --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: Restrict Symfony version
+ if: matrix.symfony != ''
+ run: |
+ composer global config --no-plugins allow-plugins.symfony/flex true
+ composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10"
+ composer config extra.symfony.require "${{ matrix.symfony }}"
+
+ -
+ name: Restrict Sylius version
+ if: matrix.sylius != ''
+ run: composer require "sylius/sylius:${{ matrix.sylius }}" --no-update --no-scripts --no-interaction
+
+ -
+ name: 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: Copy package.json.dist to package.json
+ if: matrix.sylius != ''
+ run: (cd tests/Application && cp package.json.\${{ matrix.sylius }}.dist package.json)
+
+ -
+ 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 prod)
+
+ -
+ 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 PHPSpec
+ run: vendor/bin/phpspec run --ansi -f progress --no-interaction
+
+ -
+ name: Run PHPUnit
+ run: vendor/bin/phpunit --colors=always
+
+ -
+ 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
+ if: failure()
+ with:
+ name: Behat logs
+ path: etc/build/
+ if-no-files-found: ignore
+
+ -
+ name: Upload test log logs
+ uses: actions/upload-artifact@v2
+ 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') }}
+ env:
+ SLACK_CHANNEL: ${{ secrets.FAILED_BUILD_SLACK_CHANNEL }}
+ SLACK_COLOR: ${{ job.status }}
+ SLACK_ICON: https://github.com/rtCamp.png?size=48
+ SLACK_MESSAGE: ':x:'
+ SLACK_TITLE: Failed build on ${{ github.event.repository.name }} repository
+ SLACK_USERNAME: ${{ secrets.FAILED_BUILD_SLACK_USERNAME }}
+ SLACK_WEBHOOK: ${{ secrets.FAILED_BUILD_SLACK_WEBHOOK }}
diff --git a/.gitignore b/.gitignore
index eadc53da..25d463f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@
!/etc/build/.gitignore
/behat.yml
+/phpunit.xml
diff --git a/composer.json b/composer.json
index bb6dd95a..70c4d7fe 100644
--- a/composer.json
+++ b/composer.json
@@ -4,8 +4,8 @@
"description": "Wishlist plugin for Sylius.",
"license": "MIT",
"require": {
- "php": "^8.0",
- "sylius/sylius": "~1.11.0 || ~1.12.0 || ~1.13.x-dev",
+ "php": "^8.1",
+ "sylius/sylius": "~1.12.0 || ~1.13.0",
"symfony/webpack-encore-bundle": "^1.15",
"dompdf/dompdf": "^2.0"
},
@@ -35,7 +35,9 @@
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"league/flysystem-bundle": "2.4.0",
- "sylius/mailer-bundle": "^1.8 || ^2.0@beta"
+ "sylius/mailer-bundle": "^1.8 || ^2.0@beta",
+ "lchrusciel/api-test-case": "^4.1 || ^5.0",
+ "nelmio/alice": "^3.10"
},
"conflict": {
"symfony/symfony": "4.1.8",
@@ -52,7 +54,12 @@
}
},
"autoload-dev": {
- "classmap": ["tests/Application/Kernel.php"]
+ "classmap": ["tests/Application/Kernel.php"],
+ "psr-4": {
+ "BitBag\\SyliusWishlistPlugin\\": "src/",
+ "Tests\\BitBag\\SyliusWishlistPlugin\\": "tests/",
+ "Sylius\\Tests\\Api\\": ["vendor/sylius/sylius/tests/Api/"]
+ }
},
"config": {
"allow-plugins": {
@@ -61,6 +68,15 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"symfony/thanks": true,
"symfony/flex": true
+ },
+ "preferred-install": {
+ "sylius/sylius": "source"
+ }
+ },
+ "scripts": {
+ "auto-scripts": {
+ "cache:clear": "symfony-cmd",
+ "assets:install %PUBLIC_DIR%": "symfony-cmd"
}
}
}
diff --git a/features/adding_product_to_selected_wishlist.feature b/features/adding_product_to_selected_wishlist.feature
index 64de2221..8eb9761e 100644
--- a/features/adding_product_to_selected_wishlist.feature
+++ b/features/adding_product_to_selected_wishlist.feature
@@ -15,4 +15,4 @@ Feature: Adding a product to selected wishlist
And the store has a product "Jack Daniels Gentleman" priced at "$10.00"
And all store products appear under a main taxonomy
And I add "Jack Daniels Gentleman" to selected wishlist "Wishlist2"
- And I should have "Jack Daniels Gentleman" in selected wishlists "Wishlist2"
\ No newline at end of file
+ And I should have "Jack Daniels Gentleman" in selected wishlists "Wishlist2"
diff --git a/features/assigning_wishlist_to_user.feature b/features/assigning_wishlist_to_user.feature
index 9d9137fa..088f38b3 100644
--- a/features/assigning_wishlist_to_user.feature
+++ b/features/assigning_wishlist_to_user.feature
@@ -32,11 +32,15 @@ Feature: Assigning a wishlist to a user
@ui @javascript
Scenario: Assigning a wishlist to a user and logout
When I go to "/"
+ And I go to "/wishlists"
+ And I should have 0 wishlists
And I log in as "jdeer@sylius.pl"
And I go to "/wishlists"
+ And I should have 2 wishlists
And I press "wishlist-edit-button-Wishlist1"
And I fill in "edit_wishlist_name" with "Wishlist-assigned"
And I press "edit_wishlist_save"
+ And I should wait for one second
And I log out
And I go to "/wishlists"
Then I should have 0 wishlists
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100755
index 00000000..14218120
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ tests
+
+
+
diff --git a/spec/Checker/ProductProcessingCheckerSpec.php b/spec/Checker/ProductProcessingCheckerSpec.php
index 64937f9e..8c61b431 100644
--- a/spec/Checker/ProductProcessingCheckerSpec.php
+++ b/spec/Checker/ProductProcessingCheckerSpec.php
@@ -23,7 +23,6 @@
final class ProductProcessingCheckerSpec extends ObjectBehavior
{
public function let(
-
ProductQuantityCheckerInterface $productQuantityChecker
): void {
$this->beConstructedWith(
diff --git a/spec/Checker/WishlistNameCheckerSpec.php b/spec/Checker/WishlistNameCheckerSpec.php
new file mode 100644
index 00000000..deb2eae6
--- /dev/null
+++ b/spec/Checker/WishlistNameCheckerSpec.php
@@ -0,0 +1,38 @@
+shouldHaveType(WishlistNameChecker::class);
+ }
+
+ public function it_returns_true_if_names_are_equal(): void
+ {
+ $existingWishlistName = 'test1';
+ $wishlistToCreate = 'test1';
+
+ $this->check($existingWishlistName, $wishlistToCreate)->shouldReturn(true);
+ }
+
+ public function it_returns_false_if_names_are_not_equal(): void
+ {
+ $existingWishlistName = 'test1';
+ $wishlistToCreate = 'test2';
+
+ $this->check($existingWishlistName, $wishlistToCreate)->shouldReturn(false);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/AddProductToSelectedWishlistHandlerSpec.php b/spec/CommandHandler/Wishlist/AddProductToSelectedWishlistHandlerSpec.php
new file mode 100644
index 00000000..d7e3a214
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/AddProductToSelectedWishlistHandlerSpec.php
@@ -0,0 +1,59 @@
+beConstructedWith(
+ $wishlistProductFactory,
+ $wishlistRepository
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(AddProductToSelectedWishlistHandler::class);
+ }
+
+ public function it_adds_product_to_wishlist_if_product_is_found(
+ AddProductToSelectedWishlistInterface $addProductToSelectedWishlist,
+ ProductInterface $product,
+ WishlistInterface $wishlist,
+ WishlistProductFactoryInterface $wishlistProductFactory,
+ WishlistProductInterface $wishlistProduct,
+ WishlistRepositoryInterface $wishlistRepository
+ ): void
+ {
+ $addProductToSelectedWishlist->getProduct()->willReturn($product);
+ $addProductToSelectedWishlist->getWishlist()->willReturn($wishlist);
+
+ $wishlistProductFactory->createForWishlistAndProduct($wishlist, $product)->willReturn($wishlistProduct);
+
+ $wishlist->addWishlistProduct($wishlistProduct)->shouldBeCalled();
+ $wishlistRepository->add($wishlist)->shouldBeCalled();
+
+ $this->__invoke($addProductToSelectedWishlist);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/AddProductToWishlistHandlerSpec.php b/spec/CommandHandler/Wishlist/AddProductToWishlistHandlerSpec.php
new file mode 100644
index 00000000..a7c37b82
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/AddProductToWishlistHandlerSpec.php
@@ -0,0 +1,93 @@
+beConstructedWith(
+ $wishlistProductFactory,
+ $productRepository,
+ $wishlistManager
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(AddProductToWishlistHandler::class);
+ }
+
+ public function it_adds_product_to_wishlist(
+ ProductInterface $product,
+ WishlistInterface $wishlist,
+ ProductRepositoryInterface $productRepository,
+ WishlistProductFactoryInterface $wishlistProductFactory,
+ WishlistProductInterface $wishlistProduct,
+ ObjectManager $wishlistManager
+ ): void
+ {
+ $productRepository->find(1)->willReturn($product);
+
+ $wishlistProductFactory->createForWishlistAndProduct($wishlist, $product)->willReturn($wishlistProduct);
+ $wishlist->addWishlistProduct($wishlistProduct)->shouldBeCalled();
+
+ $wishlistManager->persist($wishlistProduct)->shouldBeCalled();
+ $wishlistManager->flush()->shouldBeCalled();
+
+ $addProductToWishlist = new AddProductToWishlist(1);
+ $addProductToWishlist->setWishlist($wishlist->getWrappedObject());
+
+ $this->__invoke($addProductToWishlist);
+ }
+
+ public function it_doesnt_add_product_to_wishlist_if_product_isnt_found(
+ ProductInterface $product,
+ WishlistInterface $wishlist,
+ ProductRepositoryInterface $productRepository,
+ WishlistProductFactoryInterface $wishlistProductFactory,
+ WishlistProductInterface $wishlistProduct,
+ ObjectManager $wishlistManager
+ ): void
+ {
+ $productRepository->find(1)->willReturn(null);
+
+ $wishlistProductFactory->createForWishlistAndProduct($wishlist, $product)->shouldNotBeCalled();
+ $wishlist->addWishlistProduct($wishlistProduct)->shouldNotBeCalled();
+
+ $wishlistManager->persist($wishlistProduct)->shouldNotBeCalled();
+ $wishlistManager->flush()->shouldNotBeCalled();
+
+ $addProductToWishlist = new AddProductToWishlist(1);
+ $addProductToWishlist->setWishlist($wishlist->getWrappedObject());
+
+ $this
+ ->shouldThrow(ProductNotFoundException::class)
+ ->during('__invoke', [$addProductToWishlist])
+ ;
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/AddProductVariantToWishlistHandlerSpec.php b/spec/CommandHandler/Wishlist/AddProductVariantToWishlistHandlerSpec.php
new file mode 100644
index 00000000..b2c3563b
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/AddProductVariantToWishlistHandlerSpec.php
@@ -0,0 +1,92 @@
+beConstructedWith(
+ $wishlistProductFactory,
+ $productVariantRepository,
+ $wishlistManager
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(AddProductVariantToWishlistHandler::class);
+ }
+
+ public function it_adds_product_variant_to_wishlist(
+ ProductVariantInterface $productVariant,
+ WishlistInterface $wishlist,
+ ProductVariantRepositoryInterface $productVariantRepository,
+ WishlistProductFactoryInterface $wishlistProductFactory,
+ WishlistProductInterface $wishlistProduct,
+ ObjectManager $wishlistManager
+ ): void
+ {
+ $productVariantRepository->find(1)->willReturn($productVariant);
+
+ $wishlistProductFactory->createForWishlistAndVariant($wishlist, $productVariant)->willReturn($wishlistProduct);
+ $wishlist->addWishlistProduct($wishlistProduct)->shouldBeCalled();
+
+ $wishlistManager->persist($wishlist)->shouldBeCalled();
+ $wishlistManager->flush()->shouldBeCalled();
+
+ $addProductVariantToWishlist = new AddProductVariantToWishlist(1);
+ $addProductVariantToWishlist->setWishlist($wishlist->getWrappedObject());
+
+ $this->__invoke($addProductVariantToWishlist);
+ }
+
+ public function it_doesnt_add_product_variant_to_wishlist_if_variant_isnt_found(
+ ProductVariantInterface $productVariant,
+ WishlistInterface $wishlist,
+ ProductVariantRepositoryInterface $productVariantRepository,
+ WishlistProductFactoryInterface $wishlistProductFactory,
+ WishlistProductInterface $wishlistProduct,
+ ObjectManager $wishlistManager
+ ): void
+ {
+ $productVariantRepository->find(1)->willReturn(null);
+
+ $wishlistProductFactory->createForWishlistAndVariant($wishlist, $productVariant)->shouldNotBeCalled();
+ $wishlist->addWishlistProduct($wishlistProduct)->shouldNotBeCalled();
+
+ $wishlistManager->persist($wishlistProduct)->shouldNotBeCalled();
+ $wishlistManager->flush()->shouldNotBeCalled();
+
+ $addProductVariantToWishlist = new AddProductVariantToWishlist(1);
+ $addProductVariantToWishlist->setWishlist($wishlist->getWrappedObject());
+
+ $this
+ ->shouldThrow(ProductVariantNotFoundException::class)
+ ->during('__invoke', [$addProductVariantToWishlist])
+ ;
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/AddProductsToCartHandlerSpec.php b/spec/CommandHandler/Wishlist/AddProductsToCartHandlerSpec.php
new file mode 100644
index 00000000..45b76800
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/AddProductsToCartHandlerSpec.php
@@ -0,0 +1,131 @@
+beConstructedWith(
+ $requestStack,
+ $translator,
+ $orderModifier,
+ $orderRepository,
+ $availabilityChecker
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(AddProductsToCartHandler::class);
+ }
+
+
+ public function it_adds_products_from_wishlist_to_cart(
+ AvailabilityCheckerInterface $availabilityChecker,
+ ProductVariantInterface $productVariant,
+ OrderItemInterface $orderItem,
+ WishlistItemInterface $wishlistProduct,
+ OrderInterface $order,
+ AddProductsToCartInterface $addProductsToCart,
+ AddToCartCommandInterface $addToCartCommand,
+ OrderModifierInterface $orderModifier,
+ OrderRepositoryInterface $orderRepository,
+ RequestStack $requestStack,
+ Session $session,
+ FlashBagInterface $flashBag,
+ TranslatorInterface $translator
+ ): void {
+ $collection = new ArrayCollection([$wishlistProduct->getWrappedObject()]);
+ $addProductsToCart->getWishlistProducts()->willReturn($collection);
+
+ $wishlistProduct->getCartItem()->willReturn($addToCartCommand);
+ $addToCartCommand->getCartItem()->willReturn($orderItem);
+ $orderItem->getVariant()->willReturn($productVariant);
+ $orderItem->getQuantity()->willReturn(1);
+ $addToCartCommand->getCart()->willReturn($order);
+
+ $orderModifier->addToOrder($order, $orderItem)->shouldBeCalled();
+ $orderRepository->add($order)->shouldBeCalled();
+
+ $availabilityChecker->isStockSufficient($productVariant, 1)->willReturn(true);
+
+ $requestStack->getSession()->willReturn($session);
+ $session->getFlashBag()->willReturn($flashBag);
+ $flashBag->has('success')->willReturn(false);
+
+ $translator->trans('bitbag_sylius_wishlist_plugin.ui.added_to_cart')->willReturn('Test translation');
+ $flashBag->add('success', 'Test translation')->shouldBeCalled();
+
+ $this->__invoke($addProductsToCart);
+ }
+
+ public function it_doesnt_add_products_from_wishlist_to_cart_if_stock_is_insufficient(
+ AvailabilityCheckerInterface $availabilityChecker,
+ ProductVariantInterface $productVariant,
+ OrderItemInterface $orderItem,
+ WishlistItemInterface $wishlistProduct,
+ OrderInterface $order,
+ AddProductsToCartInterface $addProductsToCart,
+ AddToCartCommandInterface $addToCartCommand,
+ OrderModifierInterface $orderModifier,
+ OrderRepositoryInterface $orderRepository,
+ RequestStack $requestStack,
+ Session $session,
+ FlashBagInterface $flashBag,
+ TranslatorInterface $translator
+ ): void {
+ $collection = new ArrayCollection([$wishlistProduct->getWrappedObject()]);
+ $addProductsToCart->getWishlistProducts()->willReturn($collection);
+
+ $wishlistProduct->getCartItem()->willReturn($addToCartCommand);
+ $addToCartCommand->getCartItem()->willReturn($orderItem);
+ $orderItem->getVariant()->willReturn($productVariant);
+ $orderItem->getQuantity()->willReturn(0);
+ $addToCartCommand->getCart()->willReturn($order);
+ $availabilityChecker->isStockSufficient($productVariant, 0)->willReturn(false);
+
+ $orderItem->getProductName()->willReturn('Tested Product');
+
+ $orderModifier->addToOrder($order, $orderItem)->shouldNotBeCalled();
+ $orderRepository->add($order)->shouldNotBeCalled();
+
+ $requestStack->getSession()->willReturn($session);
+ $session->getFlashBag()->willReturn($flashBag);
+ $translator->trans('Tested Product does not have sufficient stock.')->willReturn('Translation test');
+ $flashBag->add('error', 'Translation test')->shouldBeCalled();
+
+ $this->__invoke($addProductsToCart);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/AddSelectedProductsToCartHandlerSpec.php b/spec/CommandHandler/Wishlist/AddSelectedProductsToCartHandlerSpec.php
new file mode 100644
index 00000000..3583feb0
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/AddSelectedProductsToCartHandlerSpec.php
@@ -0,0 +1,110 @@
+beConstructedWith(
+ $itemQuantityModifier,
+ $orderModifier,
+ $orderRepository,
+ $productProcessingChecker
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(AddSelectedProductsToCartHandler::class);
+ }
+
+ public function it_adds_selected_products_to_cart(
+ WishlistItem $wishlistProduct,
+ OrderModifierInterface $orderModifier,
+ OrderRepositoryInterface $orderRepository,
+ OrderItemQuantityModifierInterface $itemQuantityModifier,
+ OrderInterface $order,
+ OrderItemInterface $orderItem,
+ AddToCartCommandInterface $addToCartCommand,
+ ProductProcessingCheckerInterface $productProcessingChecker
+ ): void {
+ $collection = new ArrayCollection([$wishlistProduct->getWrappedObject()]);
+ $productProcessingChecker->canBeProcessed($wishlistProduct)->willReturn(true);
+
+ $wishlistProduct->getCartItem()->willReturn($addToCartCommand);
+
+ $addToCartCommand->getCart()->willReturn($order);
+ $addToCartCommand->getCartItem()->willReturn($orderItem);
+
+ $orderItem->getQuantity()->willReturn(0);
+ $itemQuantityModifier->modify($orderItem, 1)->shouldBeCalled();
+
+ $orderModifier->addToOrder($order, $orderItem)->shouldBeCalled();
+ $orderRepository->add($order)->shouldBeCalled();
+
+ $addSelectedProductsToCart = new AddSelectedProductsToCart($collection);
+
+ $this->__invoke($addSelectedProductsToCart);
+ }
+
+ public function it_doesnt_add_selected_products_to_cart_if_product_cannot_be_processed(
+ WishlistItemInterface $wishlistProduct,
+ OrderModifierInterface $orderModifier,
+ OrderRepositoryInterface $orderRepository,
+ OrderItemQuantityModifierInterface $itemQuantityModifier,
+ OrderInterface $order,
+ OrderItemInterface $orderItem,
+ AddToCartCommandInterface $addToCartCommand,
+ ProductProcessingCheckerInterface $productProcessingChecker
+ ): void {
+ $collection = new ArrayCollection([$wishlistProduct->getWrappedObject()]);
+
+ $productProcessingChecker->canBeProcessed($wishlistProduct)->willReturn(false);
+
+ $wishlistProduct->getCartItem()->shouldNotBeCalled();
+
+ $addToCartCommand->getCart()->shouldNotBeCalled();
+ $addToCartCommand->getCartItem()->shouldNotBeCalled();
+
+ $orderItem->getQuantity()->willReturn(0);
+ $itemQuantityModifier->modify($orderItem, 1)->shouldNotBeCalled();
+
+ $orderModifier->addToOrder($order, $orderItem)->shouldNotBeCalled();
+ $orderRepository->add($order)->shouldNotBeCalled();
+
+ $addSelectedProductsToCart = new AddSelectedProductsToCart($collection);
+
+ $this
+ ->shouldThrow(ProductCantBeAddedToCartException::class)
+ ->during('__invoke', [$addSelectedProductsToCart])
+ ;
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/AddWishlistToUserHandlerSpec.php b/spec/CommandHandler/Wishlist/AddWishlistToUserHandlerSpec.php
new file mode 100644
index 00000000..cec7e67a
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/AddWishlistToUserHandlerSpec.php
@@ -0,0 +1,83 @@
+beConstructedWith(
+ $wishlistRepository,
+ $wishlistCookieTokenResolver
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(AddWishlistToUserHandler::class);
+ }
+
+ public function it_adds_wishlist_to_user(
+ WishlistInterface $wishlist,
+ ShopUserInterface $shopUser,
+ WishlistRepositoryInterface $wishlistRepository,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver
+ ): void {
+ $wishlistCookieTokenResolver->resolve()->willReturn('token');
+
+ $wishlist->getToken()->willReturn('token');
+ $wishlist->getName()->willReturn('Testing wishlist');
+ $wishlist->getId()->willReturn(1);
+
+ $wishlistRepository->findOneByShopUserAndName($shopUser, 'Testing wishlist')->willReturn($wishlist);
+ $wishlist->setName('Testing wishlist1');
+ $wishlist->setShopUser($shopUser)->shouldBeCalled();
+ $wishlistRepository->add($wishlist)->shouldBeCalled();
+
+ $addWishlistToUser = new AddWishlistToUser($wishlist->getWrappedObject(), $shopUser->getWrappedObject());
+
+ $this->__invoke($addWishlistToUser);
+ }
+
+ public function it_doesnt_add_wishlist_to_user_if_token_doesnt_match(
+ WishlistInterface $wishlist,
+ ShopUserInterface $shopUser,
+ WishlistRepositoryInterface $wishlistRepository,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver
+ ): void {
+ $wishlistCookieTokenResolver->resolve()->willReturn('token');
+
+ $wishlist->getToken()->willReturn('anotherToken');
+ $wishlist->getName()->shouldNotBeCalled();
+ $wishlist->getId()->shouldNotBeCalled();
+
+ $wishlistRepository->findOneByShopUserAndName($shopUser, 'name')->shouldNotBeCalled();
+ $wishlist->setShopUser($shopUser)->shouldNotBeCalled();
+ $wishlistRepository->add($wishlist)->shouldNotBeCalled();
+
+ $addWishlistToUser = new AddWishlistToUser($wishlist->getWrappedObject(), $shopUser->getWrappedObject());
+
+ $this
+ ->shouldThrow(WishlistHasAnotherShopUserException::class)
+ ->during('__invoke', [$addWishlistToUser]);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/CreateNewWishlistHandlerSpec.php b/spec/CommandHandler/Wishlist/CreateNewWishlistHandlerSpec.php
new file mode 100644
index 00000000..4680dba1
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/CreateNewWishlistHandlerSpec.php
@@ -0,0 +1,170 @@
+beConstructedWith(
+ $wishlistRepository,
+ $tokenStorage,
+ $wishlistFactory,
+ $wishlistCookieTokenResolver,
+ $channelRepository,
+ $wishlistNameChecker,
+ $tokenUserResolver
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(CreateNewWishlistHandler::class);
+ }
+
+ public function it_creates_new_wishlist_for_user(
+ WishlistRepositoryInterface $wishlistRepository,
+ TokenStorageInterface $tokenStorage,
+ WishlistFactoryInterface $wishlistFactory,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ WishlistNameCheckerInterface $wishlistNameChecker,
+ ChannelRepositoryInterface $channelRepository,
+ TokenInterface $token,
+ ShopUserInterface $shopUser,
+ WishlistInterface $wishlist,
+ WishlistInterface $existingWishlist,
+ ChannelInterface $channel,
+ TokenUserResolverInterface $tokenUserResolver
+ ): void {
+ $wishlists = [$existingWishlist];
+
+ $tokenStorage->getToken()->willReturn($token);
+ $tokenUserResolver->resolve($token)->willReturn($shopUser);
+
+ $wishlistCookieTokenResolver->resolve()->willReturn('token');
+ $wishlistFactory->createForUser($shopUser)->willReturn($wishlist);
+
+ $wishlist->getShopUser()->willReturn($shopUser);
+ $shopUser->getId()->willReturn(1);
+ $wishlistRepository->findAllByShopUser(1)->willReturn($wishlists);
+
+ $wishlist->setToken('token')->shouldBeCalled();
+ $channelRepository->findOneByCode('test_channel_code')->willReturn($channel);
+ $wishlist->setChannel($channel)->shouldBeCalled();
+
+ $existingWishlist->getName()->willReturn('existing');
+ $wishlistNameChecker->check('existing', 'New wishlist')->willReturn(false);
+ $wishlist->setName('New wishlist');
+
+ $wishlistRepository->add($wishlist)->shouldBeCalled();
+
+ $createNewWishlist = new CreateNewWishlist('New wishlist', 'test_channel_code');
+
+ $this->__invoke($createNewWishlist);
+ }
+
+ public function it_creates_new_wishlist_for_guest(
+ WishlistRepositoryInterface $wishlistRepository,
+ TokenStorageInterface $tokenStorage,
+ WishlistFactoryInterface $wishlistFactory,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ ChannelRepositoryInterface $channelRepository,
+ WishlistInterface $newWishlist,
+ ChannelInterface $channel,
+ TokenUserResolverInterface $tokenUserResolver
+ ): void {
+ $tokenStorage->getToken()->willReturn(null);
+ $tokenUserResolver->resolve(null)->willReturn(null);
+
+ $wishlistCookieTokenResolver->resolve()->willReturn('token');
+ $wishlistFactory->createNew()->willReturn($newWishlist);
+
+ $wishlistRepository->findAllByAnonymous('token')->willReturn([]);
+
+ $newWishlist->setToken('token')->shouldBeCalled();
+ $channelRepository->findOneByCode('test_channel_code')->willReturn($channel);
+ $newWishlist->setChannel($channel)->shouldBeCalled();
+
+ $wishlistRepository->add($newWishlist)->shouldBeCalled();
+
+ $createNewWishlist = new CreateNewWishlist('New wishlist', 'test_channel_code');
+
+ $this->__invoke($createNewWishlist);
+ }
+
+ public function it_doesnt_add_duplicated_wishlist_name_for_user(
+ WishlistRepositoryInterface $wishlistRepository,
+ TokenStorageInterface $tokenStorage,
+ WishlistFactoryInterface $wishlistFactory,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ WishlistNameCheckerInterface $wishlistNameChecker,
+ ChannelRepositoryInterface $channelRepository,
+ TokenInterface $token,
+ ShopUserInterface $shopUser,
+ WishlistInterface $wishlist,
+ WishlistInterface $existingWishlist,
+ ChannelInterface $channel,
+ TokenUserResolverInterface $tokenUserResolver
+ ): void {
+ $wishlists = [$existingWishlist];
+
+ $tokenStorage->getToken()->willReturn($token);
+ $tokenUserResolver->resolve($token)->willReturn($shopUser);
+
+ $wishlistCookieTokenResolver->resolve()->willReturn('token');
+ $wishlistFactory->createForUser($shopUser)->willReturn($wishlist);
+
+ $wishlist->getShopUser()->willReturn($shopUser);
+ $shopUser->getId()->willReturn(1);
+ $wishlistRepository->findAllByShopUser(1)->willReturn($wishlists);
+
+ $wishlist->setToken('token')->shouldBeCalled();
+ $channelRepository->findOneByCode('test_channel_code')->willReturn($channel);
+ $wishlist->setChannel($channel)->shouldBeCalled();
+
+ $existingWishlist->getName()->willReturn('existing');
+ $wishlistNameChecker->check('existing', 'existing')->willReturn(true);
+ $wishlist->setName('existing')->shouldNotBeCalled();
+
+ $wishlistRepository->add($wishlist)->shouldNotBeCalled();
+
+ $createNewWishlist = new CreateNewWishlist('existing', 'test_channel_code');
+
+ $this
+ ->shouldThrow(WishlistNameIsTakenException::class)
+ ->during('__invoke', [$createNewWishlist])
+ ;
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/CreateWishlistHandlerSpec.php b/spec/CommandHandler/Wishlist/CreateWishlistHandlerSpec.php
new file mode 100644
index 00000000..8ee5c213
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/CreateWishlistHandlerSpec.php
@@ -0,0 +1,140 @@
+beConstructedWith(
+ $tokenStorage,
+ $wishlistFactory,
+ $shopUserWishlistResolver,
+ $wishlistManager,
+ $channelRepository,
+ $tokenUserResolver,
+ $requestStack,
+ 'token'
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(CreateWishlistHandler::class);
+ }
+
+ public function it_creates_new_wishlist_for_user(
+ TokenStorage $tokenStorage,
+ TokenInterface $token,
+ ShopUserInterface $user,
+ WishlistFactoryInterface $wishlistFactory,
+ WishlistInterface $wishlist,
+ ShopUserWishlistResolverInterface $shopUserWishlistResolver,
+ ChannelRepositoryInterface $channelRepository,
+ ChannelInterface $channel,
+ ObjectManager $wishlistManager,
+ TokenUserResolverInterface $tokenUserResolver,
+ RequestStack $requestStack,
+ Request $request,
+ ParameterBag $attributes
+ ): void {
+ $tokenValue = 'test_token_value';
+ $channelCode = 'test_channel_code';
+
+ $createWishlist = new CreateWishlist($tokenValue, $channelCode);
+
+ $tokenStorage->getToken()->willReturn($token);
+ $tokenUserResolver->resolve($token)->willReturn($user);
+
+ $wishlistFactory->createNew()->willReturn($wishlist);
+ $shopUserWishlistResolver->resolve($user)->willReturn($wishlist);
+ $wishlist->setName('Wishlist')->shouldBeCalledOnce();
+ $wishlist->setToken($tokenValue)->shouldBeCalledOnce();
+
+ $requestStack->getMainRequest()->willReturn($request)->shouldBeCalledOnce();
+ $request->attributes = $attributes;
+
+ $channelRepository->findOneByCode($channelCode)->willReturn($channel);
+
+ $wishlist->setChannel($channel)->shouldBeCalled();
+
+ $wishlistManager->persist($wishlist)->shouldBeCalled();
+ $wishlistManager->flush()->shouldBeCalled();
+
+ $this->__invoke($createWishlist);
+ }
+
+ public function it_creates_new_wishlist_for_guest_with_missing_channel(
+ TokenStorage $tokenStorage,
+ TokenInterface $token,
+ ShopUserInterface $user,
+ WishlistFactoryInterface $wishlistFactory,
+ WishlistInterface $wishlist,
+ ShopUserWishlistResolverInterface $shopUserWishlistResolver,
+ ChannelRepositoryInterface $channelRepository,
+ ChannelInterface $channel,
+ ObjectManager $wishlistManager,
+ TokenUserResolverInterface $tokenUserResolver,
+ RequestStack $requestStack,
+ Request $request,
+ ParameterBag $attributes
+ ): void {
+ $tokenValue = 'test_token_value';
+ $channelCode = null;
+
+ $createWishlist = new CreateWishlist($tokenValue, $channelCode);
+
+ $tokenStorage->getToken()->willReturn(null);
+ $tokenUserResolver->resolve(null)->willReturn(null);
+
+ $wishlistFactory->createNew()->willReturn($wishlist);
+ $shopUserWishlistResolver->resolve($user)->shouldNotBeCalled();
+ $wishlist->setName('Wishlist')->shouldBeCalledOnce();
+ $wishlist->setToken($tokenValue)->shouldBeCalledOnce();
+
+ $requestStack->getMainRequest()->willReturn($request)->shouldBeCalledOnce();
+ $request->attributes = $attributes;
+
+ $channelRepository->findOneByCode('test')->willReturn(null);
+
+ $wishlist->setChannel($channel)->shouldNotBeCalled();
+
+ $wishlistManager->persist($wishlist)->shouldBeCalled();
+ $wishlistManager->flush()->shouldBeCalled();
+
+ $this->__invoke($createWishlist);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/ExportSelectedProductsFromWishlistToPdfHandlerSpec.php b/spec/CommandHandler/Wishlist/ExportSelectedProductsFromWishlistToPdfHandlerSpec.php
new file mode 100644
index 00000000..ffd0e2a1
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/ExportSelectedProductsFromWishlistToPdfHandlerSpec.php
@@ -0,0 +1,46 @@
+beConstructedWith($exporterWishlistToPdf);
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(ExportSelectedProductsFromWishlistToPdfHandler::class);
+ }
+
+ public function it_exports_a_collection_of_products(
+ WishlistToPdfExporterInterface $exporterWishlistToPdf,
+ ExportSelectedProductsFromWishlistToPdfInterface $exportSelectedProductsFromWishlistToPdf,
+ Collection $wishlistProducts
+ ): void {
+ $exportSelectedProductsFromWishlistToPdf
+ ->getWishlistProducts()
+ ->willReturn($wishlistProducts);
+
+ $exporterWishlistToPdf
+ ->createModelToPdfAndExportToPdf($wishlistProducts)
+ ->shouldBeCalled();
+
+ $this->__invoke($exportSelectedProductsFromWishlistToPdf);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/ExportWishlistToCsvHandlerSpec.php b/spec/CommandHandler/Wishlist/ExportWishlistToCsvHandlerSpec.php
new file mode 100644
index 00000000..69cea8ba
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/ExportWishlistToCsvHandlerSpec.php
@@ -0,0 +1,97 @@
+beConstructedWith(
+ $csvWishlistProductFactory,
+ $csvSerializerFactory
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(ExportWishlistToCsvHandler::class);
+ }
+
+ public function it_exports_wishlist_to_csv(
+ AddToCartCommandInterface $addToCartCommand,
+ OrderItemInterface $orderItem,
+ ProductVariantInterface $productVariant,
+ WishlistItemInterface $wishlistItem,
+ WishlistProductInterface $wishlistProduct,
+ ProductInterface $product,
+ \SplFileObject $file,
+ CsvWishlistProductFactoryInterface $csvWishlistProductFactory,
+ CsvWishlistProductInterface $csvWishlistProduct,
+ CsvSerializerFactoryInterface $csvSerializerFactory,
+ Serializer $serializer
+ ): void {
+ $wishlistProducts = new ArrayCollection([$wishlistItem->getWrappedObject()]);
+
+ $headers = [
+ 'variantId',
+ 'productId',
+ 'variantCode',
+ ];
+
+ $file->fputcsv($headers)->shouldBeCalled();
+
+ $wishlistItem->getCartItem()->willReturn($addToCartCommand);
+ $addToCartCommand->getCartItem()->willReturn($orderItem);
+ $wishlistItem->getWishlistProduct()->willReturn($wishlistProduct);
+
+ $orderItem->getVariant()->willReturn($productVariant);
+ $productVariant->getId()->willReturn(1);
+ $productVariant->getCode()->willReturn('test_product_variant');
+
+ $wishlistProduct->getProduct()->willReturn($product);
+ $product->getId()->willReturn(1);
+
+ $csvWishlistProductFactory
+ ->createWithProperties(1, 1, 'test_product_variant')
+ ->willReturn($csvWishlistProduct)
+ ;
+
+ $csvSerializerFactory->createNew()->willReturn($serializer);
+ $serializer->normalize($csvWishlistProduct, 'csv')->willReturn(['serializer_result']);
+
+ $file->fputcsv(['serializer_result'])->shouldBeCalled();
+
+ $exportWishlistToCsv = new ExportWishlistToCsv($wishlistProducts, $file->getWrappedObject());
+
+ $this->__invoke($exportWishlistToCsv);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/RemoveProductFromWishlistHandlerSpec.php b/spec/CommandHandler/Wishlist/RemoveProductFromWishlistHandlerSpec.php
new file mode 100644
index 00000000..d01135fb
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/RemoveProductFromWishlistHandlerSpec.php
@@ -0,0 +1,99 @@
+beConstructedWith(
+ $productRepository,
+ $wishlistRepository,
+ $wishlistProductRepository,
+ $wishlistManager
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(RemoveProductFromWishlistHandler::class);
+ }
+
+ public function it_removes_product_from_wishlist(
+ ProductRepositoryInterface $productRepository,
+ WishlistRepositoryInterface $wishlistRepository,
+ RepositoryInterface $wishlistProductRepository,
+ ObjectManager $wishlistManager,
+ ProductInterface $product,
+ WishlistInterface $wishlist,
+ WishlistProductInterface $wishlistProduct
+ ): void {
+ $removeProductCommand = new RemoveProductFromWishlist(1, 'wishlist_token');
+
+ $productRepository->find(1)->willReturn($product);
+ $wishlistRepository->findByToken('wishlist_token')->willReturn($wishlist);
+ $wishlistProductRepository
+ ->findOneBy(['product' => $product, 'wishlist' => $wishlist])
+ ->willReturn($wishlistProduct);
+
+ $wishlist->removeProduct($wishlistProduct)->willReturn($wishlist);
+ $wishlistManager->flush()->shouldBeCalled();
+
+ $this->__invoke($removeProductCommand)->shouldReturn($wishlist);
+ }
+
+ public function it_throws_exception_when_product_not_found(
+ ProductRepositoryInterface $productRepository,
+ ): void {
+ $removeProductCommand = new RemoveProductFromWishlist(1, 'wishlist_token');
+
+ $productRepository->find(1)->willReturn(null);
+
+ $this->shouldThrow(ProductNotFoundException::class)->during('__invoke', [$removeProductCommand]);
+ }
+
+ public function it_throws_exception_when_wishlist_not_found(
+ ProductRepositoryInterface $productRepository,
+ WishlistRepositoryInterface $wishlistRepository,
+ ProductInterface $product,
+ WishlistProductInterface $wishlistProduct,
+ RepositoryInterface $wishlistProductRepository
+ ): void {
+ $removeProductCommand = new RemoveProductFromWishlist(1, 'wishlist_token');
+
+ $productRepository->find(1)->willReturn($product);
+ $wishlistProductRepository->findOneBy([
+ 'product' => $product,
+ 'wishlist' => null,
+ ])->willReturn($wishlistProduct);
+ $wishlistRepository->findByToken('wishlist_token')->willReturn(null);
+
+ $this->shouldThrow(WishlistNotFoundException::class)->during('__invoke', [$removeProductCommand]);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/RemoveProductVariantFromWishlistHandlerSpec.php b/spec/CommandHandler/Wishlist/RemoveProductVariantFromWishlistHandlerSpec.php
new file mode 100644
index 00000000..59eaba57
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/RemoveProductVariantFromWishlistHandlerSpec.php
@@ -0,0 +1,93 @@
+beConstructedWith(
+ $wishlistRepository,
+ $productVariantRepository,
+ $wishlistProductRepository,
+ $wishlistManager
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(RemoveProductVariantFromWishlistHandler::class);
+ }
+
+ public function it_removes_product_variant_from_wishlist(
+ WishlistRepositoryInterface $wishlistRepository,
+ ProductVariantRepositoryInterface $productVariantRepository,
+ RepositoryInterface $wishlistProductRepository,
+ ObjectManager $wishlistManager,
+ ProductVariantInterface $variant,
+ WishlistInterface $wishlist,
+ WishlistProductInterface $wishlistProduct
+ ): void {
+ $removeProductVariantCommand = new RemoveProductVariantFromWishlist(1, 'wishlist_token');
+
+ $productVariantRepository->find(1)->willReturn($variant);
+ $wishlistProductRepository->findOneBy(['variant' => $variant])->willReturn($wishlistProduct);
+ $wishlistRepository->findByToken('wishlist_token')->willReturn($wishlist);
+
+ $wishlist->removeProductVariant($variant)->shouldBeCalled();
+ $wishlistManager->flush()->shouldBeCalled();
+
+ $this->__invoke($removeProductVariantCommand)->shouldReturn($wishlist);
+ }
+
+ public function it_throws_exception_when_product_variant_not_found(
+ ProductVariantRepositoryInterface $productVariantRepository
+ ): void {
+ $removeProductVariantCommand = new RemoveProductVariantFromWishlist(1, 'wishlist_token');
+
+ $productVariantRepository->find(1)->willReturn(null);
+
+ $this->shouldThrow(ProductVariantNotFoundException::class)->during('__invoke', [$removeProductVariantCommand]);
+ }
+
+ public function it_throws_exception_when_wishlist_not_found(
+ ProductVariantRepositoryInterface $productVariantRepository,
+ WishlistRepositoryInterface $wishlistRepository,
+ RepositoryInterface $wishlistProductRepository,
+ ProductVariantInterface $variant,
+ WishlistProductInterface $wishlistProduct,
+ ): void {
+ $removeProductVariantCommand = new RemoveProductVariantFromWishlist(1, 'wishlist_token');
+
+ $productVariantRepository->find(1)->willReturn($variant);
+ $wishlistProductRepository->findOneBy(['variant' => $variant])->willReturn($wishlistProduct);
+ $wishlistRepository->findByToken('wishlist_token')->willReturn(null);
+
+ $this->shouldThrow(WishlistNotFoundException::class)->during('__invoke', [$removeProductVariantCommand]);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/RemoveSelectedProductsFromWishlistHandlerSpec.php b/spec/CommandHandler/Wishlist/RemoveSelectedProductsFromWishlistHandlerSpec.php
new file mode 100644
index 00000000..fa8a29d5
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/RemoveSelectedProductsFromWishlistHandlerSpec.php
@@ -0,0 +1,88 @@
+beConstructedWith(
+ $productVariantRepository,
+ $wishlistProductManager,
+ $requestStack,
+ $translator
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(RemoveSelectedProductsFromWishlistHandler::class);
+ }
+
+ public function it_removes_selected_products_from_wishlist(
+ ProductVariantRepositoryInterface $productVariantRepository,
+ WishlistItemInterface $wishlistItem,
+ WishlistProductInterface $wishlistProduct,
+ ProductVariantInterface $productVariant,
+ RequestStack $requestStack,
+ Session $session,
+ FlashBagInterface $flashBag,
+ TranslatorInterface $translator
+ ): void {
+ $removeSelectedProductsCommand = new RemoveSelectedProductsFromWishlist(new ArrayCollection([$wishlistItem->getWrappedObject()]));
+
+ $productVariant->getId()->willReturn(1);
+ $wishlistItem->getWishlistProduct()->willReturn($wishlistProduct);
+ $wishlistProduct->getVariant()->willReturn($productVariant);
+ $productVariantRepository->find($productVariant)->willReturn($productVariant);
+ $requestStack->getSession()->willReturn($session);
+ $session->getFlashBag()->willReturn($flashBag);
+
+ $this->__invoke($removeSelectedProductsCommand);
+ }
+
+ public function it_throws_exception_when_variant_not_found(
+ ProductVariantRepositoryInterface $productVariantRepository,
+ WishlistItemInterface $wishlistItem,
+ WishlistProductInterface $wishlistProduct
+ ): void {
+ $removeSelectedProductsCommand = new RemoveSelectedProductsFromWishlist(new ArrayCollection([$wishlistItem->getWrappedObject()]));
+
+ $wishlistItem->getWishlistProduct()->willReturn($wishlistProduct);
+ $wishlistProduct->getVariant()->willReturn(null);
+ $productVariantRepository->find(null)->willReturn(null);
+
+ $this->shouldThrow(NotFoundHttpException::class)->during('__invoke', [$removeSelectedProductsCommand]);
+ }
+}
+
diff --git a/spec/CommandHandler/Wishlist/RemoveWishlistHandlerSpec.php b/spec/CommandHandler/Wishlist/RemoveWishlistHandlerSpec.php
new file mode 100644
index 00000000..c3a4a707
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/RemoveWishlistHandlerSpec.php
@@ -0,0 +1,66 @@
+beConstructedWith($wishlistRepository, $wishlistManager);
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(RemoveWishlistHandler::class);
+ }
+
+ public function it_removes_matching_wishlist(
+ WishlistRepositoryInterface $wishlistRepository,
+ ObjectManager $wishlistManager,
+ WishlistInterface $wishlist
+ ): void {
+ $removeWishlist = new RemoveWishlist('token');
+
+ $wishlistRepository->findByToken('token')->willReturn($wishlist);
+
+ $wishlistManager->remove($wishlist)->shouldBeCalled();
+ $wishlistManager->flush()->shouldBeCalled();
+
+ $this->__invoke($removeWishlist);
+ }
+
+ public function it_throws_exception_when_wishlist_isnt_found(
+ WishlistRepositoryInterface $wishlistRepository,
+ ObjectManager $wishlistManager,
+ WishlistInterface $wishlist
+ ): void {
+ $removeWishlist = new RemoveWishlist('token');
+
+ $wishlistRepository->findByToken('token')->willReturn(null);
+
+ $wishlistManager->remove($wishlist)->shouldNotBeCalled();
+ $wishlistManager->flush()->shouldNotBeCalled();
+
+ $this
+ ->shouldThrow(WishlistNotFoundException::class)
+ ->during('__invoke', [$removeWishlist]);
+ }
+}
diff --git a/spec/CommandHandler/Wishlist/UpdateWishlistNameHandlerSpec.php b/spec/CommandHandler/Wishlist/UpdateWishlistNameHandlerSpec.php
new file mode 100644
index 00000000..f3f461d8
--- /dev/null
+++ b/spec/CommandHandler/Wishlist/UpdateWishlistNameHandlerSpec.php
@@ -0,0 +1,73 @@
+beConstructedWith($wishlistRepository, $wishlistCookieTokenResolver);
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(UpdateWishlistNameHandler::class);
+ }
+
+ public function it_renames_found_wishlist(
+ WishlistRepositoryInterface $wishlistRepository,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ WishlistInterface $wishlist
+ ): void {
+ $updateWishlistName = new UpdateWishlistName('newName', $wishlist->getWrappedObject());
+
+ $wishlistCookieTokenResolver->resolve()->willReturn('token');
+
+ $wishlistRepository->findOneByTokenAndName('token', 'newName')->willReturn(null);
+
+ $wishlist->setName('newName')->shouldBeCalled();
+
+ $wishlistRepository->add($wishlist)->shouldBeCalled();
+
+ $this->__invoke($updateWishlistName);
+ }
+
+ public function it_throws_exception_when_wishlist_name_is_already_taken(
+ WishlistRepositoryInterface $wishlistRepository,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ WishlistInterface $wishlist,
+ WishlistInterface $existingWishlist
+ ): void {
+ $updateWishlistName = new UpdateWishlistName('newName', $wishlist->getWrappedObject());
+
+ $wishlistCookieTokenResolver->resolve()->willReturn('token');
+
+ $wishlistRepository->findOneByTokenAndName('token', 'newName')->willReturn($wishlist);
+
+ $wishlist->setName('newName')->shouldNotBeCalled();
+
+ $wishlistRepository->add($wishlist)->shouldNotBeCalled();
+
+ $this
+ ->shouldThrow(WishlistNameIsTakenException::class)
+ ->during('__invoke', [$updateWishlistName]);
+ }
+}
diff --git a/spec/Context/WishlistContextSpec.php b/spec/Context/WishlistContextSpec.php
index 81b76cf2..140c3f90 100644
--- a/spec/Context/WishlistContextSpec.php
+++ b/spec/Context/WishlistContextSpec.php
@@ -27,7 +27,7 @@
final class WishlistContextSpec extends ObjectBehavior
{
- function let(
+ public function let(
TokenStorageInterface $tokenStorage,
WishlistRepositoryInterface $wishlistRepository,
WishlistFactoryInterface $wishlistFactory,
@@ -44,17 +44,17 @@ function let(
);
}
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(WishlistContext::class);
}
- function it_implements_wishlist_context_interface(): void
+ public function it_implements_wishlist_context_interface(): void
{
$this->shouldHaveType(WishlistContextInterface::class);
}
- function it_creates_new_wishlist_if_no_cookie_and_user(
+ public function it_creates_new_wishlist_if_no_cookie_and_user(
Request $request,
ParameterBag $parameterBag,
TokenStorageInterface $tokenStorage,
@@ -73,7 +73,7 @@ function it_creates_new_wishlist_if_no_cookie_and_user(
$this->getWishlist($request)->shouldReturn($wishlist);
}
- function it_returns_cookie_wishlist_if_cookie_and_no_user(
+ public function it_returns_cookie_wishlist_if_cookie_and_no_user(
Request $request,
ParameterBag $parameterBag,
TokenStorageInterface $tokenStorage,
@@ -91,7 +91,7 @@ function it_returns_cookie_wishlist_if_cookie_and_no_user(
$this->getWishlist($request)->shouldReturn($wishlist);
}
- function it_returns_new_wishlist_if_cookie_not_found_and_no_user(
+ public function it_returns_new_wishlist_if_cookie_not_found_and_no_user(
Request $request,
ParameterBag $parameterBag,
TokenStorageInterface $tokenStorage,
@@ -111,7 +111,7 @@ function it_returns_new_wishlist_if_cookie_not_found_and_no_user(
$this->getWishlist($request)->shouldReturn($wishlist);
}
- function it_returns_user_wishlist_if_found_and_user_logged_in(
+ public function it_returns_user_wishlist_if_found_and_user_logged_in(
Request $request,
ParameterBag $parameterBag,
TokenStorageInterface $tokenStorage,
@@ -134,7 +134,7 @@ function it_returns_user_wishlist_if_found_and_user_logged_in(
$this->getWishlist($request)->shouldReturn($wishlist);
}
- function it_returns_new_wishlist_if_not_found_and_user_logged_in(
+ public function it_returns_new_wishlist_if_not_found_and_user_logged_in(
Request $request,
ParameterBag $parameterBag,
TokenStorageInterface $tokenStorage,
diff --git a/spec/Controller/Action/RemoveProductFromWishlistActionSpec.php b/spec/Controller/Action/RemoveProductFromWishlistActionSpec.php
index 6fbc0f10..025287e3 100644
--- a/spec/Controller/Action/RemoveProductFromWishlistActionSpec.php
+++ b/spec/Controller/Action/RemoveProductFromWishlistActionSpec.php
@@ -30,7 +30,7 @@
final class RemoveProductFromWishlistActionSpec extends ObjectBehavior
{
- function let(
+ public function let(
WishlistContextInterface $wishlistContext,
ProductRepositoryInterface $productRepository,
EntityManagerInterface $wishlistProductManager,
@@ -48,12 +48,12 @@ function let(
);
}
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(RemoveProductFromWishlistAction::class);
}
- function it_throws_404_if_product_was_not_found(Request $request, ProductRepositoryInterface $productRepository): void
+ public function it_throws_404_if_product_was_not_found(Request $request, ProductRepositoryInterface $productRepository): void
{
$request->get('productId')->willReturn(1);
$productRepository->find(1)->willReturn(null);
@@ -61,7 +61,7 @@ function it_throws_404_if_product_was_not_found(Request $request, ProductReposit
$this->shouldThrow(NotFoundHttpException::class)->during('__invoke', [$request]);
}
- function it_handles_request_and_redirects_to_wishlist(
+ public function it_handles_request_and_redirects_to_wishlist(
Request $request,
ProductRepositoryInterface $productRepository,
ProductInterface $product,
diff --git a/spec/DependencyInjection/BitBagSyliusWishlistExtensionSpec.php b/spec/DependencyInjection/BitBagSyliusWishlistExtensionSpec.php
index 483ff4fa..d9b5a7b4 100644
--- a/spec/DependencyInjection/BitBagSyliusWishlistExtensionSpec.php
+++ b/spec/DependencyInjection/BitBagSyliusWishlistExtensionSpec.php
@@ -17,17 +17,17 @@
final class BitBagSyliusWishlistExtensionSpec extends ObjectBehavior
{
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(BitBagSyliusWishlistExtension::class);
}
- function it_is_instance_of_prepend_extension_interface()
+ public function it_is_instance_of_prepend_extension_interface()
{
$this->shouldHaveType(PrependExtensionInterface::class);
}
- function it_is_extending_abstract_resource_extension()
+ public function it_is_extending_abstract_resource_extension()
{
$this->shouldHaveType(AbstractResourceExtension::class);
}
diff --git a/spec/DependencyInjection/ConfigurationSpec.php b/spec/DependencyInjection/ConfigurationSpec.php
index 07f41364..3ecf37ab 100644
--- a/spec/DependencyInjection/ConfigurationSpec.php
+++ b/spec/DependencyInjection/ConfigurationSpec.php
@@ -16,12 +16,12 @@
final class ConfigurationSpec extends ObjectBehavior
{
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(ConfigurationInterface::class);
}
- function it_returns_tree_builder(): void
+ public function it_returns_tree_builder(): void
{
$this->getConfigTreeBuilder()->shouldBeAnInstanceOf(TreeBuilder::class);
}
diff --git a/spec/Entity/WishlistProductSpec.php b/spec/Entity/WishlistProductSpec.php
index f63fe552..6154d96c 100644
--- a/spec/Entity/WishlistProductSpec.php
+++ b/spec/Entity/WishlistProductSpec.php
@@ -18,24 +18,24 @@
final class WishlistProductSpec extends ObjectBehavior
{
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(WishlistProduct::class);
}
- function it_implements_wishlist_product_interface(): void
+ public function it_implements_wishlist_product_interface(): void
{
$this->shouldHaveType(WishlistProductInterface::class);
}
- function it_gets_wishlist(WishlistInterface $wishlist): void
+ public function it_gets_wishlist(WishlistInterface $wishlist): void
{
$this->setWishlist($wishlist);
$this->getWishlist()->shouldReturn($wishlist);
}
- function it_gets_product(ProductInterface $product): void
+ public function it_gets_product(ProductInterface $product): void
{
$this->setProduct($product);
diff --git a/spec/Entity/WishlistSpec.php b/spec/Entity/WishlistSpec.php
index 95c714a1..8a18e2a8 100644
--- a/spec/Entity/WishlistSpec.php
+++ b/spec/Entity/WishlistSpec.php
@@ -20,33 +20,35 @@
final class WishlistSpec extends ObjectBehavior
{
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(Wishlist::class);
}
- function it_implements_wishlist_interface(): void
+ public function it_implements_wishlist_interface(): void
{
$this->shouldHaveType(WishlistInterface::class);
}
- function it_has_no_products_by_default(): void
+ public function it_has_no_products_by_default(): void
{
$this->getProducts()->toArray()->shouldReturn([]);
}
- function it_has_no_wishlist_products_by_default(): void
+ public function it_has_no_wishlist_products_by_default(): void
{
$this->getWishlistProducts()->toArray()->shouldReturn([]);
}
- function it_does_not_have_product_by_default(ProductInterface $product): void
+ public function it_does_not_have_product_by_default(ProductInterface $product): void
{
$this->hasProduct($product)->shouldReturn(false);
}
- function it_adds_wishlist_product(WishlistProductInterface $wishlistProduct, ProductVariantInterface $productVariant): void
- {
+ public function it_adds_wishlist_product(
+ WishlistProductInterface $wishlistProduct,
+ ProductVariantInterface $productVariant
+ ): void {
$wishlistProduct->getVariant()->willReturn($productVariant);
$wishlistProduct->setWishlist($this)->shouldBeCalled();
diff --git a/spec/Factory/WishlistFactorySpec.php b/spec/Factory/WishlistFactorySpec.php
index 639c470c..2b549b16 100644
--- a/spec/Factory/WishlistFactorySpec.php
+++ b/spec/Factory/WishlistFactorySpec.php
@@ -24,12 +24,12 @@ public function let(FactoryInterface $factory): void
$this->beConstructedWith($factory);
}
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(WishlistFactory::class);
}
- function it_implements_wishlist_factory_interface(): void
+ public function it_implements_wishlist_factory_interface(): void
{
$this->shouldHaveType(WishlistFactoryInterface::class);
}
@@ -41,8 +41,11 @@ public function it_creates_new_wishlist(FactoryInterface $factory, WishlistInter
$this->createNew()->shouldReturn($wishlist);
}
- function it_creates_wishlist_for_user(FactoryInterface $factory, WishlistInterface $wishlist, ShopUserInterface $shopUser): void
- {
+ public function it_creates_wishlist_for_user(
+ FactoryInterface $factory,
+ WishlistInterface $wishlist,
+ ShopUserInterface $shopUser
+ ): void {
$factory->createNew()->willReturn($wishlist);
$wishlist->setName('Wishlist')->shouldBeCalled();
diff --git a/spec/Factory/WishlistProductFactorySpec.php b/spec/Factory/WishlistProductFactorySpec.php
index fe195f2d..ff902056 100644
--- a/spec/Factory/WishlistProductFactorySpec.php
+++ b/spec/Factory/WishlistProductFactorySpec.php
@@ -22,29 +22,31 @@
final class WishlistProductFactorySpec extends ObjectBehavior
{
- function let(FactoryInterface $factory): void
+ public function let(FactoryInterface $factory): void
{
$this->beConstructedWith($factory);
}
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(WishlistProductFactory::class);
}
- function it_implements_wishlist_product_factory_interface(): void
+ public function it_implements_wishlist_product_factory_interface(): void
{
$this->shouldHaveType(WishlistProductFactoryInterface::class);
}
- function it_creates_wishlist_product(FactoryInterface $factory, WishlistProductInterface $wishlistProduct): void
- {
+ public function it_creates_wishlist_product(
+ FactoryInterface $factory,
+ WishlistProductInterface $wishlistProduct
+ ): void {
$factory->createNew()->willReturn($wishlistProduct);
$this->createNew()->shouldReturn($wishlistProduct);
}
- function it_creates_wishlist_product_for_wishlist_and_product(
+ public function it_creates_wishlist_product_for_wishlist_and_product(
FactoryInterface $factory,
WishlistProductInterface $wishlistProduct,
WishlistInterface $wishlist,
@@ -64,7 +66,7 @@ function it_creates_wishlist_product_for_wishlist_and_product(
$this->createForWishlistAndProduct($wishlist, $product);
}
- function it_creates_wishlist_product_for_wishlist_and_variant(
+ public function it_creates_wishlist_product_for_wishlist_and_variant(
FactoryInterface $factory,
WishlistProductInterface $wishlistProduct,
WishlistInterface $wishlist,
diff --git a/spec/Model/Factory/VariantPdfModelFactorySpec.php b/spec/Model/Factory/VariantPdfModelFactorySpec.php
index f4665a23..89601175 100644
--- a/spec/Model/Factory/VariantPdfModelFactorySpec.php
+++ b/spec/Model/Factory/VariantPdfModelFactorySpec.php
@@ -18,17 +18,17 @@
final class VariantPdfModelFactorySpec extends ObjectBehavior
{
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(VariantPdfModelFactory::class);
}
- function it_implements_variant_pdf_model_factory_interface(): void
+ public function it_implements_variant_pdf_model_factory_interface(): void
{
$this->shouldHaveType(VariantPdfModelFactoryInterface::class);
}
- function it_returns_product_pdf_model(): void
+ public function it_returns_product_pdf_model(): void
{
$productVariant = new ProductVariant();
$productPdfModel = $this->createWithVariantAndImagePath(
diff --git a/spec/Model/VariantPdfModelSpec.php b/spec/Model/VariantPdfModelSpec.php
index 58865543..2bce9c57 100644
--- a/spec/Model/VariantPdfModelSpec.php
+++ b/spec/Model/VariantPdfModelSpec.php
@@ -17,17 +17,17 @@
final class VariantPdfModelSpec extends ObjectBehavior
{
- function it_is_initializable(): void
+ public function it_is_initializable(): void
{
$this->shouldHaveType(VariantPdfModel::class);
}
- function it_implements_variant_pdf_model_interface(): void
+ public function it_implements_variant_pdf_model_interface(): void
{
$this->shouldHaveType(VariantPdfModelInterface::class);
}
- function it_returns_property_of_variant_pdf_model(ProductVariantInterface $productVariant): void
+ public function it_returns_property_of_variant_pdf_model(ProductVariantInterface $productVariant): void
{
$this->setActualVariant('variant test');
$this->setVariant($productVariant);
diff --git a/spec/Resolver/ShopUserWishlistResolverSpec.php b/spec/Resolver/ShopUserWishlistResolverSpec.php
new file mode 100644
index 00000000..47f5166d
--- /dev/null
+++ b/spec/Resolver/ShopUserWishlistResolverSpec.php
@@ -0,0 +1,100 @@
+beConstructedWith(
+ $wishlistRepository,
+ $wishlistFactory,
+ $channelContext
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(ShopUserWishlistResolver::class);
+ $this->shouldImplement(ShopUserWishlistResolverInterface::class);
+ }
+
+ public function it_created_new_wishlist_for_shop_user_if_cannot_resolve_with_channel(
+ WishlistRepositoryInterface $wishlistRepository,
+ WishlistFactoryInterface $wishlistFactory,
+ ChannelContextInterface $channelContext,
+ ChannelInterface $channel,
+ WishlistInterface $wishlist,
+ ShopUserInterface $user
+ ): void {
+ $channelContext->getChannel()->willReturn($channel);
+ $wishlistRepository->findOneByShopUserAndChannel($user, $channel)->willReturn(null);
+ $wishlistFactory->createForUserAndChannel($user, $channel)->willReturn($wishlist);
+
+ $this->resolve($user)->shouldReturn($wishlist);
+ }
+
+ public function it_resolves_wishlist_for_shop_user_with_channel(
+ WishlistRepositoryInterface $wishlistRepository,
+ WishlistFactoryInterface $wishlistFactory,
+ ChannelContextInterface $channelContext,
+ ChannelInterface $channel,
+ WishlistInterface $wishlist,
+ ShopUserInterface $user
+ ): void {
+ $channelContext->getChannel()->willReturn($channel);
+ $wishlistRepository->findOneByShopUserAndChannel($user, $channel)->willReturn($wishlist);
+ $wishlistFactory->createForUserAndChannel($user, $channel)->shouldNotBeCalled();
+
+ $this->resolve($user)->shouldReturn($wishlist);
+ }
+
+ public function it_created_new_wishlist_for_shop_user_if_cannot_resolve_without_channel(
+ WishlistRepositoryInterface $wishlistRepository,
+ WishlistFactoryInterface $wishlistFactory,
+ ChannelContextInterface $channelContext,
+ WishlistInterface $wishlist,
+ ShopUserInterface $user
+ ): void {
+ $channelContext->getChannel()->willThrow(ChannelNotFoundException::class);
+ $wishlistRepository->findOneByShopUser($user)->willReturn(null);
+ $wishlistFactory->createForUser($user)->willReturn($wishlist);
+
+ $this->resolve($user)->shouldReturn($wishlist);
+ }
+
+ public function it_resolves_wishlist_for_shop_user_without_channel(
+ WishlistRepositoryInterface $wishlistRepository,
+ WishlistFactoryInterface $wishlistFactory,
+ ChannelContextInterface $channelContext,
+ WishlistInterface $wishlist,
+ ShopUserInterface $user
+ ): void {
+ $channelContext->getChannel()->willThrow(ChannelNotFoundException::class);
+ $wishlistRepository->findOneByShopUser($user)->willReturn($wishlist);
+ $wishlistFactory->createForUser($user)->shouldNotBeCalled();
+
+ $this->resolve($user)->shouldReturn($wishlist);
+ }
+}
diff --git a/spec/Resolver/WishlistCookieTokenResolverSpec.php b/spec/Resolver/WishlistCookieTokenResolverSpec.php
new file mode 100644
index 00000000..659cb61c
--- /dev/null
+++ b/spec/Resolver/WishlistCookieTokenResolverSpec.php
@@ -0,0 +1,78 @@
+beConstructedWith($requestStack, 'token');
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(WishlistCookieTokenResolver::class);
+ $this->shouldImplement(WishlistCookieTokenResolverInterface::class);
+ }
+
+ public function it_returns_wishlist_cookie_token_from_main_request_cookies(
+ RequestStack $requestStack,
+ Request $request,
+ ParameterBag $inputBag
+ ): void {
+ $requestStack->getMainRequest()->willReturn($request);
+ $inputBag->get('token')->willReturn('wishlist_token');
+ $request->cookies = $inputBag;
+
+ $this->resolve()->shouldReturn('wishlist_token');
+ }
+
+ public function it_returns_wishlist_cookie_token_from_main_request_attributes(
+ RequestStack $requestStack,
+ Request $request,
+ ParameterBag $inputBagCookies,
+ ParameterBag $inputBagAttributes
+ ): void {
+ $requestStack->getMainRequest()->willReturn($request);
+ $inputBagCookies->get('token')->willReturn(null);
+ $inputBagAttributes->get('token')->willReturn('wishlist_token');
+ $request->cookies = $inputBagCookies;
+ $request->attributes = $inputBagAttributes;
+
+ $this->resolve()->shouldReturn('wishlist_token');
+ }
+
+ public function it_returns_new_wishlist_token_class_if_not_found_in_cookies_nor_attributes(
+ RequestStack $requestStack,
+ Request $request,
+ ParameterBag $inputBagCookies,
+ ParameterBag $inputBagAttributes,
+ WishlistToken $wishlistToken
+ ): void {
+ $requestStack->getMainRequest()->willReturn($request);
+ $inputBagCookies->get('token')->willReturn(null);
+ $inputBagAttributes->get('token')->willReturn(null);
+ $request->cookies = $inputBagCookies;
+ $request->attributes = $inputBagAttributes;
+ $wishlistToken->getValue()->willReturn('wishlist_token');
+
+ $this->resolve()->shouldBeString();
+ }
+}
diff --git a/spec/Resolver/WishlistsResolverSpec.php b/spec/Resolver/WishlistsResolverSpec.php
new file mode 100644
index 00000000..0b8bcf3c
--- /dev/null
+++ b/spec/Resolver/WishlistsResolverSpec.php
@@ -0,0 +1,141 @@
+beConstructedWith(
+ $wishlistRepository,
+ $tokenStorage,
+ $wishlistCookieTokenResolver,
+ $channelContext,
+ $tokenUserResolver,
+ $messageBus
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(WishlistsResolver::class);
+ $this->shouldImplement(WishlistsResolverInterface::class);
+ }
+
+ public function it_resolves_wishlists_by_shop_user_and_token(
+ WishlistRepositoryInterface $wishlistRepository,
+ TokenStorageInterface $tokenStorage,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ ChannelContextInterface $channelContext,
+ TokenUserResolverInterface $tokenUserResolver,
+ WishlistInterface $wishlist,
+ TokenInterface $token,
+ ShopUserInterface $user,
+ ChannelInterface $channel
+ ): void {
+ $wishlists = [
+ $wishlist->getWrappedObject()
+ ];
+
+ $wishlistToken = 'wishlist_token';
+
+ $tokenStorage->getToken()->willReturn($token);
+ $tokenUserResolver->resolve($token)->willReturn($user);
+ $wishlistCookieTokenResolver->resolve()->willReturn($wishlistToken);
+ $channelContext->getChannel()->willReturn($channel);
+ $user->getId()->willReturn(1);
+ $wishlistRepository->findAllByShopUserAndToken(1, $wishlistToken)->willReturn($wishlists);
+
+ $this->resolve()->shouldReturn($wishlists);
+ }
+
+ public function it_resolves_wishlists_by_token_and_channel_without_user(
+ WishlistRepositoryInterface $wishlistRepository,
+ TokenStorageInterface $tokenStorage,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ ChannelContextInterface $channelContext,
+ TokenUserResolverInterface $tokenUserResolver,
+ WishlistInterface $wishlist,
+ TokenInterface $token,
+ ChannelInterface $channel
+ ): void {
+ $wishlists = [
+ $wishlist->getWrappedObject()
+ ];
+
+ $wishlistToken = 'wishlist_token';
+
+ $tokenStorage->getToken()->willReturn($token);
+ $tokenUserResolver->resolve($token)->willReturn(null);
+ $wishlistCookieTokenResolver->resolve()->willReturn($wishlistToken);
+ $channelContext->getChannel()->willReturn($channel);
+ $wishlistRepository->findAllByAnonymousAndChannel($wishlistToken, $channel)->willReturn($wishlists);
+
+ $this->resolve()->shouldReturn($wishlists);
+ }
+
+ public function it_resolves_wishlists_by_token(
+ WishlistRepositoryInterface $wishlistRepository,
+ TokenStorageInterface $tokenStorage,
+ WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ ChannelContextInterface $channelContext,
+ TokenUserResolverInterface $tokenUserResolver,
+ WishlistInterface $wishlist,
+ TokenInterface $token
+ ): void {
+ $wishlists = [
+ $wishlist->getWrappedObject()
+ ];
+
+ $wishlistToken = 'wishlist_token';
+
+ $tokenStorage->getToken()->willReturn($token);
+ $tokenUserResolver->resolve($token)->willReturn(null);
+ $wishlistCookieTokenResolver->resolve()->willReturn($wishlistToken);
+ $channelContext->getChannel()->willThrow(ChannelNotFoundException::class);
+ $wishlistRepository->findAllByAnonymous($wishlistToken)->willReturn($wishlists);
+
+ $this->resolve()->shouldReturn($wishlists);
+ }
+}
diff --git a/spec/Services/Generator/ModelCreatorSpec.php b/spec/Services/Generator/ModelCreatorSpec.php
new file mode 100644
index 00000000..513d3f1b
--- /dev/null
+++ b/spec/Services/Generator/ModelCreatorSpec.php
@@ -0,0 +1,73 @@
+beConstructedWith(
+ $variantImageToDataUriResolver,
+ $variantPdfModelFactory,
+ $requestStack
+ );
+ }
+
+ public function it_is_initializable(): void
+ {
+ $this->shouldHaveType(ModelCreator::class);
+ $this->shouldImplement(ModelCreatorInterface::class);
+ }
+
+ public function it_creates_pdf_model(
+ WishlistItemInterface $wishlistItem,
+ OrderItemInterface $orderItem,
+ AddToCartCommandInterface $addToCartCommand,
+ ProductVariantInterface $variant,
+ Request $request,
+ VariantImageToDataUriResolverInterface $variantImageToDataUriResolver,
+ VariantPdfModelFactoryInterface $variantPdfModelFactory,
+ RequestStack $requestStack,
+ VariantPdfModelInterface $pdfModel
+ ): void {
+ $wishlistItem->getCartItem()->willReturn($addToCartCommand);
+ $addToCartCommand->getCartItem()->willReturn($orderItem);
+ $orderItem->getVariant()->willReturn($variant);
+ $orderItem->getQuantity()->willReturn(1);
+ $requestStack->getCurrentRequest()->willReturn($request);
+ $request->getSchemeAndHttpHost()->willReturn('host');
+ $variantImageToDataUriResolver->resolve($variant, 'host')->willReturn('url');
+ $variant->getCode()->willReturn('code');
+ $variantPdfModelFactory->createWithVariantAndImagePath(
+ $variant,
+ 'url',
+ 1,
+ 'code'
+ )->willReturn($pdfModel);
+
+ $this->createWishlistItemToPdf($wishlistItem)->shouldReturn($pdfModel);
+ }
+}
diff --git a/src/Checker/ProductProcessingChecker.php b/src/Checker/ProductProcessingChecker.php
index c34df3f8..e64fbff1 100644
--- a/src/Checker/ProductProcessingChecker.php
+++ b/src/Checker/ProductProcessingChecker.php
@@ -11,20 +11,16 @@
namespace BitBag\SyliusWishlistPlugin\Checker;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItem;
-use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
-use Symfony\Contracts\Translation\TranslatorInterface;
+use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface;
final class ProductProcessingChecker implements ProductProcessingCheckerInterface
{
- private ProductQuantityCheckerInterface $productQuantityChecker;
-
public function __construct(
- ProductQuantityCheckerInterface $productQuantityChecker
+ private ProductQuantityCheckerInterface $productQuantityChecker
) {
- $this->productQuantityChecker = $productQuantityChecker;
}
- public function canBeProcessed(WishlistItem $wishlistProduct): bool
+ public function canBeProcessed(WishlistItemInterface $wishlistProduct): bool
{
$cartItem = $wishlistProduct->getCartItem()->getCartItem();
diff --git a/src/Checker/ProductProcessingCheckerInterface.php b/src/Checker/ProductProcessingCheckerInterface.php
index b7c8f491..cb0aa433 100644
--- a/src/Checker/ProductProcessingCheckerInterface.php
+++ b/src/Checker/ProductProcessingCheckerInterface.php
@@ -10,9 +10,9 @@
namespace BitBag\SyliusWishlistPlugin\Checker;
-use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItem;
+use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface;
interface ProductProcessingCheckerInterface
{
- public function canBeProcessed(WishlistItem $wishlistProduct): bool;
+ public function canBeProcessed(WishlistItemInterface $wishlistProduct): bool;
}
diff --git a/src/Checker/ProductQuantityChecker.php b/src/Checker/ProductQuantityChecker.php
index 38366ebb..ae0a7e80 100644
--- a/src/Checker/ProductQuantityChecker.php
+++ b/src/Checker/ProductQuantityChecker.php
@@ -11,8 +11,6 @@
namespace BitBag\SyliusWishlistPlugin\Checker;
use Sylius\Component\Order\Model\OrderItemInterface;
-use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
-use Symfony\Contracts\Translation\TranslatorInterface;
final class ProductQuantityChecker implements ProductQuantityCheckerInterface
{
diff --git a/src/Checker/WishlistNameChecker.php b/src/Checker/WishlistNameChecker.php
index 0cf09618..112fb257 100644
--- a/src/Checker/WishlistNameChecker.php
+++ b/src/Checker/WishlistNameChecker.php
@@ -17,8 +17,8 @@ public function check(string $existingWishlistName, string $wishlistToCreate): b
{
if ($existingWishlistName == $wishlistToCreate) {
return true;
- } else {
- return false;
}
+
+ return false;
}
}
diff --git a/src/Command/Wishlist/AddProductToSelectedWishlist.php b/src/Command/Wishlist/AddProductToSelectedWishlist.php
index 609b7bc0..c7412dc5 100644
--- a/src/Command/Wishlist/AddProductToSelectedWishlist.php
+++ b/src/Command/Wishlist/AddProductToSelectedWishlist.php
@@ -13,16 +13,12 @@
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
use Sylius\Component\Core\Model\ProductInterface;
-final class AddProductToSelectedWishlist implements WishlistSyncCommandInterface
+final class AddProductToSelectedWishlist implements AddProductToSelectedWishlistInterface
{
- private WishlistInterface $wishlist;
-
- private ProductInterface $product;
-
- public function __construct(WishlistInterface $wishlist, ProductInterface $product)
- {
- $this->wishlist = $wishlist;
- $this->product = $product;
+ public function __construct(
+ private WishlistInterface $wishlist,
+ private ProductInterface $product
+ ) {
}
public function getWishlist(): WishlistInterface
diff --git a/src/Command/Wishlist/AddProductToSelectedWishlistInterface.php b/src/Command/Wishlist/AddProductToSelectedWishlistInterface.php
new file mode 100644
index 00000000..e9ede15b
--- /dev/null
+++ b/src/Command/Wishlist/AddProductToSelectedWishlistInterface.php
@@ -0,0 +1,21 @@
+wishlist;
}
}
-
diff --git a/src/Command/Wishlist/WishlistItem.php b/src/Command/Wishlist/WishlistItem.php
index b32e0fc1..3710118a 100644
--- a/src/Command/Wishlist/WishlistItem.php
+++ b/src/Command/Wishlist/WishlistItem.php
@@ -12,7 +12,6 @@
use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface;
use Sylius\Bundle\OrderBundle\Controller\AddToCartCommandInterface;
-use Sylius\Component\Order\Model\OrderItemInterface;
class WishlistItem implements WishlistItemInterface
{
diff --git a/src/Command/Wishlist/WishlistSyncCommandInterface.php b/src/Command/Wishlist/WishlistSyncCommandInterface.php
index 3aad2d3b..3ff41744 100644
--- a/src/Command/Wishlist/WishlistSyncCommandInterface.php
+++ b/src/Command/Wishlist/WishlistSyncCommandInterface.php
@@ -1,8 +1,15 @@
wishlistProductFactory = $wishlistProductFactory;
- $this->wishlistRepository = $wishlistRepository;
}
- public function __invoke(AddProductToSelectedWishlist $addProductToSelectedWishlist)
+ public function __invoke(AddProductToSelectedWishlistInterface $addProductToSelectedWishlist)
{
$product = $addProductToSelectedWishlist->getProduct();
$wishlist = $addProductToSelectedWishlist->getWishlist();
- if (null === $product) {
- throw new NotFoundHttpException();
- }
-
/** @var WishlistProductInterface $wishlistProduct */
$wishlistProduct = $this->wishlistProductFactory->createForWishlistAndProduct($wishlist, $product);
diff --git a/src/CommandHandler/Wishlist/AddProductToWishlistHandler.php b/src/CommandHandler/Wishlist/AddProductToWishlistHandler.php
index b38787b1..3cc573c1 100644
--- a/src/CommandHandler/Wishlist/AddProductToWishlistHandler.php
+++ b/src/CommandHandler/Wishlist/AddProductToWishlistHandler.php
@@ -13,7 +13,6 @@
use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductToWishlist;
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
use BitBag\SyliusWishlistPlugin\Exception\ProductNotFoundException;
-use BitBag\SyliusWishlistPlugin\Exception\WishlistNotFoundException;
use BitBag\SyliusWishlistPlugin\Factory\WishlistProductFactoryInterface;
use Doctrine\Persistence\ObjectManager;
use Sylius\Component\Core\Model\ProductInterface;
@@ -22,20 +21,11 @@
final class AddProductToWishlistHandler implements MessageHandlerInterface
{
- private WishlistProductFactoryInterface $wishlistProductFactory;
-
- private ProductRepositoryInterface $productRepository;
-
- private ObjectManager $wishlistManager;
-
public function __construct(
- WishlistProductFactoryInterface $wishlistProductFactory,
- ProductRepositoryInterface $productRepository,
- ObjectManager $wishlistManager
+ private WishlistProductFactoryInterface $wishlistProductFactory,
+ private ProductRepositoryInterface $productRepository,
+ private ObjectManager $wishlistManager
) {
- $this->wishlistProductFactory = $wishlistProductFactory;
- $this->productRepository = $productRepository;
- $this->wishlistManager = $wishlistManager;
}
public function __invoke(AddProductToWishlist $addProductToWishlist): WishlistInterface
@@ -52,12 +42,6 @@ public function __invoke(AddProductToWishlist $addProductToWishlist): WishlistIn
);
}
- if (null === $wishlist) {
- throw new WishlistNotFoundException(
- 'bitbag_sylius_wishlist_plugin.ui.wishlist_for_channel_not_found'
- );
- }
-
$wishlistProduct = $this->wishlistProductFactory->createForWishlistAndProduct($wishlist, $product);
$wishlist->addWishlistProduct($wishlistProduct);
diff --git a/src/CommandHandler/Wishlist/AddProductVariantToWishlistHandler.php b/src/CommandHandler/Wishlist/AddProductVariantToWishlistHandler.php
index da437d49..2cbca483 100644
--- a/src/CommandHandler/Wishlist/AddProductVariantToWishlistHandler.php
+++ b/src/CommandHandler/Wishlist/AddProductVariantToWishlistHandler.php
@@ -21,20 +21,11 @@
final class AddProductVariantToWishlistHandler implements MessageHandlerInterface
{
- private WishlistProductFactoryInterface $wishlistProductFactory;
-
- private ProductVariantRepositoryInterface $productVariantRepository;
-
- private ObjectManager $wishlistManager;
-
public function __construct(
- WishlistProductFactoryInterface $wishlistProductFactory,
- ProductVariantRepositoryInterface $productVariantRepository,
- ObjectManager $wishlistManager
+ private WishlistProductFactoryInterface $wishlistProductFactory,
+ private ProductVariantRepositoryInterface $productVariantRepository,
+ private ObjectManager $wishlistManager
) {
- $this->wishlistProductFactory = $wishlistProductFactory;
- $this->productVariantRepository = $productVariantRepository;
- $this->wishlistManager = $wishlistManager;
}
public function __invoke(AddProductVariantToWishlist $addProductVariantToWishlist): WishlistInterface
diff --git a/src/CommandHandler/Wishlist/AddProductsToCartHandler.php b/src/CommandHandler/Wishlist/AddProductsToCartHandler.php
index 8f1b62fe..52060df7 100644
--- a/src/CommandHandler/Wishlist/AddProductsToCartHandler.php
+++ b/src/CommandHandler/Wishlist/AddProductsToCartHandler.php
@@ -10,7 +10,7 @@
namespace BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist;
-use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductsToCart;
+use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductsToCartInterface;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItem;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface;
use Doctrine\Common\Collections\Collection;
@@ -25,31 +25,16 @@
final class AddProductsToCartHandler implements MessageHandlerInterface
{
- private RequestStack $requestStack;
-
- private TranslatorInterface $translator;
-
- private OrderModifierInterface $orderModifier;
-
- private OrderRepositoryInterface $orderRepository;
-
- private ?AvailabilityCheckerInterface $availabilityChecker;
-
public function __construct(
- RequestStack $requestStack,
- TranslatorInterface $translator,
- OrderModifierInterface $orderModifier,
- OrderRepositoryInterface $orderRepository,
- ?AvailabilityCheckerInterface $availabilityChecker = null
+ private RequestStack $requestStack,
+ private TranslatorInterface $translator,
+ private OrderModifierInterface $orderModifier,
+ private OrderRepositoryInterface $orderRepository,
+ private ?AvailabilityCheckerInterface $availabilityChecker = null
) {
- $this->requestStack = $requestStack;
- $this->translator = $translator;
- $this->orderModifier = $orderModifier;
- $this->orderRepository = $orderRepository;
- $this->availabilityChecker = $availabilityChecker;
}
- public function __invoke(AddProductsToCart $addProductsToWishlistCommand): void
+ public function __invoke(AddProductsToCartInterface $addProductsToWishlistCommand): void
{
$this->addProductsToWishlist($addProductsToWishlistCommand->getWishlistProducts());
}
diff --git a/src/CommandHandler/Wishlist/AddSelectedProductsToCartHandler.php b/src/CommandHandler/Wishlist/AddSelectedProductsToCartHandler.php
index 17406a97..328fba2e 100644
--- a/src/CommandHandler/Wishlist/AddSelectedProductsToCartHandler.php
+++ b/src/CommandHandler/Wishlist/AddSelectedProductsToCartHandler.php
@@ -10,10 +10,10 @@
namespace BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist;
-use BitBag\SyliusWishlistPlugin\Checker\ProductProcessingChecker;
use BitBag\SyliusWishlistPlugin\Checker\ProductProcessingCheckerInterface;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddSelectedProductsToCart;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItem;
+use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface;
use BitBag\SyliusWishlistPlugin\Exception\ProductCantBeAddedToCartException;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
@@ -23,24 +23,12 @@
final class AddSelectedProductsToCartHandler implements MessageHandlerInterface
{
- private OrderItemQuantityModifierInterface $itemQuantityModifier;
-
- private OrderModifierInterface $orderModifier;
-
- private OrderRepositoryInterface $orderRepository;
-
- private ProductProcessingCheckerInterface $productProcessingChecker;
-
public function __construct(
- OrderItemQuantityModifierInterface $itemQuantityModifier,
- OrderModifierInterface $orderModifier,
- OrderRepositoryInterface $orderRepository,
- ProductProcessingCheckerInterface $productProcessingChecker
+ private OrderItemQuantityModifierInterface $itemQuantityModifier,
+ private OrderModifierInterface $orderModifier,
+ private OrderRepositoryInterface $orderRepository,
+ private ProductProcessingCheckerInterface $productProcessingChecker
) {
- $this->itemQuantityModifier = $itemQuantityModifier;
- $this->orderModifier = $orderModifier;
- $this->orderRepository = $orderRepository;
- $this->productProcessingChecker = $productProcessingChecker;
}
public function __invoke(AddSelectedProductsToCart $addSelectedProductsToCartCommand): void
@@ -50,7 +38,7 @@ public function __invoke(AddSelectedProductsToCart $addSelectedProductsToCartCom
private function addSelectedProductsToCart(Collection $wishlistProducts): void
{
- /** @var WishlistItem $wishlistProduct */
+ /** @var WishlistItemInterface $wishlistProduct */
foreach ($wishlistProducts as $wishlistProduct) {
if ($this->productProcessingChecker->canBeProcessed($wishlistProduct)) {
$this->addProductToWishlist($wishlistProduct);
diff --git a/src/CommandHandler/Wishlist/AddWishlistToUserHandler.php b/src/CommandHandler/Wishlist/AddWishlistToUserHandler.php
index 8c728fd2..cb38e0d9 100644
--- a/src/CommandHandler/Wishlist/AddWishlistToUserHandler.php
+++ b/src/CommandHandler/Wishlist/AddWishlistToUserHandler.php
@@ -19,16 +19,10 @@
final class AddWishlistToUserHandler implements MessageHandlerInterface
{
- private WishlistRepositoryInterface $wishlistRepository;
-
- private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver;
-
public function __construct(
- WishlistRepositoryInterface $wishlistRepository,
- WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver
+ private WishlistRepositoryInterface $wishlistRepository,
+ private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver
) {
- $this->wishlistRepository = $wishlistRepository;
- $this->wishlistCookieTokenResolver = $wishlistCookieTokenResolver;
}
public function __invoke(AddWishlistToUser $addWishlistsToUser): void
@@ -37,12 +31,12 @@ public function __invoke(AddWishlistToUser $addWishlistsToUser): void
$user = $addWishlistsToUser->getShopUser();
$wishlistCookieToken = $this->wishlistCookieTokenResolver->resolve();
- if ($wishlistCookieToken !== $wishlist->getToken()){
+ if ($wishlistCookieToken !== $wishlist->getToken()) {
throw new WishlistHasAnotherShopUserException();
}
if ($this->wishlistRepository->findOneByShopUserAndName($user, $wishlist->getName()) instanceof WishlistInterface) {
- $wishlist->setName($wishlist->getName().$wishlist->getId());
+ $wishlist->setName($wishlist->getName() . $wishlist->getId());
}
$wishlist->setShopUser($user);
diff --git a/src/CommandHandler/Wishlist/CopySelectedProductsToOtherWishlistHandler.php b/src/CommandHandler/Wishlist/CopySelectedProductsToOtherWishlistHandler.php
index 951a2bdc..c14159e9 100644
--- a/src/CommandHandler/Wishlist/CopySelectedProductsToOtherWishlistHandler.php
+++ b/src/CommandHandler/Wishlist/CopySelectedProductsToOtherWishlistHandler.php
@@ -18,16 +18,10 @@
final class CopySelectedProductsToOtherWishlistHandler
{
- private WishlistRepositoryInterface $wishlistRepository;
-
- private WishlistProductsToOtherWishlistDuplicatorInterface $duplicatorProductsToWishlist;
-
public function __construct(
- WishlistRepositoryInterface $wishlistRepository,
- WishlistProductsToOtherWishlistDuplicatorInterface $duplicatorProductsToWishlist
+ private WishlistRepositoryInterface $wishlistRepository,
+ private WishlistProductsToOtherWishlistDuplicatorInterface $duplicatorProductsToWishlist
) {
- $this->wishlistRepository = $wishlistRepository;
- $this->duplicatorProductsToWishlist = $duplicatorProductsToWishlist;
}
public function __invoke(CopySelectedProductsToOtherWishlistInterface $copySelectedProductsToOtherWishlist): void
diff --git a/src/CommandHandler/Wishlist/CreateNewWishlistHandler.php b/src/CommandHandler/Wishlist/CreateNewWishlistHandler.php
index 6b225251..c626a8c8 100644
--- a/src/CommandHandler/Wishlist/CreateNewWishlistHandler.php
+++ b/src/CommandHandler/Wishlist/CreateNewWishlistHandler.php
@@ -1,15 +1,16 @@
wishlistRepository = $wishlistRepository;
- $this->tokenStorage = $tokenStorage;
- $this->wishlistFactory = $wishlistFactory;
- $this->wishlistCookieTokenResolver = $wishlistCookieTokenResolver;
- $this->channelRepository = $channelRepository;
- $this->wishlistNameChecker = $wishlistNameChecker;
- $this->tokenUserResolver = $tokenUserResolver;
}
public function __invoke(CreateNewWishlist $createNewWishlist): void
@@ -80,7 +60,7 @@ public function __invoke(CreateNewWishlist $createNewWishlist): void
$wishlist->setChannel($channel);
}
- /** @var WishlistInterface $wishlist */
+ /** @var WishlistInterface $newWishlist */
foreach ($wishlists as $newWishlist) {
if (!$this->wishlistNameChecker->check($newWishlist->getName(), $createNewWishlist->getName())) {
$wishlist->setName($createNewWishlist->getName());
diff --git a/src/CommandHandler/Wishlist/CreateWishlistHandler.php b/src/CommandHandler/Wishlist/CreateWishlistHandler.php
index 3c0146aa..1a09596a 100644
--- a/src/CommandHandler/Wishlist/CreateWishlistHandler.php
+++ b/src/CommandHandler/Wishlist/CreateWishlistHandler.php
@@ -26,40 +26,16 @@
final class CreateWishlistHandler implements MessageHandlerInterface
{
- private TokenStorageInterface $tokenStorage;
-
- private WishlistFactoryInterface $wishlistFactory;
-
- private ShopUserWishlistResolverInterface $shopUserWishlistResolver;
-
- private ObjectManager $wishlistManager;
-
- private ChannelRepositoryInterface $channelRepository;
-
- private TokenUserResolverInterface $tokenUserResolver;
-
- private RequestStack $requestStack;
-
- private string $wishlistCookieToken;
-
public function __construct(
- TokenStorageInterface $tokenStorage,
- WishlistFactoryInterface $wishlistFactory,
- ShopUserWishlistResolverInterface $shopUserWishlistResolver,
- ObjectManager $wishlistManager,
- ChannelRepositoryInterface $channelRepository,
- TokenUserResolverInterface $tokenUserResolver,
- RequestStack $requestStack,
- string $wishlistCookieToken,
+ private TokenStorageInterface $tokenStorage,
+ private WishlistFactoryInterface $wishlistFactory,
+ private ShopUserWishlistResolverInterface $shopUserWishlistResolver,
+ private ObjectManager $wishlistManager,
+ private ChannelRepositoryInterface $channelRepository,
+ private TokenUserResolverInterface $tokenUserResolver,
+ private RequestStack $requestStack,
+ private string $wishlistCookieToken
) {
- $this->tokenStorage = $tokenStorage;
- $this->wishlistFactory = $wishlistFactory;
- $this->shopUserWishlistResolver = $shopUserWishlistResolver;
- $this->wishlistManager = $wishlistManager;
- $this->channelRepository = $channelRepository;
- $this->tokenUserResolver = $tokenUserResolver;
- $this->requestStack = $requestStack;
- $this->wishlistCookieToken = $wishlistCookieToken;
}
public function __invoke(CreateWishlist $createWishlist): WishlistInterface
@@ -76,8 +52,7 @@ public function __invoke(CreateWishlist $createWishlist): WishlistInterface
$wishlist = $this->shopUserWishlistResolver->resolve($user);
}
- if (null !== $createWishlist->getTokenValue())
- {
+ if (null !== $createWishlist->getTokenValue()) {
$wishlist->setToken($createWishlist->getTokenValue());
$mainRequest = $this->requestStack->getMainRequest();
diff --git a/src/CommandHandler/Wishlist/ExportSelectedProductsFromWishlistToPdfHandler.php b/src/CommandHandler/Wishlist/ExportSelectedProductsFromWishlistToPdfHandler.php
index c536b48f..a9ee34f5 100644
--- a/src/CommandHandler/Wishlist/ExportSelectedProductsFromWishlistToPdfHandler.php
+++ b/src/CommandHandler/Wishlist/ExportSelectedProductsFromWishlistToPdfHandler.php
@@ -16,12 +16,9 @@
final class ExportSelectedProductsFromWishlistToPdfHandler implements MessageHandlerInterface
{
- private WishlistToPdfExporterInterface $exporterWishlistToPdf;
-
public function __construct(
- WishlistToPdfExporterInterface $exporterWishlistToPdf
+ private WishlistToPdfExporterInterface $exporterWishlistToPdf
) {
- $this->exporterWishlistToPdf = $exporterWishlistToPdf;
}
public function __invoke(ExportSelectedProductsFromWishlistToPdfInterface $exportSelectedProductsFromWishlistToPdf): void
diff --git a/src/CommandHandler/Wishlist/ExportWishlistToCsvHandler.php b/src/CommandHandler/Wishlist/ExportWishlistToCsvHandler.php
index 8c68a74b..a454527f 100644
--- a/src/CommandHandler/Wishlist/ExportWishlistToCsvHandler.php
+++ b/src/CommandHandler/Wishlist/ExportWishlistToCsvHandler.php
@@ -26,16 +26,10 @@ final class ExportWishlistToCsvHandler implements MessageHandlerInterface
'variantCode',
];
- private CsvWishlistProductFactoryInterface $csvWishlistProductFactory;
-
- private CsvSerializerFactoryInterface $csvSerializerFactory;
-
public function __construct(
- CsvWishlistProductFactoryInterface $csvWishlistProductFactory,
- CsvSerializerFactoryInterface $csvSerializerFactory
+ private CsvWishlistProductFactoryInterface $csvWishlistProductFactory,
+ private CsvSerializerFactoryInterface $csvSerializerFactory
) {
- $this->csvWishlistProductFactory = $csvWishlistProductFactory;
- $this->csvSerializerFactory = $csvSerializerFactory;
}
public function __invoke(ExportWishlistToCsv $exportWishlistToCsv): \SplFileObject
diff --git a/src/CommandHandler/Wishlist/ImportWishlistFromCsvHandler.php b/src/CommandHandler/Wishlist/ImportWishlistFromCsvHandler.php
index 9725a328..2baf62e3 100644
--- a/src/CommandHandler/Wishlist/ImportWishlistFromCsvHandler.php
+++ b/src/CommandHandler/Wishlist/ImportWishlistFromCsvHandler.php
@@ -28,32 +28,14 @@
final class ImportWishlistFromCsvHandler implements MessageHandlerInterface
{
- private AddProductVariantToWishlistAction $addProductVariantToWishlistAction;
-
- private ProductVariantRepositoryInterface $productVariantRepository;
-
- private array $allowedMimeTypes;
-
- private CsvSerializerFactoryInterface $csvSerializerFactory;
-
- private RequestStack $requestStack;
-
- private TranslatorInterface $translator;
-
public function __construct(
- AddProductVariantToWishlistAction $addProductVariantToWishlistAction,
- ProductVariantRepositoryInterface $productVariantRepository,
- array $allowedMimeTypes,
- CsvSerializerFactoryInterface $csvSerializerFactory,
- RequestStack $requestStack,
- TranslatorInterface $translator
+ private AddProductVariantToWishlistAction $addProductVariantToWishlistAction,
+ private ProductVariantRepositoryInterface $productVariantRepository,
+ private array $allowedMimeTypes,
+ private CsvSerializerFactoryInterface $csvSerializerFactory,
+ private RequestStack $requestStack,
+ private TranslatorInterface $translator
) {
- $this->addProductVariantToWishlistAction = $addProductVariantToWishlistAction;
- $this->productVariantRepository = $productVariantRepository;
- $this->allowedMimeTypes = $allowedMimeTypes;
- $this->csvSerializerFactory = $csvSerializerFactory;
- $this->requestStack = $requestStack;
- $this->translator = $translator;
}
public function __invoke(ImportWishlistFromCsv $importWishlistFromCsv): Response
diff --git a/src/CommandHandler/Wishlist/RemoveProductFromWishlistHandler.php b/src/CommandHandler/Wishlist/RemoveProductFromWishlistHandler.php
index 30102105..dc8dbb00 100644
--- a/src/CommandHandler/Wishlist/RemoveProductFromWishlistHandler.php
+++ b/src/CommandHandler/Wishlist/RemoveProductFromWishlistHandler.php
@@ -24,24 +24,12 @@
final class RemoveProductFromWishlistHandler implements MessageHandlerInterface
{
- private ProductRepositoryInterface $productRepository;
-
- private WishlistRepositoryInterface $wishlistRepository;
-
- private RepositoryInterface $wishlistProductRepository;
-
- private ObjectManager $wishlistManager;
-
public function __construct(
- ProductRepositoryInterface $productRepository,
- WishlistRepositoryInterface $wishlistRepository,
- RepositoryInterface $wishlistProductRepository,
- ObjectManager $wishlistManager
+ private ProductRepositoryInterface $productRepository,
+ private WishlistRepositoryInterface $wishlistRepository,
+ private RepositoryInterface $wishlistProductRepository,
+ private ObjectManager $wishlistManager
) {
- $this->productRepository = $productRepository;
- $this->wishlistRepository = $wishlistRepository;
- $this->wishlistProductRepository = $wishlistProductRepository;
- $this->wishlistManager = $wishlistManager;
}
public function __invoke(RemoveProductFromWishlist $removeProductFromWishlist): WishlistInterface
@@ -51,9 +39,10 @@ public function __invoke(RemoveProductFromWishlist $removeProductFromWishlist):
/** @var ?ProductInterface $product */
$product = $this->productRepository->find($productId);
- /** @var ?WishlistProductInterface $wishlistProduct */
- /** @var ?WishlistInterface $wishlist */
+
+ /** @var ?WishlistInterface $wishlist */
$wishlist = $this->wishlistRepository->findByToken($token);
+
/** @var ?WishlistProductInterface $wishlistProduct */
$wishlistProduct = $this->wishlistProductRepository->findOneBy(['product' => $product, 'wishlist' => $wishlist]);
diff --git a/src/CommandHandler/Wishlist/RemoveProductVariantFromWishlistHandler.php b/src/CommandHandler/Wishlist/RemoveProductVariantFromWishlistHandler.php
index 4ca8987d..4c26ca90 100644
--- a/src/CommandHandler/Wishlist/RemoveProductVariantFromWishlistHandler.php
+++ b/src/CommandHandler/Wishlist/RemoveProductVariantFromWishlistHandler.php
@@ -24,24 +24,12 @@
final class RemoveProductVariantFromWishlistHandler implements MessageHandlerInterface
{
- private WishlistRepositoryInterface $wishlistRepository;
-
- private ProductVariantRepositoryInterface $productVariantRepository;
-
- private RepositoryInterface $wishlistProductRepository;
-
- private ObjectManager $wishlistManager;
-
public function __construct(
- WishlistRepositoryInterface $wishlistRepository,
- ProductVariantRepositoryInterface $productVariantRepository,
- RepositoryInterface $wishlistProductRepository,
- ObjectManager $wishlistManager
+ private WishlistRepositoryInterface $wishlistRepository,
+ private ProductVariantRepositoryInterface $productVariantRepository,
+ private RepositoryInterface $wishlistProductRepository,
+ private ObjectManager $wishlistManager
) {
- $this->wishlistRepository = $wishlistRepository;
- $this->productVariantRepository = $productVariantRepository;
- $this->wishlistProductRepository = $wishlistProductRepository;
- $this->wishlistManager = $wishlistManager;
}
public function __invoke(RemoveProductVariantFromWishlist $removeProductVariantFromWishlist): WishlistInterface
diff --git a/src/CommandHandler/Wishlist/RemoveSelectedProductsFromWishlistHandler.php b/src/CommandHandler/Wishlist/RemoveSelectedProductsFromWishlistHandler.php
index 832754b5..f9b6ac13 100644
--- a/src/CommandHandler/Wishlist/RemoveSelectedProductsFromWishlistHandler.php
+++ b/src/CommandHandler/Wishlist/RemoveSelectedProductsFromWishlistHandler.php
@@ -12,11 +12,11 @@
use BitBag\SyliusWishlistPlugin\Command\Wishlist\RemoveSelectedProductsFromWishlist;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItem;
+use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
-use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
@@ -24,24 +24,12 @@
final class RemoveSelectedProductsFromWishlistHandler implements MessageHandlerInterface
{
- private ProductVariantRepositoryInterface $productVariantRepository;
-
- private EntityManagerInterface $wishlistProductManager;
-
- private RequestStack $requestStack;
-
- private TranslatorInterface $translator;
-
public function __construct(
- ProductVariantRepositoryInterface $productVariantRepository,
- EntityManagerInterface $wishlistProductManager,
- RequestStack $requestStack,
- TranslatorInterface $translator
+ private ProductVariantRepositoryInterface $productVariantRepository,
+ private EntityManagerInterface $wishlistProductManager,
+ private RequestStack $requestStack,
+ private TranslatorInterface $translator
) {
- $this->productVariantRepository = $productVariantRepository;
- $this->wishlistProductManager = $wishlistProductManager;
- $this->requestStack = $requestStack;
- $this->translator = $translator;
}
public function __invoke(RemoveSelectedProductsFromWishlist $removeSelectedProductsFromWishlistCommand): void
@@ -62,7 +50,7 @@ private function removeSelectedProductsFromWishlist(Collection $wishlistProducts
}
}
- private function removeProductFromWishlist(WishlistItem $wishlistProduct): void
+ private function removeProductFromWishlist(WishlistItemInterface $wishlistProduct): void
{
$productVariant = $this->productVariantRepository->find($wishlistProduct->getWishlistProduct()->getVariant());
diff --git a/src/CommandHandler/Wishlist/RemoveWishlistHandler.php b/src/CommandHandler/Wishlist/RemoveWishlistHandler.php
index a8296ac9..2d4e81ed 100644
--- a/src/CommandHandler/Wishlist/RemoveWishlistHandler.php
+++ b/src/CommandHandler/Wishlist/RemoveWishlistHandler.php
@@ -18,16 +18,10 @@
final class RemoveWishlistHandler implements MessageHandlerInterface
{
- private WishlistRepositoryInterface $wishlistRepository;
-
- private ObjectManager $wishlistManager;
-
public function __construct(
- WishlistRepositoryInterface $wishlistRepository,
- ObjectManager $wishlistManager
+ private WishlistRepositoryInterface $wishlistRepository,
+ private ObjectManager $wishlistManager
) {
- $this->wishlistRepository = $wishlistRepository;
- $this->wishlistManager = $wishlistManager;
}
public function __invoke(RemoveWishlist $removeWishlist): void
diff --git a/src/CommandHandler/Wishlist/UpdateWishlistNameHandler.php b/src/CommandHandler/Wishlist/UpdateWishlistNameHandler.php
index 1ff72761..a81d37a0 100644
--- a/src/CommandHandler/Wishlist/UpdateWishlistNameHandler.php
+++ b/src/CommandHandler/Wishlist/UpdateWishlistNameHandler.php
@@ -15,16 +15,10 @@
final class UpdateWishlistNameHandler
{
- private WishlistRepositoryInterface $wishlistRepository;
-
- private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver;
-
public function __construct(
- WishlistRepositoryInterface $wishlistRepository,
- WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver
+ private WishlistRepositoryInterface $wishlistRepository,
+ private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver
) {
- $this->wishlistRepository = $wishlistRepository;
- $this->wishlistCookieTokenResolver = $wishlistCookieTokenResolver;
}
public function __invoke(UpdateWishlistName $updateWishlistName): void
diff --git a/src/Context/WishlistContext.php b/src/Context/WishlistContext.php
index e7c1b921..d194fe1c 100644
--- a/src/Context/WishlistContext.php
+++ b/src/Context/WishlistContext.php
@@ -23,32 +23,14 @@
final class WishlistContext implements WishlistContextInterface
{
- private TokenStorageInterface $tokenStorage;
-
- private WishlistRepositoryInterface $wishlistRepository;
-
- private WishlistFactoryInterface $wishlistFactory;
-
- private string $wishlistCookieToken;
-
- private ChannelContextInterface $channelContext;
-
- private TokenUserResolverInterface $tokenUserResolver;
-
public function __construct(
- TokenStorageInterface $tokenStorage,
- WishlistRepositoryInterface $wishlistRepository,
- WishlistFactoryInterface $wishlistFactory,
- string $wishlistCookieToken,
- ChannelContextInterface $channelContext,
- TokenUserResolverInterface $tokenUserResolver,
- ) {
- $this->tokenStorage = $tokenStorage;
- $this->wishlistRepository = $wishlistRepository;
- $this->wishlistFactory = $wishlistFactory;
- $this->wishlistCookieToken = $wishlistCookieToken;
- $this->channelContext = $channelContext;
- $this->tokenUserResolver = $tokenUserResolver;
+ private TokenStorageInterface $tokenStorage,
+ private WishlistRepositoryInterface $wishlistRepository,
+ private WishlistFactoryInterface $wishlistFactory,
+ private string $wishlistCookieToken,
+ private ChannelContextInterface $channelContext,
+ private TokenUserResolverInterface $tokenUserResolver,
+ ) {
}
public function getWishlist(Request $request): WishlistInterface
diff --git a/src/Controller/Action/AddProductToSelectedWishlistAction.php b/src/Controller/Action/AddProductToSelectedWishlistAction.php
index 3c48ebb5..1d2209b5 100644
--- a/src/Controller/Action/AddProductToSelectedWishlistAction.php
+++ b/src/Controller/Action/AddProductToSelectedWishlistAction.php
@@ -20,7 +20,6 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
diff --git a/src/Controller/Action/AddWishlistToUserAction.php b/src/Controller/Action/AddWishlistToUserAction.php
index ed200beb..f3ed5d23 100644
--- a/src/Controller/Action/AddWishlistToUserAction.php
+++ b/src/Controller/Action/AddWishlistToUserAction.php
@@ -49,7 +49,7 @@ public function __construct(
UrlGeneratorInterface $urlGenerator,
TokenStorageInterface $tokenStorage,
TokenUserResolverInterface $tokenUserResolver,
- ) {
+ ) {
$this->commandBus = $commandBus;
$this->requestStack = $requestStack;
$this->translator = $translator;
diff --git a/src/Controller/Action/BaseWishlistProductsAction.php b/src/Controller/Action/BaseWishlistProductsAction.php
index c609eb88..2fb5d686 100644
--- a/src/Controller/Action/BaseWishlistProductsAction.php
+++ b/src/Controller/Action/BaseWishlistProductsAction.php
@@ -65,22 +65,22 @@ public function __construct(
public function __invoke(int $wishlistId, Request $request): Response
{
- if ($this->createForm($wishlistId) == null) {
+ if (null === $this->createForm($wishlistId)) {
return new RedirectResponse(
- $this->urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_locale_wishlist_list_wishlists'));
- } else {
- $form = $this->createForm($wishlistId);
- $form->handleRequest($request);
+ $this->urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_locale_wishlist_list_wishlists')
+ );
+ }
+ $form = $this->createForm($wishlistId);
+ $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $this->handleCommand($form);
+ if ($form->isSubmitted() && $form->isValid()) {
+ $this->handleCommand($form);
- return new RedirectResponse(
- $this->urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_locale_wishlist_show_chosen_wishlist', [
+ return new RedirectResponse(
+ $this->urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_locale_wishlist_show_chosen_wishlist', [
'wishlistId' => $wishlistId,
])
- );
- }
+ );
}
/** @var Session $session */
@@ -103,18 +103,19 @@ private function createForm(int $wishlistId): ?FormInterface
{
$wishlist = $this->wishlistRepository->find($wishlistId);
$cart = $this->cartContext->getCart();
- if ($wishlist == null) {
+
+ if (null === $wishlist) {
/** @var Session $session */
$session = $this->requestStack->getSession();
$session->getFlashBag()->add('error', $this->translator->trans('bitbag_sylius_wishlist_plugin.ui.wishlist_not_exists'));
+
return null;
- } else {
- $commandsArray = $this->wishlistCommandProcessor->createWishlistItemsCollection($wishlist->getWishlistProducts());
+ }
+ $commandsArray = $this->wishlistCommandProcessor->createWishlistItemsCollection($wishlist->getWishlistProducts());
- return $this->formFactory->create(WishlistCollectionType::class, ['items' => $commandsArray], [
+ return $this->formFactory->create(WishlistCollectionType::class, ['items' => $commandsArray], [
'cart' => $cart,
]);
- }
}
}
diff --git a/src/Controller/Action/CleanWishlistAction.php b/src/Controller/Action/CleanWishlistAction.php
index 09e8b375..35d5996b 100644
--- a/src/Controller/Action/CleanWishlistAction.php
+++ b/src/Controller/Action/CleanWishlistAction.php
@@ -17,7 +17,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
diff --git a/src/Controller/Action/CreateNewWishlistAction.php b/src/Controller/Action/CreateNewWishlistAction.php
index c2902dd4..33928701 100644
--- a/src/Controller/Action/CreateNewWishlistAction.php
+++ b/src/Controller/Action/CreateNewWishlistAction.php
@@ -11,14 +11,12 @@
namespace BitBag\SyliusWishlistPlugin\Controller\Action;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\CreateNewWishlist;
-use BitBag\SyliusWishlistPlugin\Exception\WishlistNameIsTakenException;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Channel\Context\ChannelNotFoundException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -82,7 +80,6 @@ public function __invoke(Request $request): Response
);
}
-
return new JsonResponse();
}
}
diff --git a/src/Controller/Action/ExportSelectedProductsToCsvAction.php b/src/Controller/Action/ExportSelectedProductsToCsvAction.php
index f7feea1d..7ab6d8e4 100644
--- a/src/Controller/Action/ExportSelectedProductsToCsvAction.php
+++ b/src/Controller/Action/ExportSelectedProductsToCsvAction.php
@@ -35,40 +35,19 @@ final class ExportSelectedProductsToCsvAction
{
use HandleTrait;
- private CartContextInterface $cartContext;
-
- private FormFactoryInterface $formFactory;
-
- private RequestStack $requestStack;
-
- private WishlistCommandProcessorInterface $wishlistCommandProcessor;
-
- private UrlGeneratorInterface $urlGenerator;
-
- private TranslatorInterface $translator;
-
- private WishlistRepositoryInterface $wishlistRepository;
-
private string $wishlistName;
public function __construct(
- CartContextInterface $cartContext,
- FormFactoryInterface $formFactory,
- RequestStack $requestStack,
- MessageBusInterface $messageBus,
- WishlistCommandProcessorInterface $wishlistCommandProcessor,
- UrlGeneratorInterface $urlGenerator,
- TranslatorInterface $translator,
- WishlistRepositoryInterface $wishlistRepository
+ private CartContextInterface $cartContext,
+ private FormFactoryInterface $formFactory,
+ private RequestStack $requestStack,
+ private WishlistCommandProcessorInterface $wishlistCommandProcessor,
+ private UrlGeneratorInterface $urlGenerator,
+ private TranslatorInterface $translator,
+ private WishlistRepositoryInterface $wishlistRepository,
+ MessageBusInterface $messageBus
) {
- $this->cartContext = $cartContext;
- $this->formFactory = $formFactory;
- $this->requestStack = $requestStack;
$this->messageBus = $messageBus;
- $this->wishlistCommandProcessor = $wishlistCommandProcessor;
- $this->urlGenerator = $urlGenerator;
- $this->translator = $translator;
- $this->wishlistRepository = $wishlistRepository;
}
public function __invoke(int $wishlistId, Request $request): Response
diff --git a/src/Controller/Action/ImportWishlistFromCsvAction.php b/src/Controller/Action/ImportWishlistFromCsvAction.php
index 2aed3d6e..3c025a16 100644
--- a/src/Controller/Action/ImportWishlistFromCsvAction.php
+++ b/src/Controller/Action/ImportWishlistFromCsvAction.php
@@ -29,26 +29,14 @@ final class ImportWishlistFromCsvAction
{
use HandleTrait;
- private FormFactoryInterface $formFactory;
-
- private RequestStack $requestStack;
-
- private Environment $twigEnvironment;
-
- private WishlistsResolverInterface $wishlistsResolver;
-
public function __construct(
- FormFactoryInterface $formFactory,
- RequestStack $requestStack,
- MessageBusInterface $messageBus,
- Environment $twigEnvironment,
- WishlistsResolverInterface $wishlistsResolver
+ private FormFactoryInterface $formFactory,
+ private RequestStack $requestStack,
+ private Environment $twigEnvironment,
+ private WishlistsResolverInterface $wishlistsResolver,
+ MessageBusInterface $messageBus
) {
- $this->formFactory = $formFactory;
- $this->requestStack = $requestStack;
$this->messageBus = $messageBus;
- $this->twigEnvironment = $twigEnvironment;
- $this->wishlistsResolver = $wishlistsResolver;
}
public function __invoke(Request $request): Response
diff --git a/src/Controller/Action/ShowChosenWishlistAction.php b/src/Controller/Action/ShowChosenWishlistAction.php
index 13bf28dd..6de651b9 100644
--- a/src/Controller/Action/ShowChosenWishlistAction.php
+++ b/src/Controller/Action/ShowChosenWishlistAction.php
@@ -57,7 +57,7 @@ public function __construct(
WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
TokenStorageInterface $tokenStorage,
TokenUserResolverInterface $tokenUserResolver,
- ) {
+ ) {
$this->wishlistRepository = $wishlistRepository;
$this->cartContext = $cartContext;
$this->formFactory = $formFactory;
@@ -74,15 +74,16 @@ public function __invoke(string $wishlistId, Request $request): Response
$token = $this->tokenStorage->getToken();
/** @var WishlistInterface $wishlist */
- $wishlist = $this->wishlistRepository->find((int)$wishlistId);
+ $wishlist = $this->wishlistRepository->find((int) $wishlistId);
$wishlistCookieToken = $this->wishlistCookieTokenResolver->resolve();
$user = $this->tokenUserResolver->resolve($token);
if ($wishlist instanceof WishlistInterface && $user instanceof ShopUserInterface
|| $wishlist instanceof WishlistInterface && $wishlist->getToken() === $wishlistCookieToken
- && $wishlist->getShopUser() === null) {
+ && null === $wishlist->getShopUser()) {
$form = $this->createForm($wishlist);
+
return new Response(
$this->twigEnvironment->render('@BitBagSyliusWishlistPlugin/WishlistDetails/index.html.twig', [
'wishlist' => $wishlist,
@@ -91,7 +92,7 @@ public function __invoke(string $wishlistId, Request $request): Response
);
}
- return new RedirectResponse($this->urlGenerator->generate("bitbag_sylius_wishlist_plugin_shop_locale_wishlist_list_wishlists"));
+ return new RedirectResponse($this->urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_locale_wishlist_list_wishlists'));
}
private function createForm(WishlistInterface $wishlist): FormInterface
diff --git a/src/Controller/Action/UpdateWishlistNameAction.php b/src/Controller/Action/UpdateWishlistNameAction.php
index 5e5bf295..b45dd63d 100644
--- a/src/Controller/Action/UpdateWishlistNameAction.php
+++ b/src/Controller/Action/UpdateWishlistNameAction.php
@@ -15,7 +15,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -73,6 +72,7 @@ public function __invoke(Request $request): Response
$this->translator->trans('bitbag_sylius_wishlist_plugin.ui.wishlist_name_already_exists')
);
}
+
return new Response($this->urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_locale_wishlist_list_products'));
}
}
diff --git a/src/Controller/OrderItemController.php b/src/Controller/OrderItemController.php
index dbe0dc58..6792d74e 100644
--- a/src/Controller/OrderItemController.php
+++ b/src/Controller/OrderItemController.php
@@ -74,6 +74,7 @@ public function addAction(Request $request): Response
return new Response($this->generateUrl('sylius_shop_homepage'));
}
+
return new Response($this->generateUrl('bitbag_sylius_wishlist_plugin_shop_locale_wishlist_add_product_variant', [
'wishlistId' => $wishlist->getId(),
'variantId' => $variant->getId(),
diff --git a/src/Duplicator/WishlistProductsToOtherWishlistDuplicator.php b/src/Duplicator/WishlistProductsToOtherWishlistDuplicator.php
index 5ba1a34b..2d680f29 100644
--- a/src/Duplicator/WishlistProductsToOtherWishlistDuplicator.php
+++ b/src/Duplicator/WishlistProductsToOtherWishlistDuplicator.php
@@ -14,7 +14,6 @@
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface;
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
use BitBag\SyliusWishlistPlugin\Facade\WishlistProductFactoryFacadeInterface;
-use BitBag\SyliusWishlistPlugin\Guard\ProductVariantInWishlistGuardInterface;
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface;
@@ -24,28 +23,13 @@
final class WishlistProductsToOtherWishlistDuplicator implements WishlistProductsToOtherWishlistDuplicatorInterface
{
- private WishlistProductFactoryFacadeInterface $wishlistProductVariantFactory;
-
- private ProductVariantRepositoryInterface $productVariantRepository;
-
- private WishlistRepositoryInterface $wishlistRepository;
-
- private RequestStack $requestStack;
-
- private TranslatorInterface $translator;
-
public function __construct(
- WishlistProductFactoryFacadeInterface $wishlistProductVariantFactory,
- ProductVariantRepositoryInterface $productVariantRepository,
- WishlistRepositoryInterface $wishlistRepository,
- RequestStack $requestStack,
- TranslatorInterface $translator
+ private WishlistProductFactoryFacadeInterface $wishlistProductVariantFactory,
+ private ProductVariantRepositoryInterface $productVariantRepository,
+ private WishlistRepositoryInterface $wishlistRepository,
+ private RequestStack $requestStack,
+ private TranslatorInterface $translator
) {
- $this->wishlistProductVariantFactory = $wishlistProductVariantFactory;
- $this->productVariantRepository = $productVariantRepository;
- $this->wishlistRepository = $wishlistRepository;
- $this->requestStack = $requestStack;
- $this->translator = $translator;
}
public function copyWishlistProductsToOtherWishlist(Collection $wishlistProducts, WishlistInterface $destinedWishlist): void
@@ -62,7 +46,7 @@ public function copyWishlistProductsToOtherWishlist(Collection $wishlistProducts
$session->getFlashBag()->add(
'error',
- sprintf("%s".$message, $variant)
+ sprintf('%s' . $message, $variant)
);
} else {
$this->wishlistProductVariantFactory->createWithProductVariant($destinedWishlist, $variant);
diff --git a/src/EventSubscriber/CreateNewWishlistSubscriber.php b/src/EventSubscriber/CreateNewWishlistSubscriber.php
index 69ffef7f..ea1c14a0 100644
--- a/src/EventSubscriber/CreateNewWishlistSubscriber.php
+++ b/src/EventSubscriber/CreateNewWishlistSubscriber.php
@@ -26,25 +26,14 @@ final class CreateNewWishlistSubscriber implements EventSubscriberInterface
{
private const ALLOWED_ENDPOINTS_PREFIX = '/wishlist';
- private string $wishlistCookieToken;
-
- private WishlistsResolverInterface $wishlistsResolver;
-
- private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver;
-
- private ?Request $mainRequest = null;
-
public function __construct(
- string $wishlistCookieToken,
- WishlistsResolverInterface $wishlistsResolver,
- WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
- RequestStack $requestStack,
+ private string $wishlistCookieToken,
+ private WishlistsResolverInterface $wishlistsResolver,
+ private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ private RequestStack $requestStack,
+ private ?Request $mainRequest = null
) {
- $this->wishlistCookieToken = $wishlistCookieToken;
- $this->wishlistsResolver = $wishlistsResolver;
- $this->wishlistCookieTokenResolver = $wishlistCookieTokenResolver;
-
- $this->mainRequest = $requestStack->getMainRequest();
+ $this->mainRequest = $this->requestStack->getMainRequest();
}
public static function getSubscribedEvents(): array
diff --git a/src/Exception/ProductNotFoundException.php b/src/Exception/ProductNotFoundException.php
index dcc9f315..2406a3c7 100644
--- a/src/Exception/ProductNotFoundException.php
+++ b/src/Exception/ProductNotFoundException.php
@@ -12,6 +12,6 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-class ProductNotFoundException extends NotFoundHttpException
+final class ProductNotFoundException extends NotFoundHttpException
{
}
diff --git a/src/Facade/WishlistProductFactoryFacade.php b/src/Facade/WishlistProductFactoryFacade.php
index e6a40af8..88ddc993 100644
--- a/src/Facade/WishlistProductFactoryFacade.php
+++ b/src/Facade/WishlistProductFactoryFacade.php
@@ -18,11 +18,9 @@
final class WishlistProductFactoryFacade implements WishlistProductFactoryFacadeInterface
{
- private WishlistProductFactoryInterface $wishlistProductFactory;
-
- public function __construct(WishlistProductFactoryInterface $wishlistProductFactory)
- {
- $this->wishlistProductFactory = $wishlistProductFactory;
+ public function __construct(
+ private WishlistProductFactoryInterface $wishlistProductFactory
+ ) {
}
public function createWithProduct(WishlistInterface $wishlist, ProductInterface $product): void
diff --git a/src/Factory/DomPdfFactory.php b/src/Factory/DomPdfFactory.php
index c54bb5c8..56016a87 100644
--- a/src/Factory/DomPdfFactory.php
+++ b/src/Factory/DomPdfFactory.php
@@ -15,11 +15,9 @@
class DomPdfFactory implements DomPdfFactoryInterface
{
- private DomPdfOptionsFactoryInterface $domPdfOptionsFactory;
-
- public function __construct(DomPdfOptionsFactoryInterface $domPdfOptionsFactory)
- {
- $this->domPdfOptionsFactory = $domPdfOptionsFactory;
+ public function __construct(
+ private DomPdfOptionsFactoryInterface $domPdfOptionsFactory
+ ) {
}
public function createNew(): Dompdf
diff --git a/src/Factory/WishlistFactory.php b/src/Factory/WishlistFactory.php
index 3c2b9f30..6fa9c9f9 100644
--- a/src/Factory/WishlistFactory.php
+++ b/src/Factory/WishlistFactory.php
@@ -17,11 +17,9 @@
final class WishlistFactory implements WishlistFactoryInterface
{
- private FactoryInterface $wishlistFactory;
-
- public function __construct(FactoryInterface $wishlistFactory)
- {
- $this->wishlistFactory = $wishlistFactory;
+ public function __construct(
+ private FactoryInterface $wishlistFactory
+ ) {
}
public function createNew(): WishlistInterface
diff --git a/src/Factory/WishlistProductFactory.php b/src/Factory/WishlistProductFactory.php
index dbcf18f4..b35283ee 100644
--- a/src/Factory/WishlistProductFactory.php
+++ b/src/Factory/WishlistProductFactory.php
@@ -18,11 +18,9 @@
final class WishlistProductFactory implements WishlistProductFactoryInterface
{
- private FactoryInterface $wishlistProductFactory;
-
- public function __construct(FactoryInterface $wishlistProductFactory)
- {
- $this->wishlistProductFactory = $wishlistProductFactory;
+ public function __construct(
+ private FactoryInterface $wishlistProductFactory
+ ) {
}
public function createNew(): WishlistProductInterface
diff --git a/src/Form/Extension/AddToCartTypeExtension.php b/src/Form/Extension/AddToCartTypeExtension.php
index 7f9070b5..ccef6225 100644
--- a/src/Form/Extension/AddToCartTypeExtension.php
+++ b/src/Form/Extension/AddToCartTypeExtension.php
@@ -21,11 +21,9 @@
final class AddToCartTypeExtension extends AbstractTypeExtension
{
- private WishlistsResolverInterface $wishlistsResolver;
-
- public function __construct(WishlistsResolverInterface $wishlistsResolver)
- {
- $this->wishlistsResolver = $wishlistsResolver;
+ public function __construct(
+ private WishlistsResolverInterface $wishlistsResolver
+ ) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
diff --git a/src/Form/Type/AddProductsToCartType.php b/src/Form/Type/AddProductsToCartType.php
index cd9ee48a..25c0c408 100644
--- a/src/Form/Type/AddProductsToCartType.php
+++ b/src/Form/Type/AddProductsToCartType.php
@@ -57,7 +57,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$form
->add('cartItem', AddToCartType::class, [
- 'constraints'=> new Valid(),
+ 'constraints' => new Valid(),
'label' => false,
'required' => false,
'product' => $wishlistProduct->getProduct(),
diff --git a/src/Form/Type/ImportWishlistFromCsvType.php b/src/Form/Type/ImportWishlistFromCsvType.php
index dfa75da6..ac7e8802 100644
--- a/src/Form/Type/ImportWishlistFromCsvType.php
+++ b/src/Form/Type/ImportWishlistFromCsvType.php
@@ -54,7 +54,7 @@ public function configureOptions(OptionsResolver $resolver)
'allowedMimeTypes' => [
'text/plain',
'text/csv',
- 'application/csv'
+ 'application/csv',
],
'wishlists' => [],
]);
diff --git a/src/Migrations/Version20230522123447.php b/src/Migrations/Version20230522123447.php
index 11b9b50f..1978b49d 100644
--- a/src/Migrations/Version20230522123447.php
+++ b/src/Migrations/Version20230522123447.php
@@ -22,12 +22,12 @@ public function getDescription(): string
public function up(Schema $schema): void
{
- # Missing fields
+ // Missing fields
$this->addSql('ALTER TABLE bitbag_wishlist ADD channel_id INT DEFAULT NULL, ADD name VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE bitbag_wishlist ADD CONSTRAINT FK_578D4E7772F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id) ON DELETE CASCADE');
$this->addSql('CREATE INDEX IDX_578D4E7772F5A1AA ON bitbag_wishlist (channel_id)');
- # Missing indexes
+ // Missing indexes
$this->addSql('ALTER TABLE bitbag_wishlist DROP INDEX UNIQ_578D4E77A45D93BF, ADD INDEX IDX_578D4E77A45D93BF (shop_user_id)');
$this->addSql('DROP INDEX UNIQ_578D4E775F37A13B ON bitbag_wishlist');
}
diff --git a/src/Model/Factory/VariantPdfModelFactory.php b/src/Model/Factory/VariantPdfModelFactory.php
index d1a5dc34..8ef08f3b 100644
--- a/src/Model/Factory/VariantPdfModelFactory.php
+++ b/src/Model/Factory/VariantPdfModelFactory.php
@@ -11,6 +11,7 @@
namespace BitBag\SyliusWishlistPlugin\Model\Factory;
use BitBag\SyliusWishlistPlugin\Model\VariantPdfModel;
+use BitBag\SyliusWishlistPlugin\Model\VariantPdfModelInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
final class VariantPdfModelFactory implements VariantPdfModelFactoryInterface
@@ -20,7 +21,7 @@ public function createWithVariantAndImagePath(
string $path,
int $quantity,
string $actualVariant
- ): VariantPdfModel {
+ ): VariantPdfModelInterface {
$productPdfModel = new VariantPdfModel();
$productPdfModel->setVariant($variant);
diff --git a/src/Model/Factory/VariantPdfModelFactoryInterface.php b/src/Model/Factory/VariantPdfModelFactoryInterface.php
index 70221b19..3a37c8d4 100644
--- a/src/Model/Factory/VariantPdfModelFactoryInterface.php
+++ b/src/Model/Factory/VariantPdfModelFactoryInterface.php
@@ -10,7 +10,7 @@
namespace BitBag\SyliusWishlistPlugin\Model\Factory;
-use BitBag\SyliusWishlistPlugin\Model\VariantPdfModel;
+use BitBag\SyliusWishlistPlugin\Model\VariantPdfModelInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
interface VariantPdfModelFactoryInterface
@@ -20,5 +20,5 @@ public function createWithVariantAndImagePath(
string $path,
int $quantity,
string $actualVariant
- ): VariantPdfModel;
+ ): VariantPdfModelInterface;
}
diff --git a/src/Processor/VariantPdfModelProcessor.php b/src/Processor/VariantPdfModelProcessor.php
index 8d88256d..48ade170 100644
--- a/src/Processor/VariantPdfModelProcessor.php
+++ b/src/Processor/VariantPdfModelProcessor.php
@@ -19,11 +19,9 @@
final class VariantPdfModelProcessor implements VariantPdfModelProcessorInterface
{
- private ModelCreatorInterface $pdfModelCreator;
-
- public function __construct(ModelCreatorInterface $pdfModelCreator)
- {
- $this->pdfModelCreator = $pdfModelCreator;
+ public function __construct(
+ private ModelCreatorInterface $pdfModelCreator
+ ) {
}
public function createVariantPdfModelCollection(Collection $wishlistProducts): ArrayCollection
diff --git a/src/Repository/WishlistRepository.php b/src/Repository/WishlistRepository.php
index 2b238561..ab31cbb6 100644
--- a/src/Repository/WishlistRepository.php
+++ b/src/Repository/WishlistRepository.php
@@ -62,6 +62,7 @@ public function findAllByShopUser(int $shopUser): ?array
public function findAllByShopUserAndToken(int $shopUser, string $token): ?array
{
$qb = $this->createQueryBuilder('o');
+
return $qb->where('o.shopUser = :shopUser')
->orWhere($qb->expr()->andX(
'o.token = :token',
diff --git a/src/Resolver/GenerateDataUriForImageResolver.php b/src/Resolver/GenerateDataUriForImageResolver.php
index c3f59fc8..44555d7f 100644
--- a/src/Resolver/GenerateDataUriForImageResolver.php
+++ b/src/Resolver/GenerateDataUriForImageResolver.php
@@ -16,20 +16,11 @@
final class GenerateDataUriForImageResolver implements GenerateDataUriForImageResolverInterface
{
- private PackageInterface $package;
-
- private FilterService $filterService;
-
- private string $imageFilterName;
-
public function __construct(
- PackageInterface $package,
- FilterService $filterService,
- string $imageFilterName
+ private PackageInterface $package,
+ private FilterService $filterService,
+ private string $imageFilterName
) {
- $this->package = $package;
- $this->filterService = $filterService;
- $this->imageFilterName = $imageFilterName;
}
public function resolve(ProductImageInterface $image): string
@@ -44,7 +35,7 @@ public function resolve(ProductImageInterface $image): string
public function resolveWithNoImage(): string
{
- $pathToReadFile = self::PATH_TO_EMPTY_PRODUCT_IMAGE;
+ $pathToReadFile = self::PATH_TO_EMPTY_PRODUCT_IMAGE;
$data = file_get_contents($pathToReadFile);
return 'data:image/' . 'png' . ';base64,' . base64_encode($data);
diff --git a/src/Resolver/ShopUserWishlistResolver.php b/src/Resolver/ShopUserWishlistResolver.php
index 7c3c4c42..8986c8ef 100644
--- a/src/Resolver/ShopUserWishlistResolver.php
+++ b/src/Resolver/ShopUserWishlistResolver.php
@@ -20,20 +20,11 @@
final class ShopUserWishlistResolver implements ShopUserWishlistResolverInterface
{
- private WishlistRepositoryInterface $wishlistRepository;
-
- private WishlistFactoryInterface $wishlistFactory;
-
- private ChannelContextInterface $channelContext;
-
public function __construct(
- WishlistRepositoryInterface $wishlistRepository,
- WishlistFactoryInterface $wishlistFactory,
- ChannelContextInterface $channelContext
+ private WishlistRepositoryInterface $wishlistRepository,
+ private WishlistFactoryInterface $wishlistFactory,
+ private ChannelContextInterface $channelContext
) {
- $this->wishlistRepository = $wishlistRepository;
- $this->wishlistFactory = $wishlistFactory;
- $this->channelContext = $channelContext;
}
public function resolve(ShopUserInterface $user): WishlistInterface
diff --git a/src/Resolver/TokenUserResolver.php b/src/Resolver/TokenUserResolver.php
index e35a1f18..82779d20 100644
--- a/src/Resolver/TokenUserResolver.php
+++ b/src/Resolver/TokenUserResolver.php
@@ -10,6 +10,7 @@
namespace BitBag\SyliusWishlistPlugin\Resolver;
+use BitBag\SyliusWishlistPlugin\Util\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
@@ -17,12 +18,12 @@ final class TokenUserResolver implements TokenUserResolverInterface
{
public function resolve(?TokenInterface $token): ?UserInterface
{
- if ($token === null) {
+ if (null === $token) {
return null;
}
$user = $token->getUser();
- if (is_string($user) && $user === 'anon.') {
+ if (is_string($user) && User::SYMFONY_5_ANON_USER === $user) {
return null;
}
diff --git a/src/Resolver/VariantImageToDataUriResolver.php b/src/Resolver/VariantImageToDataUriResolver.php
index 53338271..4fecaa3b 100644
--- a/src/Resolver/VariantImageToDataUriResolver.php
+++ b/src/Resolver/VariantImageToDataUriResolver.php
@@ -14,11 +14,9 @@
final class VariantImageToDataUriResolver implements VariantImageToDataUriResolverInterface
{
- private GenerateDataUriForImageResolverInterface $dataUriForImageResolver;
-
- public function __construct(GenerateDataUriForImageResolverInterface $dataUriForImageResolver)
- {
- $this->dataUriForImageResolver = $dataUriForImageResolver;
+ public function __construct(
+ private GenerateDataUriForImageResolverInterface $dataUriForImageResolver
+ ) {
}
public function resolve(ProductVariantInterface $variant, string $baseUrl): string
@@ -31,7 +29,7 @@ public function resolve(ProductVariantInterface $variant, string $baseUrl): stri
$fileExt = explode('.', $image->getPath());
- if ($fileExt[1] === "svg") {
+ if ('svg' === $fileExt[1]) {
return $this->dataUriForImageResolver->resolveWithNoImage();
}
diff --git a/src/Resolver/WishlistCookieTokenResolver.php b/src/Resolver/WishlistCookieTokenResolver.php
index ec93ebaf..dc5e313f 100644
--- a/src/Resolver/WishlistCookieTokenResolver.php
+++ b/src/Resolver/WishlistCookieTokenResolver.php
@@ -16,16 +16,10 @@
final class WishlistCookieTokenResolver implements WishlistCookieTokenResolverInterface
{
- private RequestStack $requestStack;
-
- private string $wishlistCookieToken;
-
public function __construct(
- RequestStack $requestStack,
- string $wishlistCookieToken
+ private RequestStack $requestStack,
+ private string $wishlistCookieToken
) {
- $this->requestStack = $requestStack;
- $this->wishlistCookieToken = $wishlistCookieToken;
}
public function resolve(): string
diff --git a/src/Resolver/WishlistsResolver.php b/src/Resolver/WishlistsResolver.php
index 28729ef0..10dfe6a5 100644
--- a/src/Resolver/WishlistsResolver.php
+++ b/src/Resolver/WishlistsResolver.php
@@ -10,7 +10,6 @@
namespace BitBag\SyliusWishlistPlugin\Resolver;
-use BitBag\SyliusWishlistPlugin\Command\Wishlist\CreateNewWishlist;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\CreateWishlist;
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface;
@@ -18,7 +17,6 @@
use Sylius\Component\Channel\Context\ChannelNotFoundException;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
-use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\Messenger\HandleTrait;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -27,30 +25,15 @@ final class WishlistsResolver implements WishlistsResolverInterface
{
use HandleTrait;
- private WishlistRepositoryInterface $wishlistRepository;
-
- private TokenStorageInterface $tokenStorage;
-
- private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver;
-
- private ChannelContextInterface $channelContext;
-
- private TokenUserResolverInterface $tokenUserResolver;
-
public function __construct(
- WishlistRepositoryInterface $wishlistRepository,
- TokenStorageInterface $tokenStorage,
- WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
- ChannelContextInterface $channelContext,
- MessageBusInterface $messageBus,
- TokenUserResolverInterface $tokenUserResolver,
+ private WishlistRepositoryInterface $wishlistRepository,
+ private TokenStorageInterface $tokenStorage,
+ private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
+ private ChannelContextInterface $channelContext,
+ private TokenUserResolverInterface $tokenUserResolver,
+ MessageBusInterface $messageBus
) {
- $this->wishlistRepository = $wishlistRepository;
- $this->tokenStorage = $tokenStorage;
- $this->wishlistCookieTokenResolver = $wishlistCookieTokenResolver;
- $this->channelContext = $channelContext;
$this->messageBus = $messageBus;
- $this->tokenUserResolver = $tokenUserResolver;
}
public function resolve(): array
diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml
index 358ac564..4950453c 100644
--- a/src/Resources/config/services.yml
+++ b/src/Resources/config/services.yml
@@ -118,11 +118,11 @@ services:
- '@sylius.context.cart.new_shop_based.inner'
- '@form.factory'
- '@request_stack'
- - "@sylius.command_bus"
- "@bitbag_sylius_wishlist_plugin.processor.wishlist_command_processor"
- "@router"
- "@translator"
- "@bitbag_sylius_wishlist_plugin.repository.wishlist"
+ - "@sylius.command_bus"
tags:
- { name: controller.service_arguments }
@@ -131,9 +131,9 @@ services:
arguments:
- "@form.factory"
- '@request_stack'
- - "@sylius.command_bus"
- "@twig"
- "@bitbag_sylius_wishlist_plugin.resolver.wishlists_resolver"
+ - "@sylius.command_bus"
tags:
- { name: controller.service_arguments }
diff --git a/src/Resources/config/services/resolver.yml b/src/Resources/config/services/resolver.yml
index 713faf07..87f8897b 100644
--- a/src/Resources/config/services/resolver.yml
+++ b/src/Resources/config/services/resolver.yml
@@ -13,8 +13,8 @@ services:
- "@security.token_storage"
- "@bitbag_sylius_wishlist_plugin.resolver.wishlist_cookie_token_resolver"
- "@sylius.context.channel"
- - "@sylius.command_bus"
- "@bitbag_sylius_wishlist_plugin.resolver.token_user_resolver"
+ - "@sylius.command_bus"
bitbag_sylius_wishlist_plugin.resolver.wishlist_cookie_token_resolver:
class: BitBag\SyliusWishlistPlugin\Resolver\WishlistCookieTokenResolver
diff --git a/src/Services/Exporter/DomPdfWishlistExporter.php b/src/Services/Exporter/DomPdfWishlistExporter.php
index 409e603f..2d80cd29 100644
--- a/src/Services/Exporter/DomPdfWishlistExporter.php
+++ b/src/Services/Exporter/DomPdfWishlistExporter.php
@@ -17,16 +17,10 @@
final class DomPdfWishlistExporter implements DomPdfWishlistExporterInterface
{
- private Environment $twigEnvironment;
-
- private DomPdfFactoryInterface $domPdfFactory;
-
public function __construct(
- Environment $twigEnvironment,
- DomPdfFactoryInterface $domPdfFactory
+ private Environment $twigEnvironment,
+ private DomPdfFactoryInterface $domPdfFactory
) {
- $this->twigEnvironment = $twigEnvironment;
- $this->domPdfFactory = $domPdfFactory;
}
public function export(Collection $data): void
diff --git a/src/Services/Exporter/WishlistToPdfExporter.php b/src/Services/Exporter/WishlistToPdfExporter.php
index 5ce36165..7c409c14 100644
--- a/src/Services/Exporter/WishlistToPdfExporter.php
+++ b/src/Services/Exporter/WishlistToPdfExporter.php
@@ -15,16 +15,10 @@
final class WishlistToPdfExporter implements WishlistToPdfExporterInterface
{
- private VariantPdfModelProcessorInterface $variantPdfModelProcessor;
-
- private DomPdfWishlistExporterInterface $domPdfWishlistExporter;
-
public function __construct(
- VariantPdfModelProcessorInterface $variantPdfModelProcessor,
- DomPdfWishlistExporterInterface $domPdfWishlistExporter
+ private VariantPdfModelProcessorInterface $variantPdfModelProcessor,
+ private DomPdfWishlistExporterInterface $domPdfWishlistExporter
) {
- $this->variantPdfModelProcessor = $variantPdfModelProcessor;
- $this->domPdfWishlistExporter = $domPdfWishlistExporter;
}
public function createModelToPdfAndExportToPdf(Collection $wishlistProducts): void
diff --git a/src/Services/Generator/ModelCreator.php b/src/Services/Generator/ModelCreator.php
index da4a1a1c..58416080 100644
--- a/src/Services/Generator/ModelCreator.php
+++ b/src/Services/Generator/ModelCreator.php
@@ -18,25 +18,16 @@
final class ModelCreator implements ModelCreatorInterface
{
- private VariantImageToDataUriResolverInterface $variantImageToDataUriResolver;
-
- private VariantPdfModelFactoryInterface $variantPdfModelFactory;
-
- private RequestStack $requestStack;
-
public function __construct(
- VariantImageToDataUriResolverInterface $variantImageToDataUriResolver,
- VariantPdfModelFactoryInterface $variantPdfModelFactory,
- RequestStack $requestStack
+ private VariantImageToDataUriResolverInterface $variantImageToDataUriResolver,
+ private VariantPdfModelFactoryInterface $variantPdfModelFactory,
+ private RequestStack $requestStack
) {
- $this->variantImageToDataUriResolver = $variantImageToDataUriResolver;
- $this->variantPdfModelFactory = $variantPdfModelFactory;
- $this->requestStack = $requestStack;
}
- public function createWishlistItemToPdf(WishlistItemInterface $wishlistProduct): VariantPdfModelInterface
+ public function createWishlistItemToPdf(WishlistItemInterface $wishlistItem): VariantPdfModelInterface
{
- $cartItem = $wishlistProduct->getCartItem()->getCartItem();
+ $cartItem = $wishlistItem->getCartItem()->getCartItem();
$variant = $cartItem->getVariant();
$quantity = $cartItem->getQuantity();
$baseUrl = $this->requestStack->getCurrentRequest()->getSchemeAndHttpHost();
diff --git a/src/Services/Generator/ModelCreatorInterface.php b/src/Services/Generator/ModelCreatorInterface.php
index a96dc2e4..51e2cc50 100644
--- a/src/Services/Generator/ModelCreatorInterface.php
+++ b/src/Services/Generator/ModelCreatorInterface.php
@@ -15,5 +15,5 @@
interface ModelCreatorInterface
{
- public function createWishlistItemToPdf(WishlistItemInterface $wishlistProduct): VariantPdfModelInterface;
+ public function createWishlistItemToPdf(WishlistItemInterface $wishlistItem): VariantPdfModelInterface;
}
diff --git a/src/Twig/WishlistExtension.php b/src/Twig/WishlistExtension.php
index da5832c0..2675dc40 100644
--- a/src/Twig/WishlistExtension.php
+++ b/src/Twig/WishlistExtension.php
@@ -23,16 +23,10 @@
class WishlistExtension extends AbstractExtension
{
- private WishlistRepositoryInterface $wishlistRepository;
-
- private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver;
-
public function __construct(
- WishlistRepositoryInterface $wishlistRepository,
- WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver
+ private WishlistRepositoryInterface $wishlistRepository,
+ private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver
) {
- $this->wishlistRepository = $wishlistRepository;
- $this->wishlistCookieTokenResolver = $wishlistCookieTokenResolver;
}
public function getFunctions(): array
diff --git a/src/Util/User.php b/src/Util/User.php
new file mode 100644
index 00000000..667fbf6a
--- /dev/null
+++ b/src/Util/User.php
@@ -0,0 +1,16 @@
+security = $security;
+ public function __construct(
+ private Security $security
+ ) {
}
protected function supports($attribute, $subject): bool
diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php
index 4ea3be00..1e1ef827 100755
--- a/tests/Application/Kernel.php
+++ b/tests/Application/Kernel.php
@@ -58,11 +58,18 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir() . '/config';
+ $syliusDir = $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION;
$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');
+ if (is_dir($syliusDir)) {
+ $loader->load($syliusDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
+ $loader->load($syliusDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
+ $loader->load($syliusDir . '/{services}' . self::CONFIG_EXTS, 'glob');
+ $loader->load($syliusDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
+ }
$loader->load($confDir . '/{api_resources}/*' . self::CONFIG_EXTS, 'glob');
}
diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php
index c1cc24e5..b0f13b83 100755
--- a/tests/Application/config/bundles.php
+++ b/tests/Application/config/bundles.php
@@ -51,6 +51,8 @@
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],
+ Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
+ Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Sylius\Behat\Application\SyliusTestPlugin\SyliusTestPlugin::class => ['test' => true, 'test_cached' => true],
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => 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/security.yaml b/tests/Application/config/sylius/1.11/packages/security.yaml
deleted file mode 100644
index 10628102..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-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.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/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml
deleted file mode 100644
index cf16fdfe..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"
\ No newline at end of file
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 cf16fdfe..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"
\ No newline at end of file
diff --git a/tests/Application/config/sylius/1.12/packages/security.yaml b/tests/Application/config/sylius/1.12/packages/security.yaml
index 10628102..4ed342f8 100644
--- a/tests/Application/config/sylius/1.12/packages/security.yaml
+++ b/tests/Application/config/sylius/1.12/packages/security.yaml
@@ -1,16 +1,5 @@
-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
+ enable_authenticator_manager: true
providers:
sylius_admin_user_provider:
id: sylius.admin_user_provider.email_or_name_based
@@ -20,11 +9,8 @@ security:
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:
+ password_hashers:
Sylius\Component\User\Model\UserInterface: argon2i
firewalls:
admin:
@@ -40,7 +26,7 @@ security:
default_target_path: sylius_admin_dashboard
use_forward: false
use_referer: true
- csrf_token_generator: security.csrf.token_manager
+ enable_csrf: true
csrf_parameter: _csrf_admin_security_token
csrf_token_id: admin_authenticate
remember_me:
@@ -52,46 +38,32 @@ security:
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
+ pattern: "%sylius.security.new_api_admin_regex%/.*"
+ provider: sylius_api_admin_user_provider
stateless: true
- anonymous: true
+ entry_point: jwt
json_login:
- check_path: "%sylius.security.new_api_route%/admin-user-authentication-token"
+ check_path: "%sylius.security.new_api_admin_route%/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
+ jwt: true
new_api_shop_user:
- pattern: "%sylius.security.new_api_route%/shop-user-authentication-token"
- provider: sylius_shop_user_provider
+ pattern: "%sylius.security.new_api_shop_regex%/.*"
+ provider: sylius_api_shop_user_provider
stateless: true
- anonymous: true
+ entry_point: jwt
json_login:
- check_path: "%sylius.security.new_api_route%/shop-user-authentication-token"
+ check_path: "%sylius.security.new_api_shop_route%/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
+ jwt: true
shop:
switch_user: { role: ROLE_ALLOWED_TO_SWITCH }
@@ -108,7 +80,7 @@ security:
default_target_path: sylius_shop_homepage
use_forward: false
use_referer: true
- csrf_token_generator: security.csrf.token_manager
+ enable_csrf: true
csrf_parameter: _csrf_shop_security_token
csrf_token_id: shop_authenticate
remember_me:
@@ -118,31 +90,35 @@ security:
remember_me_parameter: _remember_me
logout:
path: sylius_shop_logout
- target: sylius_shop_login
+ target: sylius_shop_homepage
invalidate_session: false
- success_handler: sylius.handler.shop_user_logout
- anonymous: true
dev:
- pattern: ^/(_(profiler|wdt)|css|images|js)/
+ 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: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
+ - { 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: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
+ - { 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: 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.admin_regex%/login", role: PUBLIC_ACCESS }
+ - { path: "%sylius.security.shop_regex%/login", role: PUBLIC_ACCESS }
- - { path: "%sylius.security.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: "%sylius.security.shop_regex%/verify", role: IS_AUTHENTICATED_ANONYMOUSLY }
+ - { 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.api_regex%/.*", role: ROLE_API_ACCESS }
- { path: "%sylius.security.shop_regex%/account", role: ROLE_USER }
+ - { path: "%sylius.security.new_api_admin_route%/reset-password-requests", role: PUBLIC_ACCESS }
- { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS }
- - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY }
+ - { path: "%sylius.security.new_api_admin_route%/authentication-token", role: PUBLIC_ACCESS }
+ - { path: "%sylius.security.new_api_user_account_regex%/.*", role: ROLE_USER }
+ - { path: "%sylius.security.new_api_shop_route%/authentication-token", role: PUBLIC_ACCESS }
+ - { path: "%sylius.security.new_api_shop_regex%/.*", role: PUBLIC_ACCESS }
diff --git a/tests/Application/config/sylius/1.11/bundles.php b/tests/Application/config/sylius/1.13/bundles.php
similarity index 68%
rename from tests/Application/config/sylius/1.11/bundles.php
rename to tests/Application/config/sylius/1.13/bundles.php
index 7109dc23..b0560bca 100644
--- a/tests/Application/config/sylius/1.11/bundles.php
+++ b/tests/Application/config/sylius/1.13/bundles.php
@@ -3,5 +3,5 @@
return [
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
- Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
+ Sylius\Abstraction\StateMachine\SyliusStateMachineAbstractionBundle::class => ['all' => true],
];
diff --git a/tests/Application/config/sylius/1.13/packages/_sylius.yaml b/tests/Application/config/sylius/1.13/packages/_sylius.yaml
new file mode 100644
index 00000000..76aa43aa
--- /dev/null
+++ b/tests/Application/config/sylius/1.13/packages/_sylius.yaml
@@ -0,0 +1,7 @@
+parameters:
+ test_default_state_machine_adapter: 'symfony_workflow'
+ test_sylius_state_machine_adapter: '%env(string:default:test_default_state_machine_adapter:TEST_SYLIUS_STATE_MACHINE_ADAPTER)%'
+
+sylius_state_machine_abstraction:
+ graphs_to_adapters_mapping:
+ sylius_refund_refund_payment: '%test_sylius_state_machine_adapter%'
diff --git a/tests/Application/config/packages/security.yaml b/tests/Application/config/sylius/1.13/packages/security.yaml
similarity index 93%
rename from tests/Application/config/packages/security.yaml
rename to tests/Application/config/sylius/1.13/packages/security.yaml
index 4ed342f8..c81f04ba 100644
--- a/tests/Application/config/packages/security.yaml
+++ b/tests/Application/config/sylius/1.13/packages/security.yaml
@@ -45,7 +45,7 @@ security:
stateless: true
entry_point: jwt
json_login:
- check_path: "%sylius.security.new_api_admin_route%/authentication-token"
+ check_path: "%sylius.security.new_api_admin_route%/administrators/token"
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
@@ -58,7 +58,7 @@ security:
stateless: true
entry_point: jwt
json_login:
- check_path: "%sylius.security.new_api_shop_route%/authentication-token"
+ check_path: "%sylius.security.new_api_shop_route%/customers/token"
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
@@ -116,9 +116,9 @@ security:
- { 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%/reset-password-requests", role: PUBLIC_ACCESS }
+ - { 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%/authentication-token", role: PUBLIC_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%/authentication-token", role: PUBLIC_ACCESS }
+ - { path: "%sylius.security.new_api_shop_route%/customers/token", role: PUBLIC_ACCESS }
- { path: "%sylius.security.new_api_shop_regex%/.*", role: PUBLIC_ACCESS }
diff --git a/tests/Application/package.json.~1.11.0.dist b/tests/Application/package.json.~1.13.0.dist
similarity index 97%
rename from tests/Application/package.json.~1.11.0.dist
rename to tests/Application/package.json.~1.13.0.dist
index 9ca35627..36e6c1f0 100755
--- a/tests/Application/package.json.~1.11.0.dist
+++ b/tests/Application/package.json.~1.13.0.dist
@@ -1,7 +1,7 @@
{
"dependencies": {
"@babel/polyfill": "^7.0.0",
- "chart.js": "^2.9.3",
+ "chart.js": "^3.7.1",
"jquery": "^3.5.0",
"jquery.dirtyforms": "^2.0.0",
"lightbox2": "^2.9.0",
diff --git a/tests/Functional/Api/WishlistTest.php b/tests/Functional/Api/WishlistTest.php
new file mode 100644
index 00000000..7640de74
--- /dev/null
+++ b/tests/Functional/Api/WishlistTest.php
@@ -0,0 +1,195 @@
+entityManager = static::getContainer()->get('doctrine.orm.entity_manager');
+ $this->wishlistRepository = $this->entityManager->getRepository(Wishlist::class);
+
+ $this->fixturesData = $this->loadFixturesFromFile('Api/WishlistTest/wishlist.yaml');
+ }
+
+ public function test_user_can_create_wishlist(): void
+ {
+ $header = $this->getHeaderForLoginShopUser('oliver@queen.com');
+
+ $this->client->request('POST', '/api/v2/shop/wishlists', [], [], $header, json_encode([
+ 'tokenValue' => 'token',
+ 'channelCode' => 'US',
+ ]));
+
+ $response = $this->client->getResponse();
+
+ $this->assertResponse($response, $this->getResponseDirectory('test_user_can_create_wishlist'), Response::HTTP_CREATED);
+ }
+
+ public function test_admin_can_get_wishlists(): void
+ {
+ $header = $this->getHeaderForLoginAdminUser('admin@example.com');
+
+ $this->client->request('GET', '/api/v2/admin/wishlists', [], [], $header);
+
+ $response = $this->client->getResponse();
+
+ $this->assertResponse($response, $this->getResponseDirectory('test_admin_can_get_wishlists'), Response::HTTP_OK);
+ }
+
+ public function test_user_can_get_wishlist_items(): void
+ {
+ $header = $this->getHeaderForLoginShopUser('oliver@queen.com');
+ /** @var WishlistInterface $wishlist */
+ $wishlist = $this->fixturesData['olivier_wishlist'];
+ $token = $wishlist->getToken();
+
+ $this->client->request('GET', '/api/v2/shop/wishlists/' . $token, [], [], $header);
+
+ $response = $this->client->getResponse();
+ $this->assertResponse($response, $this->getResponseDirectory('test_user_can_get_wishlist_items'), Response::HTTP_OK);
+ }
+
+ public function test_user_can_add_product_to_wishlist(): void
+ {
+ $header = $this->getHeaderForLoginShopUser('oliver@queen.com');
+ $header['CONTENT_TYPE'] = self::PATCH_TYPE;
+ /** @var WishlistInterface $wishlist */
+ $wishlist = $this->fixturesData['empty_olivier_wishlist'];
+ $token = $wishlist->getToken();
+ /** @var ProductInterface $product */
+ $product = $this->fixturesData['product_1'];
+
+ $this->assertCount(0, $wishlist->getWishlistProducts());
+ $this->client->request('PATCH', '/api/v2/shop/wishlists/' . $token . '/product', [], [], $header, json_encode([
+ 'productId' => $product->getId(),
+ 'wishlist' => $wishlist,
+ ]));
+
+ $response = $this->client->getResponse();
+
+ /** @var ?WishlistInterface $updatedWishlist */
+ $updatedWishlist = $this->wishlistRepository->findOneByToken($token);
+
+ $this->assertNotNull($updatedWishlist);
+ $this->assertCount(1, $updatedWishlist->getWishlistProducts());
+ $this->assertResponse($response, $this->getResponseDirectory('test_user_can_add_product_to_wishlist'), Response::HTTP_OK);
+ }
+
+ public function test_user_can_add_variant_to_wishlist(): void
+ {
+ $header = $this->getHeaderForLoginShopUser('oliver@queen.com');
+ $header['CONTENT_TYPE'] = self::PATCH_TYPE;
+ /** @var WishlistInterface $wishlist */
+ $wishlist = $this->fixturesData['empty_olivier_wishlist'];
+ $token = $wishlist->getToken();
+ /** @var ProductVariantInterface $productVariant */
+ $productVariant = $this->fixturesData['product_variant_1'];
+
+ $this->assertCount(0, $wishlist->getWishlistProducts());
+ $this->client->request('PATCH', '/api/v2/shop/wishlists/' . $token . '/variant', [], [], $header, json_encode([
+ 'productVariantId' => $productVariant->getId(),
+ 'wishlist' => $wishlist,
+ ]));
+
+ $response = $this->client->getResponse();
+
+ /** @var ?WishlistInterface $updatedWishlist */
+ $updatedWishlist = $this->wishlistRepository->findOneByToken($token);
+
+ $this->assertNotNull($updatedWishlist);
+ $this->assertCount(1, $updatedWishlist->getWishlistProducts());
+ $this->assertResponse($response, $this->getResponseDirectory('test_user_can_add_product_variant_to_wishlist'), Response::HTTP_OK);
+ }
+
+ public function test_user_can_delete_product_from_wishlist(): void
+ {
+ $header = $this->getHeaderForLoginShopUser('oliver@queen.com');
+ /** @var WishlistInterface $wishlist */
+ $wishlist = $this->fixturesData['olivier_wishlist'];
+ $token = $wishlist->getToken();
+ /** @var WishlistInterface $wishlist */
+ $wishlist = $this->wishlistRepository->findOneByToken($token);
+ /** @var ProductInterface $product */
+ $product = $this->fixturesData['product_1'];
+
+ $this->assertCount(1, $wishlist->getWishlistProducts());
+ $this->client->request('DELETE', '/api/v2/shop/wishlists/' . $token . '/products/' . $product->getId(), [], [], $header);
+
+ $response = $this->client->getResponse();
+
+ /** @var ?WishlistInterface $updatedWishlist */
+ $updatedWishlist = $this->wishlistRepository->findOneByToken($token);
+
+ $this->assertNotNull($updatedWishlist);
+ $this->assertCount(0, $updatedWishlist->getWishlistProducts());
+ $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
+ }
+
+ public function test_user_can_delete_product_variant_from_wishlist(): void
+ {
+ $header = $this->getHeaderForLoginShopUser('oliver@queen.com');
+ /** @var WishlistInterface $wishlist */
+ $wishlist = $this->fixturesData['olivier_wishlist'];
+ $token = $wishlist->getToken();
+ /** @var WishlistInterface $wishlist */
+ $wishlist = $this->wishlistRepository->findOneByToken($token);
+ /** @var ProductVariantInterface $productVariant */
+ $productVariant = $this->fixturesData['product_variant_1'];
+
+ $this->assertCount(1, $wishlist->getWishlistProducts());
+ $this->client->request('DELETE', '/api/v2/shop/wishlists/' . $token . '/productVariants/' . $productVariant->getId(), [], [], $header);
+
+ $response = $this->client->getResponse();
+
+ /** @var ?WishlistInterface $updatedWishlist */
+ $updatedWishlist = $this->wishlistRepository->findOneByToken($token);
+
+ $this->assertNotNull($updatedWishlist);
+ $this->assertCount(0, $updatedWishlist->getWishlistProducts());
+ $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
+ }
+
+ public function test_user_can_delete_wishlist_with_token(): void
+ {
+ $header = $this->getHeaderForLoginShopUser('oliver@queen.com');
+ /** @var WishlistInterface $wishlist */
+ $wishlist = $this->fixturesData['olivier_wishlist'];
+ $token = $wishlist->getToken();
+
+ $this->assertNotNull($wishlist);
+ $this->client->request('DELETE', '/api/v2/shop/wishlists/' . $token, [], [], $header);
+
+ $response = $this->client->getResponse();
+
+ /** @var ?WishlistInterface $updatedWishlist */
+ $updatedWishlist = $this->wishlistRepository->findOneByToken($token);
+
+ $this->assertNull($updatedWishlist);
+ $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
+ }
+
+ private function getResponseDirectory(string $filename): string
+ {
+ return 'Api/WishlistTest/' . $this->getSyliusVersion() . '/' . $filename;
+ }
+}
diff --git a/tests/Functional/DataFixtures/ORM/Api/WishlistTest/wishlist.yaml b/tests/Functional/DataFixtures/ORM/Api/WishlistTest/wishlist.yaml
new file mode 100644
index 00000000..093787b1
--- /dev/null
+++ b/tests/Functional/DataFixtures/ORM/Api/WishlistTest/wishlist.yaml
@@ -0,0 +1,97 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+Sylius\Component\Core\Model\AdminUser:
+ test_admin:
+ enabled: true
+ username: "Admin"
+ firstName: "Admin"
+ lastName: "Admin"
+ email: "admin@example.com"
+ emailCanonical: "admin@example.com"
+ localeCode: 'en_US'
+ roles: ["ROLE_ADMINISTRATION_ACCESS","ROLE_API_ACCESS"]
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: 'John'
+ lastName: 'Nowak'
+ email: 'oliver@queen.com'
+ emailCanonical: 'test2@example.com'
+ customer_bruce:
+ firstName: 'Bruce'
+ lastName: 'Wayne'
+ email: 'bruce@wayne.com'
+ emailCanonical: 'test@example.com'
+Sylius\Component\Core\Model\ShopUser:
+ user_oliver:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_oliver'
+ username: 'oliver@queen.com'
+ usernameCanonical: 'oliver@queen.com'
+ user_bruce:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_bruce'
+ username: 'bruce@wayne.com'
+ usernameCanonical: 'bruce@wayne.com'
+Sylius\Component\Core\Model\Product:
+ product_{1..10}:
+ code: 'product__code'
+ enabled: true
+Sylius\Component\Core\Model\ProductTranslation:
+ product_translation_en_{1..10}:
+ translatable: '@product_'
+ name: ''
+ description: ''
+ shortDescription: ''
+ slug: ''
+ locale: 'en'
+Sylius\Component\Core\Model\ProductVariant:
+ product_variant_{1..10}:
+ code: 'product_variant__code'
+ product: '@product_'
+Sylius\Component\Product\Model\ProductVariantTranslation:
+ product_variant_translation_en_{1..10}:
+ translatable: '@product_variant_'
+ name: ''
+ locale: 'en'
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ olivier_wishlist:
+ name: 'Olivier Wishlist'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+ olivier_wishlist2:
+ name: 'Olivier Wishlist 2'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+ empty_olivier_wishlist:
+ name: 'Empty Olivier Wishlist'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+ bruce_wishlist:
+ name: 'Bruce Wishlist'
+ shopUser: '@user_bruce'
+ channel: '@channel_us'
+BitBag\SyliusWishlistPlugin\Entity\WishlistProduct:
+ wishlist_product_1:
+ wishlist: '@olivier_wishlist'
+ product: '@product_1'
+ variant: '@product_variant_1'
+ quantity: ''
+
diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/FunctionalTestCase.php
new file mode 100644
index 00000000..bdca74be
--- /dev/null
+++ b/tests/Functional/FunctionalTestCase.php
@@ -0,0 +1,67 @@
+dataFixturesPath = __DIR__ . \DIRECTORY_SEPARATOR . 'DataFixtures' . \DIRECTORY_SEPARATOR . 'ORM';
+ $this->expectedResponsesPath = __DIR__ . \DIRECTORY_SEPARATOR . 'Responses' . \DIRECTORY_SEPARATOR . 'Expected';
+ }
+
+ protected function getHeaderForLoginShopUser(string $email): array
+ {
+ $loginData = $this->logInShopUser($email);
+
+ if (is_array($loginData)) {
+ return array_merge($loginData, self::CONTENT_TYPE_HEADER);
+ }
+
+ $authorizationHeader = self::getContainer()->getParameter('sylius.api.authorization_header');
+ $header['HTTP_' . $authorizationHeader] = 'Bearer ' . $loginData;
+
+ return array_merge($header, self::CONTENT_TYPE_HEADER);
+ }
+
+ protected function getHeaderForLoginAdminUser(string $email): array
+ {
+ $loginData = $this->logInAdminUser($email);
+
+ if (is_array($loginData)) {
+ return array_merge($loginData, self::CONTENT_TYPE_HEADER);
+ }
+
+ $authorizationHeader = self::getContainer()->getParameter('sylius.api.authorization_header');
+ $header['HTTP_' . $authorizationHeader] = 'Bearer ' . $loginData;
+
+ return array_merge($header, self::CONTENT_TYPE_HEADER);
+ }
+
+ protected function getSyliusVersion(): string
+ {
+ return SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION;
+ }
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_admin_can_get_wishlists.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_admin_can_get_wishlists.json
new file mode 100644
index 00000000..303b0c98
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_admin_can_get_wishlists.json
@@ -0,0 +1,73 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/admin\/wishlists",
+ "@type":"hydra:Collection",
+ "hydra:member":[
+ {
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+ {
+ "@type":"WishlistProduct",
+ "product":{
+ "@id":"\/api\/v2\/admin\/products\/@string@",
+ "@type":"Product",
+ "id":"@integer@"
+ },
+ "variant":{
+ "@id":"\/api\/v2\/admin\/product-variants\/@string@",
+ "@type":"ProductVariant",
+ "id":"@integer@"
+ },
+ "quantity":"@integer@"
+ }
+ ],
+ "shopUser":{
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+ },
+ {
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":"@array@",
+ "shopUser":{
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+ },
+ {
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+
+ ],
+ "shopUser":{
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+ },
+ {
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":"@array@",
+ "shopUser":{
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+ }
+ ],
+ "hydra:totalItems":"@integer@"
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_add_product_to_wishlist.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_add_product_to_wishlist.json
new file mode 100644
index 00000000..db64b25b
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_add_product_to_wishlist.json
@@ -0,0 +1,29 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+ {
+ "@type":"WishlistProduct",
+ "product":{
+ "@id":"\/api\/v2\/shop\/products\/@string@",
+ "@type":"Product",
+ "id":"@integer@"
+ },
+ "variant":{
+ "@id":"\/api\/v2\/shop\/product-variants\/@string@",
+ "@type":"ProductVariant",
+ "id":"@integer@",
+ "inStock":true
+ },
+ "quantity":"@integer@"
+ }
+ ],
+ "shopUser":{
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_add_product_variant_to_wishlist.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_add_product_variant_to_wishlist.json
new file mode 100644
index 00000000..db64b25b
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_add_product_variant_to_wishlist.json
@@ -0,0 +1,29 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+ {
+ "@type":"WishlistProduct",
+ "product":{
+ "@id":"\/api\/v2\/shop\/products\/@string@",
+ "@type":"Product",
+ "id":"@integer@"
+ },
+ "variant":{
+ "@id":"\/api\/v2\/shop\/product-variants\/@string@",
+ "@type":"ProductVariant",
+ "id":"@integer@",
+ "inStock":true
+ },
+ "quantity":"@integer@"
+ }
+ ],
+ "shopUser":{
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_create_wishlist.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_create_wishlist.json
new file mode 100644
index 00000000..9ec800c2
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_create_wishlist.json
@@ -0,0 +1,13 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":"@array@",
+ "shopUser": {
+ "@type": "ShopUser",
+ "id":"@integer@",
+ "email": "@string@"
+ },
+ "token":"@string@"
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_get_wishlist_items.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_get_wishlist_items.json
new file mode 100644
index 00000000..40238f4a
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.12/test_user_can_get_wishlist_items.json
@@ -0,0 +1,33 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+ {
+ "@type":"WishlistProduct",
+ "product":{
+ "@id":"\/api\/v2\/shop\/products\/@string@",
+ "@type":"Product",
+ "id":"@integer@",
+ "variants":[
+ "\/api\/v2\/shop\/product-variants\/@string@"
+ ],
+ "defaultVariant":"\/api\/v2\/shop\/product-variants\/@string@"
+ },
+ "variant":{
+ "@id":"\/api\/v2\/shop\/product-variants\/@string@",
+ "@type":"ProductVariant",
+ "id":"@integer@",
+ "inStock":true
+ },
+ "quantity":"@integer@"
+ }
+ ],
+ "shopUser":{
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_admin_can_get_wishlists.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_admin_can_get_wishlists.json
new file mode 100644
index 00000000..1aba5098
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_admin_can_get_wishlists.json
@@ -0,0 +1,77 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/admin\/wishlists",
+ "@type":"hydra:Collection",
+ "hydra:member":[
+ {
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+ {
+ "@type":"WishlistProduct",
+ "product":{
+ "@id":"\/api\/v2\/admin\/products\/@string@",
+ "@type":"Product",
+ "id":"@integer@"
+ },
+ "variant":{
+ "@id":"\/api\/v2\/admin\/product-variants\/@string@",
+ "@type":"ProductVariant",
+ "id":"@integer@"
+ },
+ "quantity":"@integer@"
+ }
+ ],
+ "shopUser":{
+ "@id": "\/api\/v2\/admin\/shop-users\/@integer@",
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+ },
+ {
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":"@array@",
+ "shopUser":{
+ "@id": "\/api\/v2\/admin\/shop-users\/@integer@",
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+ },
+ {
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+
+ ],
+ "shopUser":{
+ "@id": "\/api\/v2\/admin\/shop-users\/@integer@",
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+ },
+ {
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":"@array@",
+ "shopUser":{
+ "@id": "\/api\/v2\/admin\/shop-users\/@integer@",
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+ }
+ ],
+ "hydra:totalItems":"@integer@"
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_add_product_to_wishlist.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_add_product_to_wishlist.json
new file mode 100644
index 00000000..6b7d1d13
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_add_product_to_wishlist.json
@@ -0,0 +1,30 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+ {
+ "@type":"WishlistProduct",
+ "product":{
+ "@id":"\/api\/v2\/shop\/products\/@string@",
+ "@type":"Product",
+ "id":"@integer@"
+ },
+ "variant":{
+ "@id":"\/api\/v2\/shop\/product-variants\/@string@",
+ "@type":"ProductVariant",
+ "id":"@integer@",
+ "inStock":true
+ },
+ "quantity":"@integer@"
+ }
+ ],
+ "shopUser":{
+ "@id": "\/api\/v2\/admin\/shop-users\/@integer@",
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_add_product_variant_to_wishlist.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_add_product_variant_to_wishlist.json
new file mode 100644
index 00000000..6b7d1d13
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_add_product_variant_to_wishlist.json
@@ -0,0 +1,30 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+ {
+ "@type":"WishlistProduct",
+ "product":{
+ "@id":"\/api\/v2\/shop\/products\/@string@",
+ "@type":"Product",
+ "id":"@integer@"
+ },
+ "variant":{
+ "@id":"\/api\/v2\/shop\/product-variants\/@string@",
+ "@type":"ProductVariant",
+ "id":"@integer@",
+ "inStock":true
+ },
+ "quantity":"@integer@"
+ }
+ ],
+ "shopUser":{
+ "@id": "\/api\/v2\/admin\/shop-users\/@integer@",
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_create_wishlist.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_create_wishlist.json
new file mode 100644
index 00000000..957d260b
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_create_wishlist.json
@@ -0,0 +1,14 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":"@array@",
+ "shopUser": {
+ "@id": "\/api\/v2\/admin\/shop-users\/@integer@",
+ "@type": "ShopUser",
+ "id":"@integer@",
+ "email": "@string@"
+ },
+ "token":"@string@"
+}
diff --git a/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_get_wishlist_items.json b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_get_wishlist_items.json
new file mode 100644
index 00000000..f0995c24
--- /dev/null
+++ b/tests/Functional/Responses/Expected/Api/WishlistTest/1.13/test_user_can_get_wishlist_items.json
@@ -0,0 +1,34 @@
+{
+ "@context":"\/api\/v2\/contexts\/Wishlist",
+ "@id":"\/api\/v2\/shop\/wishlists\/@string@",
+ "@type":"Wishlist",
+ "id":"@integer@",
+ "wishlistProducts":[
+ {
+ "@type":"WishlistProduct",
+ "product":{
+ "@id":"\/api\/v2\/shop\/products\/@string@",
+ "@type":"Product",
+ "id":"@integer@",
+ "variants":[
+ "\/api\/v2\/shop\/product-variants\/@string@"
+ ],
+ "defaultVariant":"\/api\/v2\/shop\/product-variants\/@string@"
+ },
+ "variant":{
+ "@id":"\/api\/v2\/shop\/product-variants\/@string@",
+ "@type":"ProductVariant",
+ "id":"@integer@",
+ "inStock":true
+ },
+ "quantity":"@integer@"
+ }
+ ],
+ "shopUser":{
+ "@id": "\/api\/v2\/admin\/shop-users\/@integer@",
+ "@type":"ShopUser",
+ "id":"@integer@",
+ "email":"@string@"
+ },
+ "token":"@string@"
+}
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_all_anonymous_wishlists.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_all_anonymous_wishlists.yaml
new file mode 100644
index 00000000..9aec7364
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_all_anonymous_wishlists.yaml
@@ -0,0 +1,45 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: 'John'
+ lastName: 'Nowak'
+ email: 'oliver@queen.com'
+ emailCanonical: 'test2@example.com'
+Sylius\Component\Core\Model\ShopUser:
+ user_oliver:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_oliver'
+ username: 'oliver@queen.com'
+ usernameCanonical: 'oliver@queen.com'
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ wishlist_one:
+ name: 'Wishlist One'
+ channel: '@channel_us'
+ token: 'token'
+ wishlist_two:
+ name: 'Wishlist Two'
+ channel: '@channel_us'
+ token: 'token'
+ olivier_wishlist:
+ name: 'Olivier Wishlist'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+
+
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_all_anonymous_wishlists_with_channel.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_all_anonymous_wishlists_with_channel.yaml
new file mode 100644
index 00000000..9aec7364
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_all_anonymous_wishlists_with_channel.yaml
@@ -0,0 +1,45 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: 'John'
+ lastName: 'Nowak'
+ email: 'oliver@queen.com'
+ emailCanonical: 'test2@example.com'
+Sylius\Component\Core\Model\ShopUser:
+ user_oliver:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_oliver'
+ username: 'oliver@queen.com'
+ usernameCanonical: 'oliver@queen.com'
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ wishlist_one:
+ name: 'Wishlist One'
+ channel: '@channel_us'
+ token: 'token'
+ wishlist_two:
+ name: 'Wishlist Two'
+ channel: '@channel_us'
+ token: 'token'
+ olivier_wishlist:
+ name: 'Olivier Wishlist'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+
+
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_all_wishlists_by_shop_user.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_all_wishlists_by_shop_user.yaml
new file mode 100644
index 00000000..6d4895be
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_all_wishlists_by_shop_user.yaml
@@ -0,0 +1,56 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: 'John'
+ lastName: 'Nowak'
+ email: 'oliver@queen.com'
+ emailCanonical: 'test2@example.com'
+ customer_bruce:
+ firstName: 'Bruce'
+ lastName: 'Wayne'
+ email: 'bruce@wayne.com'
+ emailCanonical: 'test@example.com'
+Sylius\Component\Core\Model\ShopUser:
+ user_oliver:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_oliver'
+ username: 'oliver@queen.com'
+ usernameCanonical: 'oliver@queen.com'
+ user_bruce:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_bruce'
+ username: 'bruce@wayne.com'
+ usernameCanonical: 'bruce@wayne.com'
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ olivier_wishlist:
+ name: 'Olivier Wishlist'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+ olivier_wishlist2:
+ name: 'Olivier Wishlist 2'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+ bruce_wishlist:
+ name: 'Bruce Wishlist'
+ shopUser: '@user_bruce'
+ channel: '@channel_us'
+
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_all_wishlists_by_token.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_all_wishlists_by_token.yaml
new file mode 100644
index 00000000..f854a1b2
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_all_wishlists_by_token.yaml
@@ -0,0 +1,26 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ wishlist_one:
+ name: 'Wishlist One'
+ channel: '@channel_us'
+ token: 'token'
+ wishlist_two:
+ name: 'Wishlist Two'
+ channel: '@channel_us'
+ token: 'token'
+
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user.yaml
new file mode 100644
index 00000000..7d5e3bdc
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user.yaml
@@ -0,0 +1,48 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: 'John'
+ lastName: 'Nowak'
+ email: 'oliver@queen.com'
+ emailCanonical: 'test2@example.com'
+ customer_bruce:
+ firstName: 'Bruce'
+ lastName: 'Wayne'
+ email: 'bruce@wayne.com'
+ emailCanonical: 'test@example.com'
+Sylius\Component\Core\Model\ShopUser:
+ user_oliver:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_oliver'
+ username: 'oliver@queen.com'
+ usernameCanonical: 'oliver@queen.com'
+ user_bruce:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_bruce'
+ username: 'bruce@wayne.com'
+ usernameCanonical: 'bruce@wayne.com'
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ olivier_wishlist:
+ name: 'Olivier Wishlist'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user_and_channel.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user_and_channel.yaml
new file mode 100644
index 00000000..a7616235
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user_and_channel.yaml
@@ -0,0 +1,53 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: 'John'
+ lastName: 'Nowak'
+ email: 'oliver@queen.com'
+ emailCanonical: 'test2@example.com'
+ customer_bruce:
+ firstName: 'Bruce'
+ lastName: 'Wayne'
+ email: 'bruce@wayne.com'
+ emailCanonical: 'test@example.com'
+Sylius\Component\Core\Model\ShopUser:
+ user_oliver:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_oliver'
+ username: 'oliver@queen.com'
+ usernameCanonical: 'oliver@queen.com'
+ user_bruce:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_bruce'
+ username: 'bruce@wayne.com'
+ usernameCanonical: 'bruce@wayne.com'
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ olivier_wishlist:
+ name: 'Olivier Wishlist'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+ bruce_wishlist:
+ name: 'Bruce Wishlist'
+ shopUser: '@user_bruce'
+ channel: '@channel_us'
+
+
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user_and_name.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user_and_name.yaml
new file mode 100644
index 00000000..2aeee011
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user_and_name.yaml
@@ -0,0 +1,49 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: 'John'
+ lastName: 'Nowak'
+ email: 'oliver@queen.com'
+ emailCanonical: 'test2@example.com'
+ customer_bruce:
+ firstName: 'Bruce'
+ lastName: 'Wayne'
+ email: 'bruce@wayne.com'
+ emailCanonical: 'test@example.com'
+Sylius\Component\Core\Model\ShopUser:
+ user_oliver:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_oliver'
+ username: 'oliver@queen.com'
+ usernameCanonical: 'oliver@queen.com'
+ user_bruce:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_bruce'
+ username: 'bruce@wayne.com'
+ usernameCanonical: 'bruce@wayne.com'
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ olivier_wishlist:
+ name: 'Olivier Wishlist'
+ shopUser: '@user_oliver'
+ token: 'token'
+ channel: '@channel_us'
+
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user_and_token.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user_and_token.yaml
new file mode 100644
index 00000000..32aa945c
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_shop_user_and_token.yaml
@@ -0,0 +1,68 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: 'John'
+ lastName: 'Nowak'
+ email: 'oliver@queen.com'
+ emailCanonical: 'test2@example.com'
+ customer_bruce:
+ firstName: 'Bruce'
+ lastName: 'Wayne'
+ email: 'bruce@wayne.com'
+ emailCanonical: 'test@example.com'
+Sylius\Component\Core\Model\ShopUser:
+ user_oliver:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_oliver'
+ username: 'oliver@queen.com'
+ usernameCanonical: 'oliver@queen.com'
+ user_bruce:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_bruce'
+ username: 'bruce@wayne.com'
+ usernameCanonical: 'bruce@wayne.com'
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ olivier_wishlist:
+ name: 'Olivier Wishlist'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+ olivier_wishlist2:
+ name: 'Olivier Wishlist 2'
+ shopUser: '@user_oliver'
+ channel: '@channel_us'
+ olivier_token_wishlist:
+ name: 'Olivier token wishlist'
+ token: 'olivier_token'
+ channel: '@channel_us'
+ olivier_token_wishlist2:
+ name: 'Olivier token wishlist 2'
+ token: 'olivier_token'
+ channel: '@channel_us'
+ bruce_wishlist:
+ name: 'Bruce Wishlist'
+ shopUser: '@user_bruce'
+ channel: '@channel_us'
+ bruce_token_wishlist:
+ name: 'Bruce token wishlist'
+ token: 'bruce_token'
+ channel: '@channel_us'
+
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_token.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_token.yaml
new file mode 100644
index 00000000..f854a1b2
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_token.yaml
@@ -0,0 +1,26 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ wishlist_one:
+ name: 'Wishlist One'
+ channel: '@channel_us'
+ token: 'token'
+ wishlist_two:
+ name: 'Wishlist Two'
+ channel: '@channel_us'
+ token: 'token'
+
diff --git a/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_token_and_name.yaml b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_token_and_name.yaml
new file mode 100644
index 00000000..2aeee011
--- /dev/null
+++ b/tests/Integration/DataFixtures/ORM/test_it_finds_one_wishlist_by_token_and_name.yaml
@@ -0,0 +1,49 @@
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ createdAt: ''
+ code: 'en_US'
+Sylius\Component\Currency\Model\Currency:
+ dollar:
+ code: 'USD'
+Sylius\Component\Core\Model\Channel:
+ channel_us:
+ code: 'US'
+ name: 'name'
+ defaultLocale: '@locale'
+ locales: [ '@locale' ]
+ taxCalculationStrategy: 'order_items_based'
+ baseCurrency: '@dollar'
+ enabled: true
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: 'John'
+ lastName: 'Nowak'
+ email: 'oliver@queen.com'
+ emailCanonical: 'test2@example.com'
+ customer_bruce:
+ firstName: 'Bruce'
+ lastName: 'Wayne'
+ email: 'bruce@wayne.com'
+ emailCanonical: 'test@example.com'
+Sylius\Component\Core\Model\ShopUser:
+ user_oliver:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_oliver'
+ username: 'oliver@queen.com'
+ usernameCanonical: 'oliver@queen.com'
+ user_bruce:
+ plainPassword: '123password'
+ roles: [ 'ROLE_USER' ]
+ enabled: 'true'
+ customer: '@customer_bruce'
+ username: 'bruce@wayne.com'
+ usernameCanonical: 'bruce@wayne.com'
+BitBag\SyliusWishlistPlugin\Entity\Wishlist:
+ olivier_wishlist:
+ name: 'Olivier Wishlist'
+ shopUser: '@user_oliver'
+ token: 'token'
+ channel: '@channel_us'
+
diff --git a/tests/Integration/Repository/WishlistRepositoryTest.php b/tests/Integration/Repository/WishlistRepositoryTest.php
new file mode 100644
index 00000000..e00ed8ec
--- /dev/null
+++ b/tests/Integration/Repository/WishlistRepositoryTest.php
@@ -0,0 +1,184 @@
+entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
+ $this->repository = $this->getContainer()->get('bitbag_sylius_wishlist_plugin.repository.wishlist');
+ }
+
+ public function testItFindsOneWishlistByShopUser(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_one_wishlist_by_shop_user.yaml');
+
+ $shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
+ /** @var ?WishlistInterface $result */
+ $result = $this->repository->findOneByShopUser($shopUser);
+
+ $this->assertNotNull($result);
+ $this->assertCount(1, [$result]);
+ $this->assertSame('Olivier Wishlist', $result->getName());
+ $this->assertSame($shopUser, $result->getShopUser());
+ }
+
+ public function testItFindsOneWishlistByToken(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_one_wishlist_by_token.yaml');
+
+ /** @var ?WishlistInterface $result */
+ $result = $this->repository->findByToken('token');
+
+ $this->assertNotNull($result);
+ $this->assertCount(1, [$result]);
+ $this->assertSame('Wishlist One', $result->getName());
+ }
+
+ public function testItFindsAllWishlistsByToken(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_all_wishlists_by_token.yaml');
+
+ /** @var array $result */
+ $result = $this->repository->findAllByToken('token');
+
+ $this->assertNotNull($result);
+ $this->assertIsArray($result);
+ $this->assertCount(2, $result);
+ $this->assertSame('Wishlist One', $result[0]->getName());
+ $this->assertSame('Wishlist Two', $result[1]->getName());
+ }
+
+ public function testItFindsAllWishlistsByShopUser(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_all_wishlists_by_shop_user.yaml');
+
+ $shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
+ /** @var array $result */
+ $result = $this->repository->findAllByShopUser($shopUser->getId());
+
+ $this->assertNotNull($result);
+ $this->assertIsArray($result);
+ $this->assertCount(2, $result);
+ $this->assertSame('Olivier Wishlist', $result[0]->getName());
+ $this->assertSame('Olivier Wishlist 2', $result[1]->getName());
+ $this->assertSame($shopUser, $result[0]->getShopUser());
+ $this->assertSame($shopUser, $result[1]->getShopUser());
+ }
+
+ public function testItFindsAllWishlistsByShopUserAndToken(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_one_wishlist_by_shop_user_and_token.yaml');
+
+ $shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
+ /** @var array $result */
+ $result = $this->repository->findAllByShopUserAndToken($shopUser->getId(), 'olivier_token');
+
+ $this->assertNotNull($result);
+ $this->assertIsArray($result);
+ $this->assertCount(4, $result);
+ $this->assertSame('Olivier Wishlist', $result[0]->getName());
+ $this->assertSame('Olivier Wishlist 2', $result[1]->getName());
+ $this->assertSame($shopUser, $result[0]->getShopUser());
+ $this->assertSame($shopUser, $result[1]->getShopUser());
+ $this->assertSame('Olivier token wishlist', $result[2]->getName());
+ $this->assertSame('Olivier token wishlist 2', $result[3]->getName());
+ $this->assertSame('olivier_token', $result[3]->getToken());
+ $this->assertSame('olivier_token', $result[3]->getToken());
+ }
+
+ public function testItFindsAllAnonymousWishlists(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_all_anonymous_wishlists.yaml');
+
+ /** @var array $result */
+ $result = $this->repository->findAllByAnonymous('token');
+
+ $this->assertNotNull($result);
+ $this->assertIsArray($result);
+ $this->assertCount(2, $result);
+ $this->assertSame('Wishlist One', $result[0]->getName());
+ $this->assertSame('Wishlist Two', $result[1]->getName());
+ }
+
+ public function testItFindsOneWishlistsByShopUserAndChannel(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_one_wishlist_by_shop_user_and_channel.yaml');
+
+ $shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
+ $channel = $this->entityManager->getRepository(Channel::class)->findOneBy(['name' => 'name']);
+ /** @var ?WishlistInterface $result */
+ $result = $this->repository->findOneByShopUserAndChannel($shopUser, $channel);
+
+ $this->assertNotNull($result);
+ $this->assertInstanceOf(WishlistInterface::class, $result);
+ $this->assertCount(1, [$result]);
+ $this->assertSame('Olivier Wishlist', $result->getName());
+ $this->assertSame($shopUser, $result->getShopUser());
+ }
+
+ public function testItFindsAllAnonymousWishlistsWithChannel(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_all_anonymous_wishlists_with_channel.yaml');
+
+ $channel = $this->entityManager->getRepository(Channel::class)->findOneBy(['name' => 'name']);
+ /** @var array $result */
+ $result = $this->repository->findAllByAnonymousAndChannel('token', $channel);
+
+ $this->assertNotNull($result);
+ $this->assertIsArray($result);
+ $this->assertCount(2, $result);
+ $this->assertSame('Wishlist One', $result[0]->getName());
+ $this->assertSame('Wishlist Two', $result[1]->getName());
+ }
+
+ public function testItFindsOneWishlistByTokenAndName(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_one_wishlist_by_token_and_name.yaml');
+
+ /** @var ?WishlistInterface $result */
+ $result = $this->repository->findOneByTokenAndName('token', 'Olivier Wishlist');
+ /** @var ?WishlistInterface $result */
+ $this->assertNotNull($result);
+ $this->assertInstanceOf(WishlistInterface::class, $result);
+ $this->assertCount(1, [$result]);
+ $this->assertSame('Olivier Wishlist', $result->getName());
+
+ $missingResult = $this->repository->findOneByTokenAndName('non_existing_token', 'Olivier Wishlist');
+ $this->assertNull($missingResult);
+ }
+
+ public function testItFindsOneWishlistByShopUserAndName(): void
+ {
+ $this->loadFixturesFromFile('test_it_finds_one_wishlist_by_shop_user_and_name.yaml');
+
+ $shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
+
+ /** @var ?WishlistInterface $result */
+ $result = $this->repository->findOneByShopUserAndName($shopUser, 'Olivier Wishlist');
+ /** @var ?WishlistInterface $result */
+ $this->assertNotNull($result);
+ $this->assertInstanceOf(WishlistInterface::class, $result);
+ $this->assertCount(1, [$result]);
+ $this->assertSame('Olivier Wishlist', $result->getName());
+
+ $missingResult = $this->repository->findOneByShopUserAndName($shopUser, 'Bruce Wishlist');
+ $this->assertNull($missingResult);
+ }
+}