itemRepositoryMock = $this->createMock(\Magento\Quote\Api\CartItemRepositoryInterface::class); $this->itemPoolMock = $this->createMock(\Magento\Checkout\CustomerData\ItemPoolInterface::class); $this->customerItem = $this->getMockBuilder(\Magento\Checkout\CustomerData\DefaultItem::class) ->disableOriginalConstructor() ->getMock(); $this->model = new \Magento\Checkout\Model\Cart\ImageProvider( $this->itemRepositoryMock, $this->itemPoolMock, $this->customerItem ); } public function testGetImages() { $cartId = 42; $itemId = 74; $itemData = ['product_image' => 'Magento.png', 'random' => '3.1415926535']; $itemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class); $itemMock->expects($this->once())->method('getItemId')->willReturn($itemId); $expectedResult = [$itemId => $itemData['product_image']]; $this->itemRepositoryMock->expects($this->once())->method('getList')->with($cartId)->willReturn([$itemMock]); $this->customerItem->expects($this->once())->method('getItemData')->with($itemMock)->willReturn($itemData); $this->assertEquals($expectedResult, $this->model->getImages($cartId)); } }