예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function generate(PromotionInterface $promotion, Instruction $instruction)
 {
     for ($i = 0, $amount = $instruction->getAmount(); $i < $amount; $i++) {
         $coupon = $this->repository->createNew();
         $coupon->setPromotion($promotion);
         $coupon->setCode($this->generateUniqueCode());
         $coupon->setUsageLimit($instruction->getUsageLimit());
         $this->manager->persist($coupon);
     }
     $this->manager->flush();
 }
예제 #2
0
 function it_should_generate_coupons_according_to_instruction($repository, $manager, PromotionInterface $promotion, CouponInterface $coupon, Instruction $instruction)
 {
     $instruction->getAmount()->willReturn(1);
     $instruction->getUsageLimit()->willReturn(null);
     $repository->createNew()->willReturn($coupon);
     $repository->findOneBy(Argument::any())->willReturn(null);
     $coupon->setPromotion($promotion)->shouldBeCalled();
     $coupon->setCode(Argument::any())->shouldBeCalled();
     $coupon->setUsageLimit(null)->shouldBeCalled();
     $manager->persist($coupon)->shouldBeCalled();
     $manager->flush()->shouldBeCalled();
     $this->generate($promotion, $instruction);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function generate(PromotionInterface $promotion, Instruction $instruction)
 {
     $generatedCoupons = [];
     for ($i = 0, $amount = $instruction->getAmount(); $i < $amount; ++$i) {
         $coupon = $this->couponFactory->createNew();
         $coupon->setPromotion($promotion);
         $coupon->setCode($this->generateUniqueCode());
         $coupon->setUsageLimit($instruction->getUsageLimit());
         $coupon->setExpiresAt($instruction->getExpiresAt());
         $generatedCoupons[] = $coupon;
         $this->manager->persist($coupon);
     }
     $this->manager->flush();
     return $generatedCoupons;
 }
예제 #4
0
 function it_should_generate_coupons_according_to_instruction(FactoryInterface $couponFactory, $repository, $manager, FilterCollection $filters, PromotionInterface $promotion, CouponInterface $coupon, Instruction $instruction)
 {
     $instruction->getAmount()->willReturn(1);
     $instruction->getUsageLimit()->willReturn(null);
     $instruction->getExpiresAt()->willReturn(null);
     $couponFactory->createNew()->willReturn($coupon);
     $repository->findOneBy(Argument::any())->willReturn(null);
     $coupon->setPromotion($promotion)->shouldBeCalled();
     $coupon->setCode(Argument::any())->shouldBeCalled();
     $coupon->setUsageLimit(null)->shouldBeCalled();
     $coupon->setExpiresAt(null)->shouldBeCalled();
     $manager->getFilters()->shouldBeCalled()->willReturn($filters);
     $filters->disable('softdeleteable')->shouldBeCalled();
     $filters->enable('softdeleteable')->shouldBeCalled();
     $manager->persist($coupon)->shouldBeCalled();
     $manager->flush()->shouldBeCalled();
     $this->generate($promotion, $instruction);
 }