public function testSetForItem() { $cartId = 665; $itemId = 1; $this->quoteRepositoryMock->expects($this->once())->method('get')->with($cartId)->will($this->returnValue($this->quoteMock)); $quoteItem = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Item', ['getIsVirtual', '__wakeup'], [], '', false); $this->quoteMock->expects($this->once())->method('getItemById')->with($itemId)->will($this->returnValue($quoteItem)); $quoteItem->expects($this->once())->method('getIsVirtual')->will($this->returnValue(0)); $this->quoteMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue($this->billingAddressMock)); $this->billingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(12)); $this->quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(13)); $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock)); $this->helperMock->expects($this->once())->method('getIsMessagesAvailable')->with('items', $this->quoteMock, $this->storeMock)->will($this->returnValue(true)); $this->giftMessageMock->expects($this->once())->method('getSender')->will($this->returnValue('sender')); $this->giftMessageMock->expects($this->once())->method('getRecipient')->will($this->returnValue('recipient')); $this->giftMessageMock->expects($this->once())->method('getMessage')->will($this->returnValue('Message')); $message['quote_item'][1] = ['from' => 'sender', 'to' => 'recipient', 'message' => 'Message']; $this->giftMessageManagerMock->expects($this->once())->method('add')->with($message, $this->quoteMock)->will($this->returnValue($this->giftMessageManagerMock)); $this->assertTrue($this->service->setForItem($cartId, $this->giftMessageMock, $itemId)); }