function it_reverts_promotions_that_are_not_eligible_anymore(PreQualifiedPromotionsProviderInterface $preQualifiedPromotionsProvider, PromotionEligibilityCheckerInterface $promotionEligibilityChecker, PromotionApplicatorInterface $promotionApplicator, PromotionSubjectInterface $subject, PromotionInterface $promotion)
 {
     $subject->getPromotions()->willReturn([$promotion]);
     $preQualifiedPromotionsProvider->getPromotions($subject)->willReturn([$promotion]);
     $promotionEligibilityChecker->isEligible($subject, $promotion)->willReturn(false);
     $promotionApplicator->apply($subject, $promotion)->shouldNotBeCalled();
     $promotionApplicator->revert($subject, $promotion)->shouldBeCalled();
     $this->process($subject);
 }
Esempio n. 2
0
 /**
  * @param PromotionSubjectInterface $subject
  *
  * @return mixed
  */
 public function process(PromotionSubjectInterface $subject)
 {
     foreach ($subject->getPromotions() as $promotion) {
         $this->applicator->revert($subject, $promotion);
     }
     $eligiblePromotions = [];
     foreach ($this->preQualifiedPromotionsProvider->getPromotions($subject) as $promotion) {
         if (!$this->checker->isEligible($subject, $promotion)) {
             continue;
         }
         if ($promotion->isExclusive()) {
             return $this->applicator->apply($subject, $promotion);
         }
         $eligiblePromotions[] = $promotion;
     }
     foreach ($eligiblePromotions as $promotion) {
         $this->applicator->apply($subject, $promotion);
     }
 }