function it_throws_cart_not_found_exception_and_removes_id_from_session_when_cart_is_not_found(SessionInterface $session, CartRepositoryInterface $cartRepository)
 {
     $session->has('session_key_name')->willReturn(true);
     $session->get('session_key_name')->willReturn(12345);
     $cartRepository->findCartById(12345)->willReturn(null);
     $session->remove('session_key_name')->shouldBeCalled();
     $this->shouldThrow(CartNotFoundException::class)->during('getCart');
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function purge()
 {
     $cartsToPurge = $this->repository->findExpiredCarts();
     foreach ($cartsToPurge as $cart) {
         $this->purgeCart($cart);
     }
     $this->manager->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function getCart()
 {
     if (!$this->session->has($this->sessionKeyName)) {
         throw new CartNotFoundException('Sylius was not able to find the cart in session');
     }
     $cart = $this->cartRepository->findCartById($this->session->get($this->sessionKeyName));
     if (null === $cart) {
         $this->session->remove($this->sessionKeyName);
         throw new CartNotFoundException('Sylius was not able to find the cart in session');
     }
     return $cart;
 }