function it_stops_checking_at_the_first_failing_eligibility_checker(PromotionCouponEligibilityCheckerInterface $firstPromotionCouponEligibilityChecker, PromotionCouponEligibilityCheckerInterface $secondPromotionCouponEligibilityChecker, PromotionSubjectInterface $promotionSubject, PromotionCouponInterface $promotionCoupon) { $this->beConstructedWith([$firstPromotionCouponEligibilityChecker, $secondPromotionCouponEligibilityChecker]); $firstPromotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(false); $secondPromotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->shouldNotBeCalled(); $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(false); }
function it_returns_false_if_subject_coupons_is_not_eligible(PromotionCouponEligibilityCheckerInterface $promotionCouponEligibilityChecker, PromotionCouponAwarePromotionSubjectInterface $promotionSubject, PromotionInterface $promotion, PromotionCouponInterface $promotionCoupon) { $promotion->isCouponBased()->willReturn(true); $promotionSubject->getPromotionCoupon()->willReturn($promotionCoupon); $promotionCoupon->getPromotion()->willReturn($promotion); $promotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(false); $this->isEligible($promotionSubject, $promotion)->shouldReturn(false); }
/** * {@inheritdoc} */ public function isEligible(PromotionSubjectInterface $promotionSubject, PromotionInterface $promotion) { if (!$promotion->isCouponBased()) { return true; } if (!$promotionSubject instanceof PromotionCouponAwarePromotionSubjectInterface) { return false; } $promotionCoupon = $promotionSubject->getPromotionCoupon(); if (null === $promotionCoupon) { return false; } if ($promotion !== $promotionCoupon->getPromotion()) { return false; } return $this->promotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon); }