/**
  * Test _beforeSaveMethod via save() with failed validation
  *
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Cannot save comment:
  */
 public function testSaveValidationFailed()
 {
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->commentModelMock)->willReturn(true);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->equalTo($this->commentModelMock))->will($this->returnValue(['warning message']));
     $this->commentResource->save($this->commentModelMock);
     $this->assertTrue(true);
 }
 public function testProcessRelation()
 {
     $this->invoiceMock->expects($this->once())->method('getId')->willReturn('invoice-id-value');
     $this->invoiceMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->invoiceItemMock]);
     $this->invoiceItemMock->expects($this->once())->method('setParentId')->with('invoice-id-value')->willReturnSelf();
     $this->invoiceItemMock->expects($this->once())->method('getOrderItem')->willReturn($this->orderItemMock);
     $this->invoiceItemMock->expects($this->once())->method('setOrderItem')->with($this->orderItemMock)->willReturnSelf();
     $this->invoiceItemResourceMock->expects($this->once())->method('save')->with($this->invoiceItemMock)->willReturnSelf();
     $this->invoiceMock->expects($this->exactly(2))->method('getComments')->willReturn([$this->invoiceCommentMock]);
     $this->invoiceCommentResourceMock->expects($this->once())->method('save')->with($this->invoiceCommentMock)->willReturnSelf();
     $this->relationProcessor->processRelation($this->invoiceMock);
 }
 /**
  * Process relations for Shipment
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return void
  * @throws \Exception
  */
 public function processRelation(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var $object \Magento\Sales\Model\Order\Invoice */
     if (null !== $object->getItems()) {
         foreach ($object->getItems() as $item) {
             /** @var \Magento\Sales\Model\Order\Invoice\Item */
             $item->setParentId($object->getId());
             $item->setOrderItem($item->getOrderItem());
             $this->invoiceItemResource->save($item);
         }
     }
     if (null !== $object->getComments()) {
         foreach ($object->getComments() as $comment) {
             /** @var \Magento\Sales\Model\Order\Invoice\Comment */
             $this->invoiceCommentResource->save($comment);
         }
     }
 }