Пример #1
0
 /**
  * Given a coupon code, removes it from cart.
  *
  * @param CartInterface $cart       Cart
  * @param string        $couponCode Coupon code
  *
  * @return bool Coupon has been removed from cart
  */
 public function removeCouponByCode(CartInterface $cart, $couponCode)
 {
     $coupon = $this->couponRepository->findOneBy(['code' => $couponCode]);
     if (!$coupon instanceof CouponInterface) {
         return false;
     }
     return $this->removeCoupon($cart, $coupon);
 }
Пример #2
0
 /**
  * Test add coupon by code
  *
  * @covers removeCouponByCode
  * @covers removeCoupon
  */
 public function testRemoveExistingCouponByCodeExistingCartCoupons()
 {
     $cart = $this->prophesize('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartInterface');
     $coupon = $this->prophesize('Elcodi\\Component\\Coupon\\Entity\\Interfaces\\CouponInterface');
     $cartCoupon1 = $this->prophesize('Elcodi\\Component\\CartCoupon\\Entity\\Interfaces\\CartCouponInterface');
     $cartCoupon2 = $this->prophesize('Elcodi\\Component\\CartCoupon\\Entity\\Interfaces\\CartCouponInterface');
     $cartCoupons = [$cartCoupon1->reveal(), $cartCoupon2->reveal()];
     $this->cartCouponEventDispatcher->dispatchCartCouponOnRemoveEvent(Argument::any(), Argument::any())->shouldBeCalledTimes(2);
     $this->couponRepository->findOneBy(Argument::any())->willReturn($coupon->reveal())->shouldBeCalled();
     $this->cartCouponDirector->findBy(Argument::any())->willReturn($cartCoupons)->shouldBeCalled();
     $cartCouponManager = $this->createCartCouponManagerInstance();
     $result = $cartCouponManager->removeCouponByCode($cart->reveal(), 1);
     $this->assertTrue($result);
 }