/** * {@inheritdoc} */ public function getPromotions(PromotionSubjectInterface $subject) { if (!$subject instanceof OrderInterface) { throw new UnexpectedTypeException($subject, OrderInterface::class); } $channel = $subject->getChannel(); $promotions = $this->promotionRepository->findActiveByChannel($channel); return $promotions; }
/** * {@inheritdoc} */ public function getPromotions(PromotionSubjectInterface $subject) { if (!$subject instanceof OrderInterface) { throw new UnexpectedTypeException($subject, OrderInterface::class); } $channel = $subject->getChannel(); if (null === $channel) { throw new \InvalidArgumentException('Order has no channel, but it should.'); } $promotions = $this->promotionRepository->findActiveByChannel($channel); return $promotions; }
function it_throws_exception_when_a_promotion_is_not_found_but_it_should_exist(PromotionRepositoryInterface $promotionRepository, PromotionInterface $promotion) { $promotion->getId()->willReturn(5); $promotionRepository->find(5)->willReturn(null); $this->shouldThrow(FailureException::class)->during('promotionShouldStillExistInTheRegistry', [$promotion]); }
function it_provides_an_active_promotions_for_given_subject_channel(PromotionRepositoryInterface $promotionRepository, ChannelInterface $channel, PromotionInterface $promotion1, PromotionInterface $promotion2, OrderInterface $subject) { $subject->getChannel()->willReturn($channel); $promotionRepository->findActiveByChannel($channel)->willReturn([$promotion1, $promotion2]); $this->getPromotions($subject)->shouldReturn([$promotion1, $promotion2]); }