/**
  * @param string $code
  * @param array $generatedCoupons
  *
  * @return bool
  */
 private function isUsedCode($code, array $generatedCoupons)
 {
     if (isset($generatedCoupons[$code])) {
         return true;
     }
     return null !== $this->couponRepository->findOneBy(['code' => $code]);
 }
 function it_generates_coupons_according_to_an_instruction(FactoryInterface $promotionCouponFactory, PromotionCouponRepositoryInterface $promotionCouponRepository, ObjectManager $objectManager, PromotionInterface $promotion, PromotionCouponInterface $promotionCoupon, PromotionCouponGeneratorInstructionInterface $instruction, GenerationPolicyInterface $generationPolicy)
 {
     $instruction->getAmount()->willReturn(1);
     $instruction->getUsageLimit()->willReturn(null);
     $instruction->getExpiresAt()->willReturn(null);
     $instruction->getCodeLength()->willReturn(6);
     $generationPolicy->isGenerationPossible($instruction)->willReturn(true);
     $promotionCouponFactory->createNew()->willReturn($promotionCoupon);
     $promotionCouponRepository->findOneBy(Argument::any())->willReturn(null);
     $promotionCoupon->setPromotion($promotion)->shouldBeCalled();
     $promotionCoupon->setCode(Argument::any())->shouldBeCalled();
     $promotionCoupon->setUsageLimit(null)->shouldBeCalled();
     $promotionCoupon->setExpiresAt(null)->shouldBeCalled();
     $objectManager->persist($promotionCoupon)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $this->generate($promotion, $instruction);
 }
 /**
  * @Then /^(this coupon) should no longer exist in the coupon registry$/
  */
 public function couponShouldNotExistInTheRegistry(PromotionCouponInterface $coupon)
 {
     Assert::null($this->couponRepository->findOneBy(['code' => $coupon->getCode()]), sprintf('The coupon with code %s should not exist', $coupon->getCode()));
 }