public function testProcessValidData()
 {
     $subtotal = new Subtotal();
     $amount = 42;
     $subtotal->setType(Subtotal::TYPE_SUBTOTAL);
     $subtotal->setAmount($amount);
     $subtotals = new ArrayCollection([$subtotal]);
     $this->subtotalsProvider->expects($this->any())->method('getSubtotals')->willReturn($subtotals);
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->manager->expects($this->once())->method('persist')->with($this->entity);
     $this->manager->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->entity));
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     foreach ($subtotals as $subtotal) {
         $this->assertEquals($amount, $propertyAccessor->getValue($this->entity, $subtotal->getType()));
     }
 }
 /**
  * Get order subtotal
  *
  * @param Order $order
  *
  * @return Subtotal
  */
 protected function getSubtotal(Order $order)
 {
     $subtotal = new Subtotal();
     $subtotal->setType(Subtotal::TYPE_SUBTOTAL);
     $translation = sprintf('orob2b.order.subtotals.%s', $subtotal->getType());
     $subtotal->setLabel($this->translator->trans($translation));
     $subtotalAmount = 0.0;
     foreach ($order->getLineItems() as $lineItem) {
         if (!$lineItem->getPrice()) {
             continue;
         }
         $rowTotal = $lineItem->getPrice()->getValue();
         if ($lineItem->getPriceType() === OrderLineItem::PRICE_TYPE_UNIT) {
             $rowTotal *= $lineItem->getQuantity();
         }
         if ($order->getCurrency() !== $lineItem->getPrice()->getCurrency()) {
             $rowTotal *= $this->getExchangeRate($lineItem->getPrice()->getCurrency(), $order->getCurrency());
         }
         $subtotalAmount += $rowTotal;
     }
     $subtotal->setAmount($subtotalAmount);
     $subtotal->setCurrency($order->getCurrency());
     return $subtotal;
 }
 public function testToArray()
 {
     $subtotal = new Subtotal();
     $this->assertEquals(['type' => $subtotal->getType(), 'label' => $subtotal->getLabel(), 'amount' => $subtotal->getAmount(), 'currency' => $subtotal->getCurrency()], $subtotal->toArray());
 }