From 2d538e53a8d08ec41ae83c90b674ffee68d6ed5a Mon Sep 17 00:00:00 2001 From: Hubert Filar Date: Tue, 23 Jul 2024 14:52:11 +0200 Subject: [PATCH] OP-291: Deprecate WishlistProductFactoryFacade --- ...listProductsToOtherWishlistDuplicatorSpec.php | 16 +++++++++++++--- ...WishlistProductsToOtherWishlistDuplicator.php | 7 ++++--- src/Facade/WishlistProductFactoryFacade.php | 3 +++ .../WishlistProductFactoryFacadeInterface.php | 3 +++ src/Resources/config/services/duplicator.xml | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/spec/Duplicator/WishlistProductsToOtherWishlistDuplicatorSpec.php b/spec/Duplicator/WishlistProductsToOtherWishlistDuplicatorSpec.php index 0c1b7cc9..e62a742c 100644 --- a/spec/Duplicator/WishlistProductsToOtherWishlistDuplicatorSpec.php +++ b/spec/Duplicator/WishlistProductsToOtherWishlistDuplicatorSpec.php @@ -13,7 +13,8 @@ use BitBag\SyliusWishlistPlugin\Duplicator\WishlistProductsToOtherWishlistDuplicator; use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface; -use BitBag\SyliusWishlistPlugin\Facade\WishlistProductFactoryFacadeInterface; +use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface; +use BitBag\SyliusWishlistPlugin\Factory\WishlistProductFactoryInterface; use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; use Doctrine\Common\Collections\ArrayCollection; use PhpSpec\ObjectBehavior; @@ -25,14 +26,14 @@ final class WishlistProductsToOtherWishlistDuplicatorSpec extends ObjectBehavior { public function let( - WishlistProductFactoryFacadeInterface $wishlistProductVariantFactory, + WishlistProductFactoryInterface $wishlistProductFactory, ProductVariantRepositoryInterface $productVariantRepository, WishlistRepositoryInterface $wishlistRepository, RequestStack $requestStack, TranslatorInterface $translator, ): void { $this->beConstructedWith( - $wishlistProductVariantFactory, + $wishlistProductFactory, $productVariantRepository, $wishlistRepository, $requestStack, @@ -51,6 +52,9 @@ public function it_copy_wishlist_products( ProductVariantInterface $variant2, WishlistInterface $destinedWishlist, WishlistRepositoryInterface $wishlistRepository, + WishlistProductFactoryInterface $wishlistProductFactory, + WishlistProductInterface $wishlistProduct1, + WishlistProductInterface $wishlistProduct2, ): void { $productVariantRepository->find('1')->willReturn($variant1); $productVariantRepository->find('24')->willReturn($variant2); @@ -58,6 +62,12 @@ public function it_copy_wishlist_products( $destinedWishlist->hasProductVariant($variant1)->shouldBeCalled(); $destinedWishlist->hasProductVariant($variant2)->shouldBeCalled(); + $wishlistProductFactory->createForWishlistAndVariant($destinedWishlist, $variant1)->willReturn($wishlistProduct1); + $wishlistProductFactory->createForWishlistAndVariant($destinedWishlist, $variant2)->willReturn($wishlistProduct2); + + $destinedWishlist->addWishlistProduct($wishlistProduct1)->shouldBeCalled(); + $destinedWishlist->addWishlistProduct($wishlistProduct2)->shouldBeCalled(); + $wishlistRepository->add($destinedWishlist)->shouldBeCalledOnce(); $this->copyWishlistProductsToOtherWishlist(new ArrayCollection([ diff --git a/src/Duplicator/WishlistProductsToOtherWishlistDuplicator.php b/src/Duplicator/WishlistProductsToOtherWishlistDuplicator.php index 601c7ac2..bfc55462 100644 --- a/src/Duplicator/WishlistProductsToOtherWishlistDuplicator.php +++ b/src/Duplicator/WishlistProductsToOtherWishlistDuplicator.php @@ -12,7 +12,7 @@ namespace BitBag\SyliusWishlistPlugin\Duplicator; use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface; -use BitBag\SyliusWishlistPlugin\Facade\WishlistProductFactoryFacadeInterface; +use BitBag\SyliusWishlistPlugin\Factory\WishlistProductFactoryInterface; use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; use Doctrine\Common\Collections\Collection; use Sylius\Component\Core\Model\ProductVariantInterface; @@ -24,7 +24,7 @@ final class WishlistProductsToOtherWishlistDuplicator implements WishlistProductsToOtherWishlistDuplicatorInterface { public function __construct( - private WishlistProductFactoryFacadeInterface $wishlistProductVariantFactory, + private WishlistProductFactoryInterface $wishlistProductFactory, private ProductVariantRepositoryInterface $productVariantRepository, private WishlistRepositoryInterface $wishlistRepository, private RequestStack $requestStack, @@ -53,7 +53,8 @@ public function copyWishlistProductsToOtherWishlist(Collection $wishlistProducts sprintf('%s' . $message, $variant->getName()), ); } else { - $this->wishlistProductVariantFactory->createWithProductVariant($destinedWishlist, $variant); + $wishlistProduct = $this->wishlistProductFactory->createForWishlistAndVariant($destinedWishlist, $variant); + $destinedWishlist->addWishlistProduct($wishlistProduct); } } $this->wishlistRepository->add($destinedWishlist); diff --git a/src/Facade/WishlistProductFactoryFacade.php b/src/Facade/WishlistProductFactoryFacade.php index 9f01c177..69b1af52 100644 --- a/src/Facade/WishlistProductFactoryFacade.php +++ b/src/Facade/WishlistProductFactoryFacade.php @@ -16,6 +16,9 @@ use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\ProductVariantInterface; +/** + * @deprecated + */ final class WishlistProductFactoryFacade implements WishlistProductFactoryFacadeInterface { public function __construct( diff --git a/src/Facade/WishlistProductFactoryFacadeInterface.php b/src/Facade/WishlistProductFactoryFacadeInterface.php index 816119a3..5571c0d4 100644 --- a/src/Facade/WishlistProductFactoryFacadeInterface.php +++ b/src/Facade/WishlistProductFactoryFacadeInterface.php @@ -15,6 +15,9 @@ use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\ProductVariantInterface; +/** + * @deprecated + */ interface WishlistProductFactoryFacadeInterface { public function createWithProduct(WishlistInterface $wishlist, ProductInterface $product): void; diff --git a/src/Resources/config/services/duplicator.xml b/src/Resources/config/services/duplicator.xml index b6e2c36c..d5a22146 100644 --- a/src/Resources/config/services/duplicator.xml +++ b/src/Resources/config/services/duplicator.xml @@ -6,7 +6,7 @@ - +