Пример #1
0
 function it_does_not_add_product_if_exists($orderItemQuantityModifier, $variantRepository, FactoryInterface $itemFactory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, PromotionInterface $promotion)
 {
     $variantRepository->find(500)->willReturn($variant);
     $itemFactory->createNew()->willReturn($item);
     $item->setUnitPrice(1)->willReturn($item);
     $item->setVariant($variant)->willReturn($item);
     $orderItemQuantityModifier->modify($item, 2)->shouldBeCalled();
     $item->equals($item)->willReturn(true);
     $order->getItems()->willReturn([$item]);
     $order->addItem($item)->shouldNotBeCalled();
     $this->execute($order, ['variant' => 500, 'quantity' => 2, 'price' => 1], $promotion);
 }
Пример #2
0
 function it_does_not_add_product_if_exists(RepositoryInterface $variantRepository, RepositoryInterface $itemRepository, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, PromotionInterface $promotion)
 {
     $configuration = array('variant' => 500, 'quantity' => 2, 'price' => 1);
     $variantRepository->find($configuration['variant'])->willReturn($variant);
     $itemRepository->createNew()->willReturn($item);
     $item->setUnitPrice($configuration['price'])->shouldBeCalled()->willReturn($item);
     $item->setVariant($variant)->shouldBeCalled()->willReturn($item);
     $item->setQuantity($configuration['quantity'])->shouldBeCalled()->willReturn($item);
     $item->equals($item)->willReturn(true);
     $order->getItems()->willReturn(array($item));
     $order->addItem($item)->shouldNotBeCalled();
     $this->execute($order, $configuration, $promotion);
 }
Пример #3
0
 /**
  * @param OrderInterface $order
  */
 private function generateItems(OrderInterface $order)
 {
     $numberOfItems = rand(1, 5);
     $products = $this->productRepository->findAll();
     for ($i = 0; $i < $numberOfItems; $i++) {
         $item = $this->orderItemFactory->createNew();
         $product = $this->faker->randomElement($products);
         $variant = $this->faker->randomElement($product->getVariants()->toArray());
         $item->setVariant($variant);
         $this->orderItemQuantityModifier->modify($item, rand(1, 5));
         $order->addItem($item);
     }
 }