Skip to content

Commit

Permalink
fix phpspec, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fabulousPuppet authored and christopherhero committed Aug 22, 2022
1 parent 6c05d78 commit d42379a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
20 changes: 11 additions & 9 deletions spec/Controller/Action/AddProductToWishlistActionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +35,6 @@ public function let(
WishlistProductFactoryInterface $wishlistProductFactory,
FlashBagInterface $flashBag,
TranslatorInterface $translator,
UrlGeneratorInterface $urlGenerator,
WishlistsResolverInterface $wishlistsResolver,
ObjectManager $wishlistManager,
ChannelContextInterface $channelContext
Expand All @@ -45,7 +44,6 @@ public function let(
$wishlistProductFactory,
$flashBag,
$translator,
$urlGenerator,
$wishlistsResolver,
$wishlistManager,
$channelContext
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
}
5 changes: 0 additions & 5 deletions src/Controller/Action/AddProductToWishlistAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,8 +37,6 @@ final class AddProductToWishlistAction

private TranslatorInterface $translator;

private UrlGeneratorInterface $urlGenerator;

private WishlistsResolverInterface $wishlistsResolver;

private ObjectManager $wishlistManager;
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d42379a

Please sign in to comment.