public function testUpdate()
 {
     $productSku = 'testProduct';
     $entryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface');
     $storeId = 0;
     $entryId = 42;
     $filePath = '/path/to/the/file.jpg';
     $entryPosition = 'entryPosition';
     $productMediaGalleryMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', ['addImage', 'updateImage', 'getRenamedImage', 'clearMediaAttribute', 'setMediaAttribute'], [], '', false);
     $attributeMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], [], '', false);
     $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId);
     $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)->willReturn($this->productMock);
     $this->productMock->expects($this->once())->method('getTypeInstance')->willReturnSelf();
     $this->productMock->expects($this->once())->method('getSetAttributes')->with($this->productMock)->willReturn(['media_gallery' => $attributeMock]);
     $attributeMock->expects($this->once())->method('getBackend')->willReturn($productMediaGalleryMock);
     $entryMock->expects($this->once())->method('getId')->willReturn($entryId);
     $this->entryResolverMock->expects($this->once())->method('getEntryFilePathById')->with($this->productMock, $entryId)->willReturn($filePath);
     $entryMock->expects($this->once())->method('isDisabled')->willReturn(false);
     $entryMock->expects($this->once())->method('getPosition')->willReturn($entryPosition);
     $entryMock->expects($this->once())->method('getLabel')->willReturn('entryLabel');
     $productMediaGalleryMock->expects($this->once())->method('updateImage')->with($this->productMock, $filePath, ['label' => 'entryLabel', 'position' => $entryPosition, 'disabled' => false]);
     $this->productMock->expects($this->once())->method('getMediaAttributes')->willReturn([]);
     $productMediaGalleryMock->expects($this->once())->method('clearMediaAttribute')->with($this->productMock, []);
     $entryMock->expects($this->once())->method('getTypes')->willReturn(['jpg']);
     $productMediaGalleryMock->expects($this->once())->method('setMediaAttribute')->with($this->productMock, ['jpg'], $filePath);
     $this->productMock->expects($this->once())->method('setStoreId')->with($storeId);
     $this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock);
     $this->assertTrue($this->model->update($productSku, $entryMock, $storeId));
 }
 public function testUpdate()
 {
     $productSku = 'testProduct';
     $entryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface');
     $entryId = 42;
     $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)->willReturn($this->productMock);
     $existingEntryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface');
     $existingEntryMock->expects($this->once())->method('getId')->willReturn($entryId);
     $this->productMock->expects($this->once())->method('getMediaGalleryEntries')->willReturn([$existingEntryMock]);
     $entryMock->expects($this->once())->method('getId')->willReturn($entryId);
     $this->productMock->expects($this->once())->method('setMediaGalleryEntries')->willReturn([$entryMock]);
     $this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock);
     $this->assertTrue($this->model->update($productSku, $entryMock));
 }