Example #1
0
 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);
 }
Example #2
0
 /**
  * @Transform /^promotion "([^"]+)"$/
  * @Transform /^"([^"]+)" promotion$/
  * @Transform :promotion
  */
 public function getPromotionByName($promotionName)
 {
     $promotion = $this->promotionRepository->findOneBy(['name' => $promotionName]);
     if (null === $promotion) {
         throw new \InvalidArgumentException(sprintf('Promotion with name "%s" does not exist in the promotion repository.', $promotionName));
     }
     return $promotion;
 }
Example #3
0
 /**
  * {@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;
 }
Example #4
0
 /**
  * {@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_promotion_with_coupon(SharedStorageInterface $sharedStorage, CouponFactoryInterface $couponFactory, TestPromotionFactoryInterface $testPromotionFactory, PromotionRepositoryInterface $promotionRepository, ChannelInterface $channel, CouponInterface $coupon, PromotionInterface $promotion)
 {
     $couponFactory->createNew()->willReturn($coupon);
     $coupon->setCode('Coupon galore')->shouldBeCalled();
     $sharedStorage->get('channel')->willReturn($channel);
     $testPromotionFactory->createForChannel('Promotion galore', $channel)->willReturn($promotion);
     $promotion->addCoupon($coupon)->shouldBeCalled();
     $promotion->setCouponBased(true)->shouldBeCalled();
     $promotionRepository->add($promotion)->shouldBeCalled();
     $sharedStorage->set('promotion', $promotion)->shouldBeCalled();
     $sharedStorage->set('coupon', $coupon)->shouldBeCalled();
     $this->thereIsPromotionWithCoupon('Promotion galore', 'Coupon galore');
 }
Example #6
0
 /**
  * @Given the store has promotion :promotionName with coupon :couponCode
  */
 public function thereIsPromotionWithCoupon($promotionName, $couponCode)
 {
     /** @var CouponInterface $coupon */
     $coupon = $this->couponFactory->createNew();
     $coupon->setCode($couponCode);
     $promotion = $this->testPromotionFactory->createForChannel($promotionName, $this->sharedStorage->get('channel'));
     $promotion->addCoupon($coupon);
     $promotion->setCouponBased(true);
     $this->promotionRepository->add($promotion);
     $this->sharedStorage->set('promotion', $promotion);
     $this->sharedStorage->set('coupon', $coupon);
 }
 function it_throws_exception_when_promotion_with_given_name_was_not_found(PromotionRepositoryInterface $promotionRepository)
 {
     $promotionRepository->findOneBy(['name' => 'Wrong Promotion'])->willReturn(null);
     $this->shouldThrow(\InvalidArgumentException::class)->during('getPromotionByName', ['Wrong Promotion']);
 }
 /**
  * @Then promotion :promotion should still exist in the registry
  */
 public function promotionShouldStillExistInTheRegistry(PromotionInterface $promotion)
 {
     Assert::notNull($this->promotionRepository->find($promotion->getId()));
 }
 function it_provides_active_promotions(PromotionRepositoryInterface $promotionRepository, PromotionInterface $promotion1, PromotionInterface $promotion2, PromotionSubjectInterface $subject)
 {
     $promotionRepository->findActive()->willReturn([$promotion1, $promotion2]);
     $this->getPromotions($subject)->shouldReturn([$promotion1, $promotion2]);
 }
Example #10
0
 /**
  * @Then promotion :promotion should still exist in the registry
  */
 public function promotionShouldStillExistInTheRegistry(PromotionInterface $promotion)
 {
     expect($this->promotionRepository->find($promotion->getId()))->toNotBe(null);
 }
 /**
  * {@inheritdoc}
  */
 public function getPromotions(PromotionSubjectInterface $subject)
 {
     return $this->promotionRepository->findActive();
 }
Example #12
0
 /**
  * @Transform /^promotion "([^"]+)"$/
  * @Transform /^"([^"]+)" promotion$/
  * @Transform :promotion
  */
 public function getPromotionByName($promotionName)
 {
     $promotion = $this->promotionRepository->findOneBy(['name' => $promotionName]);
     Assert::notNull($promotion, sprintf('Promotion with name "%s" does not exist', $promotionName));
     return $promotion;
 }
Example #13
0
 /**
  * @Given there is a promotion :promotionName
  */
 public function thereIsPromotion($promotionName)
 {
     $promotion = $this->testPromotionFactory->createForChannel($promotionName, $this->sharedStorage->get('channel'));
     $this->promotionRepository->add($promotion);
     $this->sharedStorage->set('promotion', $promotion);
 }