orderItemMock = $this->createPartialMock( \Magento\Sales\Model\Order\Item::class, ['setGiftMessageId', 'setGiftMessageAvailable', '__wakeup'] ); $this->quoteItemMock = $this->createPartialMock( \Magento\Quote\Model\Quote\Item::class, ['getGiftMessageId', 'getStoreId', '__wakeup'] ); $orderItems = $this->orderItemMock; $this->closureMock = function () use ($orderItems) { return $orderItems; }; $this->subjectMock = $this->createMock(\Magento\Quote\Model\Quote\Item\ToOrderItem::class); $this->helperMock = $this->createPartialMock( \Magento\GiftMessage\Helper\Message::class, ['setGiftMessageId', 'isMessagesAllowed'] ); $this->model = new \Magento\GiftMessage\Model\Plugin\QuoteItem($this->helperMock); } public function testAfterItemToOrderItem() { $storeId = 1; $giftMessageId = 1; $isMessageAvailable = true; $this->quoteItemMock->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $this->quoteItemMock->expects( $this->any() )->method( 'getGiftMessageId' )->will( $this->returnValue($giftMessageId) ); $this->helperMock->expects( $this->once() )->method( 'isMessagesAllowed' )->with( 'item', $this->quoteItemMock, $storeId )->will( $this->returnValue($isMessageAvailable) ); $this->orderItemMock->expects($this->once())->method('setGiftMessageId')->with($giftMessageId); $this->orderItemMock->expects($this->once())->method('setGiftMessageAvailable')->with($isMessageAvailable); $this->assertSame( $this->orderItemMock, $this->model->afterConvert($this->subjectMock, $this->orderItemMock, $this->quoteItemMock, []) ); } }