From d42379a0e8f1e8b936f6ac5cadda4177e353c2c7 Mon Sep 17 00:00:00 2001 From: Jan Hickiewicz Date: Wed, 15 Jun 2022 11:05:56 +0200 Subject: [PATCH] fix phpspec, refactor --- .../Action/AddProductToWishlistActionSpec.php | 20 ++++++++++--------- .../Action/AddProductToWishlistAction.php | 5 ----- src/Resources/config/services.yml | 1 - 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/spec/Controller/Action/AddProductToWishlistActionSpec.php b/spec/Controller/Action/AddProductToWishlistActionSpec.php index 4b5aa7e1..642b5315 100644 --- a/spec/Controller/Action/AddProductToWishlistActionSpec.php +++ b/spec/Controller/Action/AddProductToWishlistActionSpec.php @@ -21,11 +21,11 @@ use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Repository\ProductRepositoryInterface; +use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Contracts\Translation\TranslatorInterface; final class AddProductToWishlistActionSpec extends ObjectBehavior @@ -35,7 +35,6 @@ public function let( WishlistProductFactoryInterface $wishlistProductFactory, FlashBagInterface $flashBag, TranslatorInterface $translator, - UrlGeneratorInterface $urlGenerator, WishlistsResolverInterface $wishlistsResolver, ObjectManager $wishlistManager, ChannelContextInterface $channelContext @@ -45,7 +44,6 @@ public function let( $wishlistProductFactory, $flashBag, $translator, - $urlGenerator, $wishlistsResolver, $wishlistManager, $channelContext @@ -76,10 +74,10 @@ public function it_handles_the_request_and_persist_new_wishlist_for_logged_shop_ WishlistInterface $wishlist2, TranslatorInterface $translator, FlashBagInterface $flashBag, - UrlGeneratorInterface $urlGenerator, ObjectManager $wishlistManager, ChannelContextInterface $channelContext, - ChannelInterface $channel + ChannelInterface $channel, + ParameterBag $headers ): void { $request->get('productId')->willReturn(1); @@ -93,7 +91,6 @@ public function it_handles_the_request_and_persist_new_wishlist_for_logged_shop_ $wishlistProductFactory->createForWishlistAndProduct($wishlist1, $product)->willReturn($wishlistProduct); $translator->trans('bitbag_sylius_wishlist_plugin.ui.added_wishlist_item')->willReturn('Product has been added to your wishlist.'); - $urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_wishlist_list_products')->willReturn('/wishlist'); $channelContext->getChannel()->willReturn($channel); $channel->getId()->willReturn(1); $wishlist1->getChannel()->willReturn($channel); @@ -102,6 +99,9 @@ public function it_handles_the_request_and_persist_new_wishlist_for_logged_shop_ $wishlistManager->flush()->shouldBeCalledOnce(); $flashBag->add('success', 'Product has been added to your wishlist.')->shouldBeCalled(); + $request->headers = $headers; + $headers->get('referer')->willReturn('value'); + $this->__invoke($request)->shouldHaveType(RedirectResponse::class); } @@ -116,10 +116,10 @@ public function it_handles_the_request_and_persist_new_wishlist_for_anonymous_us WishlistProductInterface $wishlistProduct, TranslatorInterface $translator, FlashBagInterface $flashBag, - UrlGeneratorInterface $urlGenerator, ObjectManager $wishlistManager, ChannelContextInterface $channelContext, - ChannelInterface $channel + ChannelInterface $channel, + ParameterBag $headers ): void { $request->get('productId')->willReturn(1); $productRepository->find(1)->willReturn($product); @@ -132,7 +132,6 @@ public function it_handles_the_request_and_persist_new_wishlist_for_anonymous_us $wishlistProductFactory->createForWishlistAndProduct($wishlist1, $product)->willReturn($wishlistProduct); $translator->trans('bitbag_sylius_wishlist_plugin.ui.added_wishlist_item')->willReturn('Product has been added to your wishlist.'); - $urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_wishlist_list_products')->willReturn('/wishlist'); $channelContext->getChannel()->willReturn($channel); $channel->getId()->willReturn(1); $wishlist1->getChannel()->willReturn($channel); @@ -141,6 +140,9 @@ public function it_handles_the_request_and_persist_new_wishlist_for_anonymous_us $wishlistManager->flush()->shouldBeCalledOnce(); $flashBag->add('success', 'Product has been added to your wishlist.')->shouldBeCalled(); + $request->headers = $headers; + $headers->get('referer')->willReturn('value'); + $this->__invoke($request)->shouldHaveType(RedirectResponse::class); } } diff --git a/src/Controller/Action/AddProductToWishlistAction.php b/src/Controller/Action/AddProductToWishlistAction.php index eb4337a5..0b2c8a3f 100644 --- a/src/Controller/Action/AddProductToWishlistAction.php +++ b/src/Controller/Action/AddProductToWishlistAction.php @@ -25,7 +25,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Contracts\Translation\TranslatorInterface; final class AddProductToWishlistAction @@ -38,8 +37,6 @@ final class AddProductToWishlistAction private TranslatorInterface $translator; - private UrlGeneratorInterface $urlGenerator; - private WishlistsResolverInterface $wishlistsResolver; private ObjectManager $wishlistManager; @@ -51,14 +48,12 @@ public function __construct( WishlistProductFactoryInterface $wishlistProductFactory, FlashBagInterface $flashBag, TranslatorInterface $translator, - UrlGeneratorInterface $urlGenerator, WishlistsResolverInterface $wishlistsResolver, ObjectManager $wishlistManager, ChannelContextInterface $channelContext ) { $this->productRepository = $productRepository; $this->wishlistProductFactory = $wishlistProductFactory; - $this->urlGenerator = $urlGenerator; $this->flashBag = $flashBag; $this->translator = $translator; $this->wishlistsResolver = $wishlistsResolver; diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 5e7149ec..98523787 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -41,7 +41,6 @@ services: - "@bitbag_sylius_wishlist_plugin.factory.wishlist_product" - "@session.flash_bag" - "@translator" - - "@router" - "@bitbag_sylius_wishlist_plugin.resolver.wishlists_resolver" - "@bitbag_sylius_wishlist_plugin.manager.wishlist" - "@sylius.context.channel"