function it_does_not_apply_bigger_promotions_than_unit_total($adjustmentFactory, $originator, $priceRangeFilter, $taxonFilter, AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $originalItems, Collection $units, OrderInterface $order, OrderItemInterface $orderItem1, OrderItemInterface $orderItem2, OrderItemInterface $orderItem3, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, PromotionInterface $promotion)
 {
     $order->getItems()->willReturn($originalItems);
     $originalItems->toArray()->willReturn([$orderItem1, $orderItem2, $orderItem3]);
     $priceRangeFilter->filter([$orderItem1, $orderItem2, $orderItem3], ['amount' => 1000, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1, $orderItem3]);
     $taxonFilter->filter([$orderItem1, $orderItem3], ['amount' => 1000, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1]);
     $orderItem1->getQuantity()->willReturn(2);
     $orderItem1->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $promotion->getDescription()->willReturn('Test description');
     $adjustmentFactory->createNew()->willReturn($promotionAdjustment1, $promotionAdjustment2);
     $unit1->getTotal()->willReturn(300);
     $promotionAdjustment1->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment1->setLabel('Test description')->shouldBeCalled();
     $promotionAdjustment1->setAmount(-300)->shouldBeCalled();
     $originator->setOrigin($promotionAdjustment1, $promotion)->shouldBeCalled();
     $unit2->getTotal()->willReturn(200);
     $promotionAdjustment2->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment2->setLabel('Test description')->shouldBeCalled();
     $promotionAdjustment2->setAmount(-200)->shouldBeCalled();
     $originator->setOrigin($promotionAdjustment2, $promotion)->shouldBeCalled();
     $unit1->addAdjustment($promotionAdjustment1)->shouldBeCalled();
     $unit2->addAdjustment($promotionAdjustment2)->shouldBeCalled();
     $this->execute($order, ['amount' => 1000, 'filters' => ['taxons' => ['testTaxon']]], $promotion);
 }
 function it_does_not_apply_promotions_with_amount_0($adjustmentFactory, $distributor, $originator, $priceRangeFilter, $taxonFilter, AdjustmentInterface $promotionAdjustment1, Collection $originalItems, Collection $units, OrderInterface $order, OrderItemInterface $orderItem1, OrderItemInterface $orderItem2, OrderItemInterface $orderItem3, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, PromotionInterface $promotion)
 {
     $order->getItems()->willReturn($originalItems);
     $originalItems->toArray()->willReturn([$orderItem1, $orderItem2, $orderItem3]);
     $priceRangeFilter->filter([$orderItem1, $orderItem2, $orderItem3], ['percentage' => 0.2, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1, $orderItem2]);
     $taxonFilter->filter([$orderItem1, $orderItem2], ['percentage' => 0.2, 'filters' => ['taxons' => ['testTaxon']]])->willReturn([$orderItem1]);
     $orderItem1->getQuantity()->willReturn(2);
     $orderItem1->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $orderItem1->getTotal()->willReturn(5);
     $distributor->distribute(1, 2)->willReturn([1, 0]);
     $promotion->getDescription()->willReturn('Test description');
     $adjustmentFactory->createNew()->willReturn($promotionAdjustment1);
     $promotionAdjustment1->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $promotionAdjustment1->setLabel('Test description')->shouldBeCalled();
     $promotionAdjustment1->setAmount(-1)->shouldBeCalled();
     $originator->setOrigin($promotionAdjustment1, $promotion)->shouldBeCalled();
     $unit1->addAdjustment($promotionAdjustment1)->shouldBeCalled();
     $unit2->addAdjustment(Argument::any())->shouldNotBeCalled();
     $this->execute($order, ['percentage' => 0.2, 'filters' => ['taxons' => ['testTaxon']]], $promotion);
 }