/** * {@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; }
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'); }