function it_throws_exception_if_any_array_element_is_not_adjustment(AdjustmentInterface $adjustment1, AdjustmentInterface $adjustment2)
 {
     $adjustment1->getLabel()->willReturn('tax 1');
     $adjustment1->getAmount()->willReturn(1000);
     $adjustment2->getLabel()->willReturn('tax 1');
     $adjustment2->getAmount()->willReturn(3000);
     $this->shouldThrow(\InvalidArgumentException::class)->during('aggregate', [[$adjustment1, $adjustment2, 'badObject']]);
 }
 function it_throws_exception_if_any_array_element_is_not_adjustment(AdjustmentInterface $adjustment1, AdjustmentInterface $adjustment2)
 {
     $adjustment1->getLabel()->willReturn('tax 1');
     $adjustment1->getAmount()->willReturn(1000);
     $adjustment2->getLabel()->willReturn('tax 1');
     $adjustment2->getAmount()->willReturn(3000);
     $this->shouldThrow(new \InvalidArgumentException('Each adjustments array element must implement ' . AdjustmentInterface::class . '.'))->during('aggregate', array(array($adjustment1, $adjustment2, 'badObject')));
 }
示例#3
0
 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);
 }
示例#4
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);
 }
示例#5
0
 /**
  * @param AdjustmentInterface $adjustment
  */
 protected function subtractFromAdjustmentsTotal(AdjustmentInterface $adjustment)
 {
     if (!$adjustment->isNeutral()) {
         $this->adjustmentsTotal -= $adjustment->getAmount();
         $this->recalculateTotal();
     }
 }
示例#6
0
 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);
 }
示例#7
0
 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);
 }
示例#8
0
文件: Order.php 项目: Hsidhu/Sylius
 /**
  * {@inheritdoc}
  */
 public function removeAdjustment(AdjustmentInterface $adjustment)
 {
     if (!$adjustment->isLocked() && $this->hasAdjustment($adjustment)) {
         $adjustment->setAdjustable(null);
         $this->adjustments->removeElement($adjustment);
     }
 }
示例#9
0
 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);
 }
示例#10
0
 protected function configureAdjustmentAmount(AdjustmentInterface $adjustment, OrderInterface $subject, array $configuration)
 {
     $adjustment->setAmount(-$configuration['amount']);
 }
示例#11
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);
 }
 protected function configureAdjustmentAmount(AdjustmentInterface $adjustment, OrderInterface $subject, array $configuration)
 {
     $adjustment->setAmount(-$subject->getShippingTotal());
 }