/** * {@inheritdoc} */ public function apply(OrderInterface $order, PromotionInterface $promotion, array $adjustmentsAmounts) { Assert::eq($order->countItems(), count($adjustmentsAmounts)); $i = 0; foreach ($order->getItems() as $item) { $adjustmentAmount = $adjustmentsAmounts[$i++]; if (0 === $adjustmentAmount) { continue; } $this->applyAdjustmentsOnItemUnits($item, $promotion, $adjustmentAmount); } }
function it_throws_exception_if_items_count_is_different_than_adjustment_amounts(PromotionInterface $promotion, OrderInterface $order) { $order->countItems()->willReturn(2); $this->shouldThrow(\InvalidArgumentException::class)->during('apply', [$order, $promotion, [1999]]); }
function it_does_not_revert_if_order_has_no_items(OrderInterface $order, PromotionInterface $promotion) { $order->countItems()->willReturn(0); $order->getItems()->shouldNotBeCalled(); $this->revert($order, [], $promotion); }