/** * {@inheritdoc} */ public function createForPromotion($promotionId) { if (null === ($promotion = $this->promotionRepository->find($promotionId))) { throw new \InvalidArgumentException(sprintf('Promotion with id "%s" does not exist.', $promotionId)); } $coupon = $this->factory->createNew(); $coupon->setPromotion($promotion); return $coupon; }
/** * {@inheritdoc} */ public function createForPromotion($promotionId) { /** @var PromotionInterface $promotion */ Assert::notNull($promotion = $this->promotionRepository->find($promotionId), sprintf('Promotion with id %s does not exist.', $promotionId)); Assert::true($promotion->isCouponBased(), sprintf('Promotion with name %s is not coupon based.', $promotion->getName())); $coupon = $this->factory->createNew(); $coupon->setPromotion($promotion); return $coupon; }
function it_creates_a_coupon_and_assigns_a_promotion_to_id(FactoryInterface $factory, PromotionRepositoryInterface $promotionRepository, PromotionInterface $promotion, CouponInterface $coupon) { $factory->createNew()->willReturn($coupon); $promotionRepository->find(13)->willReturn($promotion); $coupon->setPromotion($promotion)->shouldBeCalled(); $this->createForPromotion(13)->shouldReturn($coupon); }
/** * @Then promotion :promotion should still exist in the registry */ public function promotionShouldStillExistInTheRegistry(PromotionInterface $promotion) { Assert::notNull($this->promotionRepository->find($promotion->getId())); }
/** * @Then promotion :promotion should still exist in the registry */ public function promotionShouldStillExistInTheRegistry(PromotionInterface $promotion) { expect($this->promotionRepository->find($promotion->getId()))->toNotBe(null); }