/** * Test object creation * * @group order */ public function testCreate() { $orderLineHistoryFactory = new OrderLineHistoryFactory(); $orderLineHistoryFactory->setEntityNamespace('Elcodi\\Component\\Cart\\Entity\\OrderLineHistory'); $orderLineFactory = new OrderLineFactory(); $orderLineFactory->setOrderLineHistoryFactory($orderLineHistoryFactory)->setInitialOrderHistoryState('new')->setEntityNamespace('Elcodi\\Component\\Cart\\Entity\\OrderLine'); $orderLine = $orderLineFactory->create(); $orderHistoryFactory = new OrderHistoryFactory(); $orderHistoryFactory->setEntityNamespace('Elcodi\\Component\\Cart\\Entity\\OrderHistory'); $orderFactory = new OrderFactory(); $orderFactory->setOrderHistoryFactory($orderHistoryFactory)->setInitialOrderHistoryState('new')->setEntityNamespace('Elcodi\\Component\\Cart\\Entity\\Order'); $order = $orderFactory->create(); $order->addOrderLine($orderLine); $this->assertCount(1, $order->getOrderHistories()); $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderHistoryInterface', $order->getOrderHistories()->first()); $this->assertEquals('new', $order->getOrderHistories()->first()->getState()); $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderHistoryInterface', $order->getLastOrderHistory()); $this->assertSame($order->getOrderHistories()->first(), $order->getLastOrderHistory()); $this->assertCount(1, $order->getOrderLines()); $orderLine = $order->getOrderLines()->first(); $this->assertCount(1, $orderLine->getOrderLineHistories()); $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderLineHistoryInterface', $orderLine->getOrderLineHistories()->first()); $this->assertEquals($orderLine->getOrderLineHistories()->first()->getState(), 'new'); $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderLineHistoryInterface', $orderLine->getLastOrderLineHistory()); $this->assertSame($orderLine->getOrderLineHistories()->first(), $orderLine->getLastOrderLineHistory()); }
/** * Creates an instance of an entity. * * This method must return always an empty instance for related entity * * @return OrderLine New OrderLine instance */ public function create() { /** * @var OrderLine $orderLine */ $classNamespace = $this->getEntityNamespace(); $orderLine = new $classNamespace(); $orderLine->setOrderLineHistories(new ArrayCollection()); $orderLineHistory = $this->orderLineHistoryFactory->create(); $orderLineHistory->setOrderLine($orderLine)->setState($this->initialOrderHistoryState); $orderLine->addOrderLineHistory($orderLineHistory)->setLastOrderLineHistory($orderLineHistory); return $orderLine; }
/** * Given an existing OrderLine, changes its state and creates a new HistoryState. * 'PreChange' and 'PostChange' events are fired, which by default are observed by * OrderManager and OrderLineManager to enforce the validity of the state transitions. * * @param OrderInterface $order Order * @param OrderLineInterface $orderLine Orderline object * @param String $newState New state to append * * @return $this self Object */ public function addStateToOrderLine(OrderInterface $order, OrderLineInterface $orderLine, $newState) { $lastOrderLineHistory = $orderLine->getOrderLineHistories()->last(); $this->orderLineStateEventDispatcher->dispatchOrderLineStatePreChangeEvent($order, $orderLine, $lastOrderLineHistory, $newState); /** * @var OrderLineHistoryInterface $orderLineHistory */ $orderLineHistory = $this->orderLineHistoryFactory->create(); $orderLineHistory->setState($newState)->setOrderLine($orderLine); $orderLine->addOrderLineHistory($orderLineHistory)->setLastOrderLineHistory($orderLineHistory); $this->orderLineStateEventDispatcher->dispatchOrderLineStateOnChangeEvent($order, $orderLine, $lastOrderLineHistory, $orderLineHistory, $newState); return $this; }