function it_calculates_correct_total_when_adjustment_is_bigger_than_cost(OrderItemInterface $item, AdjustmentInterface $adjustment) { $item->calculateTotal()->shouldBeCalled(); $item->getTotal()->willReturn(45000); $item->equals(Argument::any())->willReturn(false); $item->setOrder($this)->shouldBeCalled(); $adjustment->isNeutral()->willReturn(false); $adjustment->getAmount()->willReturn(-100000); $adjustment->setAdjustable($this)->shouldBeCalled(); $this->addItem($item)->addAdjustment($adjustment); $this->calculateTotal(); $this->getTotal()->shouldReturn(0); }
function it_returns_correct_adjustments_total_by_type_recursively(AdjustmentInterface $adjustment1, OrderItemUnitInterface $orderItemUnit1, OrderItemUnitInterface $orderItemUnit2) { $adjustment1->getType()->willReturn('tax'); $adjustment1->getAmount()->willReturn(200); $adjustment1->isNeutral()->willReturn(false); $adjustment1->setAdjustable($this)->shouldBeCalled(); $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject()); $orderItemUnit1->getTotal()->willReturn(500); $orderItemUnit1->getAdjustmentsTotal('tax')->willReturn(150); $orderItemUnit1->getAdjustmentsTotal('promotion')->willReturn(30); $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject()); $orderItemUnit2->getTotal()->willReturn(300); $orderItemUnit2->getAdjustmentsTotal('tax')->willReturn(100); $orderItemUnit2->getAdjustmentsTotal('promotion')->willReturn(0); $this->addAdjustment($adjustment1); $this->addUnit($orderItemUnit1); $this->addUnit($orderItemUnit2); $this->getAdjustmentsTotalRecursively('tax')->shouldReturn(450); $this->getAdjustmentsTotalRecursively('promotion')->shouldReturn(30); }
function it_recalculates_its_total_properly_after_adjustment_amount_change(AdjustmentInterface $adjustment1, AdjustmentInterface $adjustment2, OrderItemInterface $orderItem) { $orderItem->recalculateUnitsTotal()->shouldBeCalledTimes(2); $adjustment1->isNeutral()->willReturn(false); $adjustment1->setAdjustable($this)->shouldBeCalled(); $adjustment1->getAmount()->willReturn(100); $adjustment2->isNeutral()->willReturn(false); $adjustment2->setAdjustable($this)->shouldBeCalled(); $adjustment2->getAmount()->willReturn(50); $this->addAdjustment($adjustment1); $this->addAdjustment($adjustment2); $adjustment2->getAmount()->willReturn(150); $this->recalculateAdjustmentsTotal(); $this->getTotal()->shouldReturn(1250); }
function it_calculates_its_total_properly_after_adjustments_clear(AdjustmentInterface $adjustment1, AdjustmentInterface $adjustment2, OrderItemInterface $orderItem) { $adjustment1->isNeutral()->willReturn(false); $adjustment1->setAdjustable($this)->shouldBeCalled(); $adjustment2->isNeutral()->willReturn(false); $adjustment2->setAdjustable($this)->shouldBeCalled(); $adjustment1->getAmount()->willReturn(100); $adjustment2->getAmount()->willReturn(50); $this->addAdjustment($adjustment1); $this->addAdjustment($adjustment2); $this->setOrderItem($orderItem); $orderItem->getUnitPrice()->willReturn(1000); $this->calculateTotal(); $this->getTotal()->shouldReturn(1150); $this->clearAdjustments(); $this->calculateTotal(); $this->getTotal()->shouldReturn(1000); }
function it_calculates_correct_total_when_adjustment_is_bigger_than_cost(AdjustmentInterface $adjustment) { $this->setQuantity(1); $this->setUnitPrice(1500); $adjustment->isNeutral()->willReturn(false); $adjustment->getAmount()->willReturn(-2000); $adjustment->setAdjustable($this)->shouldBeCalled(); $this->addAdjustment($adjustment); $this->calculateTotal(); $this->getTotal()->shouldReturn(0); }
/** * Helper method */ protected function addShippingAndTaxAdjustments(OrderInterface $order, AdjustmentInterface $shippingAdjustment, AdjustmentInterface $taxAdjustment) { $shippingAdjustment->getLabel()->willReturn(OrderInterface::SHIPPING_ADJUSTMENT); $shippingAdjustment->setAdjustable($order)->shouldBeCalled(); $taxAdjustment->getLabel()->willReturn(OrderInterface::TAX_ADJUSTMENT); $taxAdjustment->setAdjustable($order)->shouldBeCalled(); $order->addAdjustment($shippingAdjustment); $order->addAdjustment($taxAdjustment); }