/**
  * @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));
 }
 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());
 }
 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());
 }