/**
  * @expectedException \Magento\Framework\Exception\CouldNotSaveException
  * @expectedExceptionMessage Could not save credit memo
  */
 public function testSaveWithException()
 {
     $entity = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->getMock();
     $entity->expects($this->never())->method('getEntityId');
     $mapper = $this->getMockBuilder('Magento\\Sales\\Model\\ResourceModel\\Order\\Creditmemo')->disableOriginalConstructor()->getMock();
     $mapper->expects($this->once())->method('save')->willThrowException(new \Exception('error'));
     $this->metadataMock->expects($this->any())->method('getMapper')->willReturn($mapper);
     $this->assertEquals($entity, $this->creditmemo->save($entity));
 }
 /**
  * Perform persist operations for one entity
  *
  * @param OrderItemInterface $entity
  * @return OrderItemInterface
  */
 public function save(OrderItemInterface $entity)
 {
     if ($entity->getProductOption()) {
         $request = $this->getBuyRequest($entity);
         $entity->setProductOptions(['info_buyRequest' => $request->toArray()]);
     }
     $this->metadata->getMapper()->save($entity);
     $this->registry[$entity->getEntityId()] = $entity;
     return $this->registry[$entity->getEntityId()];
 }
 /**
  * Performs persist operations for a specified credit memo.
  *
  * @param \Magento\Sales\Api\Data\CreditmemoInterface $entity The credit memo.
  * @return \Magento\Sales\Api\Data\CreditmemoInterface Credit memo interface.
  * @throws CouldNotSaveException
  */
 public function save(\Magento\Sales\Api\Data\CreditmemoInterface $entity)
 {
     try {
         $this->metadata->getMapper()->save($entity);
         $this->registry[$entity->getEntityId()] = $entity;
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not save credit memo'), $e);
     }
     return $this->registry[$entity->getEntityId()];
 }
 public function testDeleteById()
 {
     $orderItemId = 1;
     $productType = 'configurable';
     $requestMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $orderItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->getMock();
     $orderItemMock->expects($this->once())->method('load')->with($orderItemId)->willReturn($orderItemMock);
     $orderItemMock->expects($this->once())->method('getItemId')->willReturn($orderItemId);
     $orderItemMock->expects($this->once())->method('getProductType')->willReturn($productType);
     $orderItemMock->expects($this->once())->method('getBuyRequest')->willReturn($requestMock);
     $orderItemResourceMock = $this->getMockBuilder('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb')->disableOriginalConstructor()->getMock();
     $orderItemResourceMock->expects($this->once())->method('delete')->with($orderItemMock)->willReturnSelf();
     $this->metadata->expects($this->once())->method('getNewInstance')->willReturn($orderItemMock);
     $this->metadata->expects($this->exactly(1))->method('getMapper')->willReturn($orderItemResourceMock);
     $model = $this->getModel($orderItemMock, $productType);
     $this->assertTrue($model->deleteById($orderItemId));
 }
 public function testCreate()
 {
     $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', [], [], '', false);
     $this->metadata->expects($this->once())->method('getNewInstance')->willReturn($shipment);
     $this->assertEquals($shipment, $this->subject->create());
 }
 /**
  * Perform persist operations for one entity
  *
  * @param \Magento\Sales\Api\Data\InvoiceInterface $entity
  * @return \Magento\Sales\Api\Data\InvoiceInterface
  */
 public function save(\Magento\Sales\Api\Data\InvoiceInterface $entity)
 {
     $this->metadata->getMapper()->save($entity);
     $this->registry[$entity->getEntityId()] = $entity;
     return $this->registry[$entity->getEntityId()];
 }
 /**
  * Creates new order address instance.
  *
  * @return \Magento\Sales\Api\Data\OrderAddressInterface
  */
 public function create()
 {
     return $this->metadata->getNewInstance();
 }
 public function testCreate()
 {
     $address = $this->getMock('Magento\\Sales\\Model\\Order\\Address', ['getEntityId'], [], '', false);
     $this->metadata->expects($this->once())->method('getNewInstance')->willReturn($address);
     $this->assertEquals($address, $this->subject->create());
 }