Skip to content

Commit

Permalink
Fix PHPSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Apr 17, 2023
1 parent 54e01dc commit 28a3077
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
11 changes: 9 additions & 2 deletions spec/Controller/Action/AddProductToWishlistActionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
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\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
Expand All @@ -37,15 +39,20 @@ function let(
ObjectManager $wishlistManager,
FlashBagInterface $flashBag,
TranslatorInterface $translator,
UrlGeneratorInterface $urlGenerator
UrlGeneratorInterface $urlGenerator,
RequestStack $requestStack,
Session $session,
): void {
$requestStack->getSession()->willReturn($session);
$session->getFlashBag()->willReturn($flashBag);

$this->beConstructedWith(
$tokenStorage,
$productRepository,
$wishlistContext,
$wishlistProductFactory,
$wishlistManager,
$flashBag,
$requestStack,
$translator,
$urlGenerator,
'bitbag_wishlist_token'
Expand Down
11 changes: 9 additions & 2 deletions spec/Controller/Action/AddProductVariantToWishlistActionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
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\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
Expand All @@ -37,15 +39,20 @@ function let(
ObjectManager $wishlistManager,
FlashBagInterface $flashBag,
TranslatorInterface $translator,
UrlGeneratorInterface $urlGenerator
UrlGeneratorInterface $urlGenerator,
RequestStack $requestStack,
Session $session,
): void {
$requestStack->getSession()->willReturn($session);
$session->getFlashBag()->willReturn($flashBag);

$this->beConstructedWith(
$tokenStorage,
$productVariantRepository,
$wishlistContext,
$wishlistProductFactory,
$wishlistManager,
$flashBag,
$requestStack,
$translator,
$urlGenerator,
'bitbag_wishlist_token'
Expand Down
19 changes: 14 additions & 5 deletions spec/Controller/Action/ListWishlistProductsActionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
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\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

Expand All @@ -42,15 +44,20 @@ function let(
EntityManagerInterface $cartManager,
FlashBagInterface $flashBag,
TranslatorInterface $translator,
Environment $twigEnvironment
Environment $twigEnvironment,
RequestStack $requestStack,
Session $session,
): void {
$requestStack->getSession()->willReturn($session);
$session->getFlashBag()->willReturn($flashBag);

$this->beConstructedWith(
$wishlistContext,
$cartContext,
$formFactory,
$orderModifier,
$cartManager,
$flashBag,
$requestStack,
$translator,
$twigEnvironment
);
Expand Down Expand Up @@ -91,7 +98,9 @@ function it_lists_wishlist_items(
;
$form->isSubmitted()->willReturn(false);
$form->createView()->willReturn($formView);
$form->getErrors()->willReturn($formErrorIterator);
$form->getErrors(true)->willReturn($formErrorIterator);
$form->getErrors()->willReturn(new FormErrorIterator($form->getWrappedObject(), []));

$twigEnvironment
->render(
'@BitBagSyliusWishlistPlugin/WishlistDetails/index.html.twig',
Expand All @@ -103,7 +112,7 @@ function it_lists_wishlist_items(
->willReturn('CONTENT')
;

$form->handleRequest($request)->shouldBeCalled();
$form->handleRequest($request)->shouldBeCalled()->willReturn($form);

$this->__invoke($request)->shouldHaveType(Response::class);
}
Expand Down Expand Up @@ -159,7 +168,7 @@ function it_adds_wishlist_items_to_the_cart(
$addToCartCommand->getCart()->willReturn($cart);
$addToCartCommand->getCartItem()->willReturn($cartItem);

$form->handleRequest($request)->shouldBeCalled();
$form->handleRequest($request)->shouldBeCalled()->willReturn($form);
$orderModifier->addToOrder($cart, $cartItem)->shouldBeCalled();
$cartManager->persist($cart)->shouldBeCalled();
$cartManager->flush()->shouldBeCalled();
Expand Down
11 changes: 9 additions & 2 deletions spec/Controller/Action/RemoveProductFromWishlistActionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
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\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
Expand All @@ -34,13 +36,18 @@ function let(
EntityManagerInterface $wishlistProductManager,
FlashBagInterface $flashBag,
TranslatorInterface $translator,
UrlGeneratorInterface $urlGenerator
UrlGeneratorInterface $urlGenerator,
RequestStack $requestStack,
Session $session,
): void {
$requestStack->getSession()->willReturn($session);
$session->getFlashBag()->willReturn($flashBag);

$this->beConstructedWith(
$wishlistContext,
$productRepository,
$wishlistProductManager,
$flashBag,
$requestStack,
$translator,
$urlGenerator
);
Expand Down

0 comments on commit 28a3077

Please sign in to comment.