public function testSave() { $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn(null); $this->orderItemMock->expects($this->once())->method('getChildrenItems')->willReturn([]); $this->orderItemMock->expects($this->once())->method('getQuoteParentItemId')->willReturn(null); $this->orderMock->expects($this->once())->method('setTotalItemCount')->with(1); $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1); $this->orderMock->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]); $this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf(); $this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf(); $this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true); $this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order'); $this->orderMock->expects($this->exactly(2))->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->exactly(2))->method('getGroup')->willReturn($this->storeGroupMock); $this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock); $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1); $this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock); $this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001'); $this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf(); $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null); $this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']); $this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']); $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock); $this->adapterMock->expects($this->any())->method('quoteInto'); $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([])); $this->adapterMock->expects($this->any())->method('update'); $this->adapterMock->expects($this->any())->method('lastInsertId'); $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true)); $this->resource->save($this->orderMock); }
/** * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testSaveOrder() { $addressData = ['region' => 'CA', 'postcode' => '11111', 'lastname' => 'lastname', 'firstname' => 'firstname', 'street' => 'street', 'city' => 'Los Angeles', 'email' => '*****@*****.**', 'telephone' => '11111111', 'country_id' => 'US']; $billingAddress = $this->objectManager->create('Magento\\Sales\\Model\\Order\\Address', ['data' => $addressData]); $billingAddress->setAddressType('billing'); $shippingAddress = clone $billingAddress; $shippingAddress->setId(null)->setAddressType('shipping'); $payment = $this->objectManager->create('Magento\\Sales\\Model\\Order\\Payment'); $payment->setMethod('checkmo'); /** @var \Magento\Sales\Model\Order\Item $orderItem */ $orderItem = $this->objectManager->create('Magento\\Sales\\Model\\Order\\Item'); $orderItem->setProductId(1)->setQtyOrdered(2)->setBasePrice(10)->setPrice(10)->setRowTotal(10); /** @var \Magento\Sales\Model\Order $order */ $order = $this->objectManager->create('Magento\\Sales\\Model\\Order'); $order->setIncrementId($this->orderIncrementId)->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING))->setSubtotal(100)->setBaseSubtotal(100)->setBaseGrandTotal(100)->setCustomerIsGuest(true)->setCustomerEmail('*****@*****.**')->setBillingAddress($billingAddress)->setShippingAddress($shippingAddress)->setStoreId($this->objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getId())->addItem($orderItem)->setPayment($payment); $this->resourceModel->save($order); $this->assertNotNull($order->getCreatedAt()); $this->assertNotNull($order->getUpdatedAt()); }
public function testSave() { $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock); $this->adapterMock->expects($this->any())->method('quoteInto'); $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([])); $this->adapterMock->expects($this->any())->method('update'); $this->adapterMock->expects($this->any())->method('lastInsertId'); $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->orderMock->expects($this->once())->method('hasDataChanges')->will($this->returnValue(true)); $this->resource->save($this->orderMock); }
public function testSave() { $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock); $this->adapterMock->expects($this->any())->method('quoteInto'); $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([])); $this->adapterMock->expects($this->any())->method('update'); $this->adapterMock->expects($this->any())->method('lastInsertId'); $this->addressHandlerMock->expects($this->once())->method('removeEmptyAddresses')->with($this->equalTo($this->orderMock))->will($this->returnSelf()); $this->stateHandlerMock->expects($this->once())->method('check')->with($this->equalTo($this->orderMock))->will($this->returnSelf()); $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->orderMock->expects($this->once())->method('getRelatedObjects')->willReturn([]); $this->resource->save($this->orderMock); }