/** * Test empty cart. * * @covers tryAutomaticCoupons */ public function testEmptyCart() { $cartCouponManager = $this->prophesize('Elcodi\\Component\\CartCoupon\\Services\\CartCouponManager'); $couponRepository = $this->prophesize('Doctrine\\Common\\Persistence\\ObjectRepository'); $couponRepository->findBy(Argument::any())->shouldNotBeCalled(); $cartLines = new ArrayCollection(); $cart = $this->prophesize('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartInterface'); $cart->getCartLines()->willReturn($cartLines); $automaticCouponApplicator = new AutomaticCouponApplicator($cartCouponManager->reveal(), $couponRepository->reveal()); $automaticCouponApplicator->tryAutomaticCoupons($cart->reveal()); }
/** * Method subscribed to PreCartLoad event. * * Iterate over all automatic Coupons and check if they apply. * If any applies, it will be added to the Cart * * @param CartOnLoadEvent $event Event */ public function tryAutomaticCoupons(CartOnLoadEvent $event) { $this->automaticCouponApplicator->tryAutomaticCoupons($event->getCart()); }