Skip to content

Commit

Permalink
OP-291: Deprecate WishlistProductFactoryFacade
Browse files Browse the repository at this point in the history
  • Loading branch information
hmfilar committed Jul 23, 2024
1 parent c545592 commit 2d538e5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
16 changes: 13 additions & 3 deletions spec/Duplicator/WishlistProductsToOtherWishlistDuplicatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -51,13 +52,22 @@ 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);

$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([
Expand Down
7 changes: 4 additions & 3 deletions src/Duplicator/WishlistProductsToOtherWishlistDuplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Facade/WishlistProductFactoryFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions src/Facade/WishlistProductFactoryFacadeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/duplicator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<services>
<service id="bitbag_sylius_wishlist_plugin.services.duplicator" class="BitBag\SyliusWishlistPlugin\Duplicator\WishlistProductsToOtherWishlistDuplicator">
<argument type="service" id="bitbag_sylius_wishlist_plugin.facade.wishlist_product_factory_facade"/>
<argument type="service" id="bitbag_sylius_wishlist_plugin.factory.wishlist_product"/>
<argument type="service" id="sylius.repository.product_variant"/>
<argument type="service" id="bitbag_sylius_wishlist_plugin.repository.wishlist"/>
<argument type="service" id="request_stack"/>
Expand Down

0 comments on commit 2d538e5

Please sign in to comment.