/**
  * {@inheritdoc}
  */
 public function isEligible(PromotionSubjectInterface $promotionSubject, PromotionInterface $promotion)
 {
     if (!$promotion->hasRules()) {
         return true;
     }
     foreach ($promotion->getRules() as $rule) {
         if (!$this->isEligibleToRule($promotionSubject, $rule)) {
             return false;
         }
     }
     return true;
 }
 function it_does_not_check_more_rules_if_one_has_returned_false(RuleCheckerInterface $cartQuantityRuleChecker, RuleCheckerInterface $itemTotalRuleChecker, RuleInterface $cartQuantityRule, RuleInterface $itemTotalRule, PromotionInterface $promotion, PromotionSubjectInterface $subject, ServiceRegistryInterface $rulesRegistry)
 {
     $promotion->hasRules()->willReturn(true);
     $promotion->getRules()->willReturn([$cartQuantityRule, $itemTotalRule]);
     $cartQuantityRule->getType()->willReturn(RuleInterface::TYPE_CART_QUANTITY);
     $cartQuantityRule->getConfiguration()->willReturn([]);
     $itemTotalRule->getType()->willReturn(RuleInterface::TYPE_ITEM_TOTAL);
     $itemTotalRule->getConfiguration()->willReturn([]);
     $rulesRegistry->get(RuleInterface::TYPE_CART_QUANTITY)->willReturn($cartQuantityRuleChecker);
     $rulesRegistry->get(RuleInterface::TYPE_ITEM_TOTAL)->willReturn($itemTotalRuleChecker);
     $cartQuantityRuleChecker->isEligible($subject, [])->willReturn(false);
     $itemTotalRuleChecker->isEligible($subject, [])->shouldNotBeCalled();
     $this->isEligible($subject, $promotion)->shouldReturn(false);
 }
 function it_does_not_check_more_rules_if_one_has_returned_false(ServiceRegistryInterface $rulesRegistry, RuleCheckerInterface $firstRuleChecker, RuleCheckerInterface $secondRuleChecker, RuleInterface $firstRule, RuleInterface $secondRule, PromotionInterface $promotion, PromotionSubjectInterface $subject)
 {
     $promotion->hasRules()->willReturn(true);
     $promotion->getRules()->willReturn([$firstRule, $secondRule]);
     $firstRule->getType()->willReturn('first_rule');
     $firstRule->getConfiguration()->willReturn([]);
     $secondRule->getType()->willReturn('second_rule');
     $secondRule->getConfiguration()->willReturn([]);
     $rulesRegistry->get('first_rule')->willReturn($firstRuleChecker);
     $rulesRegistry->get('second_rule')->willReturn($secondRuleChecker);
     $firstRuleChecker->isEligible($subject, [])->willReturn(false);
     $secondRuleChecker->isEligible($subject, [])->shouldNotBeCalled();
     $this->isEligible($subject, $promotion)->shouldReturn(false);
 }
 function it_recognizes_subject_as_eligible_if_coupon_code_match($dispatcher, PromotionCouponsAwareSubjectInterface $subject, PromotionInterface $promotion, CouponInterface $coupon)
 {
     $subject->getPromotionCoupons()->willReturn(array($coupon));
     $promotion->getStartsAt()->willReturn(null);
     $promotion->getEndsAt()->willReturn(null);
     $promotion->getUsageLimit()->willReturn(null);
     $promotion->hasRules()->willReturn(false);
     $promotion->isCouponBased()->willReturn(true);
     $coupon->getPromotion()->willReturn($promotion);
     $dispatcher->dispatch(SyliusPromotionEvents::COUPON_ELIGIBLE, Argument::any())->shouldBeCalled();
     $this->isEligible($subject, $promotion)->shouldReturn(true);
 }