public function testGetSubtotals() { $this->translator->expects($this->once())->method('trans')->with(sprintf('orob2b.order.subtotals.%s', Subtotal::TYPE_SUBTOTAL))->willReturn(ucfirst(Subtotal::TYPE_SUBTOTAL)); $order = new Order(); $perUnitLineItem = new OrderLineItem(); $perUnitLineItem->setPriceType(OrderLineItem::PRICE_TYPE_UNIT); $perUnitLineItem->setPrice(Price::create(20, 'USD')); $perUnitLineItem->setQuantity(2); $bundledUnitLineItem = new OrderLineItem(); $bundledUnitLineItem->setPriceType(OrderLineItem::PRICE_TYPE_BUNDLED); $bundledUnitLineItem->setPrice(Price::create(2, 'USD')); $bundledUnitLineItem->setQuantity(10); $otherCurrencyLineItem = new OrderLineItem(); $otherCurrencyLineItem->setPriceType(OrderLineItem::PRICE_TYPE_UNIT); $otherCurrencyLineItem->setPrice(Price::create(10, 'EUR')); $otherCurrencyLineItem->setQuantity(10); $emptyLineItem = new OrderLineItem(); $order->addLineItem($perUnitLineItem); $order->addLineItem($bundledUnitLineItem); $order->addLineItem($emptyLineItem); $order->addLineItem($otherCurrencyLineItem); $order->setCurrency('USD'); $subtotals = $this->provider->getSubtotals($order); $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $subtotals); $subtotal = $subtotals->get(Subtotal::TYPE_SUBTOTAL); $this->assertInstanceOf('OroB2B\\Bundle\\OrderBundle\\Model\\Subtotal', $subtotal); $this->assertEquals(Subtotal::TYPE_SUBTOTAL, $subtotal->getType()); $this->assertEquals(ucfirst(Subtotal::TYPE_SUBTOTAL), $subtotal->getLabel()); $this->assertEquals($order->getCurrency(), $subtotal->getCurrency()); $this->assertInternalType('float', $subtotal->getAmount()); $this->assertEquals(142.0, $subtotal->getAmount()); }
/** * @param Order $order */ protected function fillSubtotals(Order $order) { $subtotals = $this->subtotalsProvider->getSubtotals($order); $propertyAccessor = PropertyAccess::createPropertyAccessor(); foreach ($subtotals as $subtotal) { try { $propertyAccessor->setValue($order, $subtotal->getType(), $subtotal->getAmount()); } catch (NoSuchPropertyException $e) { } } }
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())); } }
/** * @param float $subtotalAmount */ protected function assertCalculateSubtotalsCalled($subtotalAmount) { $subtotal = new Subtotal(); $subtotal->setType(Subtotal::TYPE_SUBTOTAL)->setAmount($subtotalAmount); $this->subtotalsProvider->expects($this->once())->method('getSubtotals')->willReturn(new ArrayCollection([$subtotal])); }