/** * @param PromotionRuleInterface $rule * * @return array */ protected function getConfiguration($rule) { if ($rule instanceof PromotionRuleInterface && null !== $rule->getConfiguration()) { return $rule->getConfiguration(); } return []; }
/** * @param PromotionRuleInterface $rule * * @return null|string */ protected function getRegistryIdentifier($rule) { if ($rule instanceof PromotionRuleInterface && null !== $rule->getType()) { return $rule->getType(); } if (null !== $this->registryIdentifier) { return $this->registryIdentifier; } return null; }
function it_does_not_check_more_rules_if_one_has_returned_false(ServiceRegistryInterface $rulesRegistry, RuleCheckerInterface $firstRuleChecker, RuleCheckerInterface $secondRuleChecker, PromotionRuleInterface $firstRule, PromotionRuleInterface $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); }
/** * {@inheritdoc} */ public function removeRule(PromotionRuleInterface $rule) { $rule->setPromotion(null); $this->rules->removeElement($rule); }
/** * @param PromotionSubjectInterface $subject * @param PromotionRuleInterface $rule * * @return bool */ protected function isEligibleToRule(PromotionSubjectInterface $subject, PromotionRuleInterface $rule) { /** @var RuleCheckerInterface $checker */ $checker = $this->ruleRegistry->get($rule->getType()); return $checker->isEligible($subject, $rule->getConfiguration()); }