public function testGetList() { $productSku = 'downloadable_sku'; $sampleData = ['id' => 324, 'store_title' => 'rock melody sample', 'title' => 'just melody sample', 'sort_order' => 21, 'sample_type' => 'file', 'sample_url' => null, 'sample_file' => '/r/o/rock.melody.ogg']; $sampleMock = $this->getMock('\\Magento\\Downloadable\\Model\\Sample', ['getId', 'getStoreTitle', 'getTitle', 'getSampleType', 'getSampleFile', 'getSampleUrl', 'getSortOrder', 'getData', '__wakeup'], [], '', false); $sampleInterfaceMock = $this->getMock('\\Magento\\Downloadable\\Api\\Data\\SampleInterface'); $this->repositoryMock->expects($this->once())->method('get')->with($productSku)->will($this->returnValue($this->productMock)); $this->productTypeMock->expects($this->once())->method('getSamples')->with($this->productMock)->will($this->returnValue([$sampleMock])); $this->setSampleAssertions($sampleMock, $sampleData); $this->sampleFactoryMock->expects($this->once())->method('create')->willReturn($sampleInterfaceMock); $this->assertEquals([$sampleInterfaceMock], $this->service->getList($productSku)); }
public function testGetProductInfo() { $productId = 3; $storeId = 1; $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue(new \Magento\Framework\Object(['id' => $storeId]))); $this->requestMock->expects($this->once())->method('getParam')->with('id', false)->willReturn($productId); $productMock = $this->getMock('Magento\\Catalog\\Api\\Data\\ProductInterface'); $this->productRepository->expects($this->once())->method('getById')->with($productId, false, $storeId)->willReturn($productMock); $this->assertSame($productMock, $this->object->getProductInfo()); }
protected function setUp() { $this->objectManager = new ObjectManager($this); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)->getMockForAbstractClass(); $this->productLinkRepositoryMock = $this->getMockBuilder(ProductLinkRepositoryInterface::class)->getMockForAbstractClass(); $this->productMock = $this->getMockBuilder(ProductInterface::class)->getMockForAbstractClass(); $this->collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->productRepositoryMock->expects($this->any())->method('getById')->willReturn($this->productMock); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock); }
protected function setUp() { $this->category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $productMethods = ['__wakeup', 'getData', 'getUrlKey', 'getName', 'formatUrlKey', 'getId', 'load', 'setStoreId']; $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', $productMethods, [], '', false); $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface'); $this->scopeConfig = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->categoryUrlPathGenerator = $this->getMock('Magento\\CatalogUrlRewrite\\Model\\CategoryUrlPathGenerator', [], [], '', false); $this->productRepository = $this->getMock('Magento\\Catalog\\Api\\ProductRepositoryInterface'); $this->productRepository->expects($this->any())->method('getById')->willReturn($this->product); $this->productUrlPathGenerator = (new ObjectManager($this))->getObject('Magento\\CatalogUrlRewrite\\Model\\ProductUrlPathGenerator', ['storeManager' => $this->storeManager, 'scopeConfig' => $this->scopeConfig, 'categoryUrlPathGenerator' => $this->categoryUrlPathGenerator, 'productRepository' => $this->productRepository]); }
public function testAfterInitialize() { $productMock = $this->getProductMock(); $configurableMatrix = [['newProduct' => true, 'id' => 'product1'], ['newProduct' => false, 'id' => 'product2', 'status' => 'simple2_status', 'sku' => 'simple2_sku', 'name' => 'simple2_name', 'price' => '3.33', 'configurable_attribute' => 'simple2_configurable_attribute', 'weight' => '5.55', 'media_gallery' => 'simple2_media_gallery', 'swatch_image' => 'simple2_swatch_image', 'small_image' => 'simple2_small_image', 'thumbnail' => 'simple2_thumbnail', 'image' => 'simple2_image'], ['newProduct' => false, 'id' => 'product3', 'qty' => '3']]; $configurations = ['product2' => ['status' => 'simple2_status', 'sku' => 'simple2_sku', 'name' => 'simple2_name', 'price' => '3.33', 'configurable_attribute' => 'simple2_configurable_attribute', 'weight' => '5.55', 'media_gallery' => 'simple2_media_gallery', 'swatch_image' => 'simple2_swatch_image', 'small_image' => 'simple2_small_image', 'thumbnail' => 'simple2_thumbnail', 'image' => 'simple2_image'], 'product3' => ['quantity_and_stock_status' => ['qty' => '3']]]; /** @var Product[]|\PHPUnit_Framework_MockObject_MockObject[] $productMocks */ $productMocks = ['product2' => $this->getProductMock($configurations['product2'], true), 'product3' => $this->getProductMock($configurations['product3'])]; $this->requestMock->expects(static::any())->method('getParam')->willReturnMap([['store', 0, 0], ['configurable-matrix', [], $configurableMatrix]]); $this->variationHandlerMock->expects(static::once())->method('duplicateImagesForVariations')->with($configurations)->willReturn($configurations); $this->productRepositoryMock->expects(static::any())->method('getById')->willReturnMap([['product2', false, 0, false, $productMocks['product2']], ['product3', false, 0, false, $productMocks['product3']]]); $this->variationHandlerMock->expects(static::any())->method('processMediaGallery')->willReturnMap([[$productMocks['product2'], $configurations['product2'], $configurations['product2']], [$productMocks['product3'], $configurations['product3'], $configurations['product3']]]); $this->assertSame($productMock, $this->updateConfigurations->afterInitialize($this->subjectMock, $productMock)); }
protected function createSwatchProduct($product) { if (gettype($product) == 'integer') { $this->productRepoMock->expects($this->any())->method('getById')->with(95)->willReturn($this->productMock); } $this->getSwatchAttributes(); }
public function testAroundSave() { $productId = 5494; $websiteId = 1; $storeId = 2; $sku = 'my product that needs saving'; $defaultScopeId = 100; $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn($defaultScopeId); $this->stockRegistry->expects($this->once())->method('getStock')->with($defaultScopeId)->willReturn($this->defaultStock); $this->product->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtension); $this->productExtension->expects($this->once())->method('getStockItem')->willReturn($this->stockItem); $storedStockItem = $this->getMockBuilder(StockItemInterface::class)->setMethods(['getItemId'])->getMockForAbstractClass(); $storedStockItem->expects($this->once())->method('getItemId')->willReturn(500); $this->stockRegistry->expects($this->once())->method('getStockItem')->willReturn($storedStockItem); $storeMock = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId); $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock); $this->product->expects($this->exactly(2))->method('getId')->willReturn($productId); $this->product->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId); $this->product->expects($this->atLeastOnce())->method('getSku')->willReturn($sku); $this->stockItem->expects($this->once())->method('setProductId')->with($productId); $this->stockItem->expects($this->once())->method('setWebsiteId')->with($websiteId); $this->stockRegistry->expects($this->once())->method('updateStockItemBySku')->with($sku, $this->stockItem); $newProductMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->disableOriginalConstructor()->getMock(); $this->productRepository->expects($this->once())->method('get')->with($sku, false, $storeId, true)->willReturn($newProductMock); $this->assertEquals($newProductMock, $this->plugin->aroundSave($this->productRepository, $this->closure, $this->product)); }
protected function setUp() { $this->objectManager = new ObjectManager($this); $this->locatorMock = $this->getMockBuilder(LocatorInterface::class)->getMockForAbstractClass(); $this->productMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['getId', 'getTypeId'])->getMockForAbstractClass(); $this->productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID); $this->productMock->expects($this->any())->method('getTypeId')->willReturn(GroupedProductType::TYPE_CODE); $this->linkedProductMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['getId', 'getName', 'getPrice'])->getMockForAbstractClass(); $this->linkedProductMock->expects($this->any())->method('getId')->willReturn(self::LINKED_PRODUCT_ID); $this->linkedProductMock->expects($this->any())->method('getName')->willReturn(self::LINKED_PRODUCT_NAME); $this->linkedProductMock->expects($this->any())->method('getPrice')->willReturn(self::LINKED_PRODUCT_PRICE); $this->linkMock = $this->getMockBuilder(ProductLinkInterface::class)->setMethods(['getLinkType', 'getLinkedProductSku', 'getPosition', 'getExtensionAttributes'])->getMockForAbstractClass(); $this->linkExtensionMock = $this->getMockBuilder(ProductLinkExtensionInterface::class)->setMethods(['getQty'])->getMockForAbstractClass(); $this->linkExtensionMock->expects($this->any())->method('getQty')->willReturn(self::LINKED_PRODUCT_QTY); $this->linkMock->expects($this->any())->method('getExtensionAttributes')->willReturn($this->linkExtensionMock); $this->linkMock->expects($this->any())->method('getPosition')->willReturn(self::LINKED_PRODUCT_POSITION); $this->linkMock->expects($this->any())->method('getLinkedProductSku')->willReturn(self::LINKED_PRODUCT_SKU); $this->linkMock->expects($this->any())->method('getLinkType')->willReturn(Grouped::LINK_TYPE); $this->linkRepositoryMock = $this->getMockBuilder(ProductLinkRepositoryInterface::class)->setMethods(['getList'])->getMockForAbstractClass(); $this->linkRepositoryMock->expects($this->any())->method('getList')->with($this->productMock)->willReturn([$this->linkMock]); $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)->setMethods(['get'])->getMockForAbstractClass(); $this->productRepositoryMock->expects($this->any())->method('get')->with(self::LINKED_PRODUCT_SKU)->willReturn($this->linkedProductMock); $this->storeMock = $this->getMockBuilder(StoreInterface::class)->setMethods(['getId'])->getMockForAbstractClass(); $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock); $this->locatorMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); }
public function testItEnablesADisabledProduct() { $mockProduct = $this->createMockDisabledProduct('test'); $mockProduct->expects($this->once())->method('setStatus')->with(ProductStatus::STATUS_ENABLED); $this->mockProductRepository->method('get')->willReturn($mockProduct); $this->mockProductRepository->expects($this->once())->method('save')->with($mockProduct); $this->productStatusAdapter->enableProductWithSku('test'); }
public function testGetProduct() { $productId = 1; $storeId = 0; $this->model->setData('product_id', $productId); $this->model->setData('store_id', $storeId); $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $productMock->expects($this->any())->method('setFinalPrice')->with(null); $productMock->expects($this->any())->method('setCustomOprtions')->with([]); $this->productRepository->expects($this->once())->method('getById')->willReturn($productMock); $this->assertEquals($productMock, $this->model->getProduct()); }
public function testGetList() { $productSku = 'downloadable_sku'; $linkData = ['id' => 324, 'store_title' => 'rock melody', 'title' => 'just melody', 'price' => 23, 'number_of_downloads' => 3, 'sort_order' => 21, 'is_shareable' => 2, 'sample_type' => 'file', 'sample_url' => null, 'sample_file' => '/r/o/rock.melody.ogg', 'link_type' => 'url', 'link_url' => 'http://link.url', 'link_file' => null]; $linkMock = $this->getMock('Magento\\Downloadable\\Model\\Link', ['getId', 'getStoreTitle', 'getTitle', 'getPrice', 'getNumberOfDownloads', 'getSortOrder', 'getIsShareable', 'getData', '__wakeup', 'setId'], [], '', false); $linkInterfaceMock = $this->getMock('\\Magento\\Downloadable\\Api\\Data\\LinkInterface'); $this->repositoryMock->expects($this->once())->method('get')->with($productSku)->will($this->returnValue($this->productMock)); $this->productTypeMock->expects($this->once())->method('getLinks')->with($this->productMock)->will($this->returnValue([$linkMock])); $this->setLinkAssertions($linkMock, $linkData); $this->linkFactoryMock->expects($this->once())->method('create')->willReturn($linkInterfaceMock); $this->assertEquals([$linkInterfaceMock], $this->service->getList($productSku)); }
public function testExecuteWithNonVisibleProduct() { $productId = 11; $this->requestMock->expects($this->once())->method('getParam')->with('id', null)->willReturn($productId); /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */ $productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog'])->getMockForAbstractClass(); $this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock); $productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(false); /** @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject $forwardMock */ $forwardMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Forward')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_FORWARD, [])->willReturn($forwardMock); $forwardMock->expects($this->once())->method('forward')->with('noroute')->willReturnSelf(); $this->assertEquals($forwardMock, $this->model->execute()); }
public function testGetProductByAttributesReturnFirstItem() { $productMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'hasData', 'getData', 'getResource', 'getAttributeSetId'])->disableOriginalConstructor()->getMock(); $firstItemMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'getId'])->disableOriginalConstructor()->getMock(); $productCollection = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Resource\\Product\\Type\\Configurable\\Product\\Collection')->setMethods(['setFlag', 'setProductFilter', 'addStoreFilter', 'addAttributeToSelect', 'addAttributeToFilter', 'getFirstItem'])->disableOriginalConstructor()->getMock(); $this->_productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($productCollection)); $productCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf()); $productCollection->expects($this->any())->method('setFlag')->will($this->returnSelf()); $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollection->expects($this->any())->method('addAttributeToFilter')->will($this->returnSelf()); $productCollection->expects($this->once())->method('getFirstItem')->willReturn($firstItemMock); $firstItemMock->expects($this->any())->method('getId')->willReturn(3); $this->productRepository->expects($this->once())->method('getById')->with(3)->willReturn($firstItemMock); $this->assertEquals($firstItemMock, $this->_model->getProductByAttributes($this->attributeData, $productMock)); }
public function testGetProductsWithFilter() { $products = ['Product1', 'Product2']; $searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\SearchCriteriaInterface')->getMockForAbstractClass(); $this->request->expects($this->exactly(2))->method('getParam')->with($this->equalTo('type'))->willReturn('FilterProductType'); $this->filterBuilder->expects($this->once())->method('setField')->with('type_id')->willReturnSelf(); $this->filterBuilder->expects($this->once())->method('setValue')->with($this->equalTo('FilterProductType'))->willReturnSelf(); $filter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->getMock(); $this->filterBuilder->expects($this->once())->method('create')->willReturn($filter); $this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with($this->equalTo([$filter]))->willReturnSelf(); $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria); $this->productRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($products); $result = $this->block->getProducts(); $this->assertEquals($products, $result); }
/** * @dataProvider dataForMediaGallery */ public function testGetProductMediaGallery($mediaGallery, $image) { $this->productMock->expects($this->once())->method('getMediaAttributeValues')->willReturn($mediaGallery); $this->productMock->expects($this->any())->method('getId')->willReturn(95); $this->imageHelperMock->expects($this->any())->method('init')->willReturnMap([[$this->productMock, 'product_page_image_large', [], $this->imageHelperMock], [$this->productMock, 'product_page_image_medium', [], $this->imageHelperMock], [$this->productMock, 'product_page_image_small', [], $this->imageHelperMock]]); $this->imageHelperMock->expects($this->any())->method('setImageFile')->with($image)->willReturnSelf(); $this->imageHelperMock->expects($this->any())->method('constrainOnly')->willReturnSelf(); $this->imageHelperMock->expects($this->any())->method('keepAspectRatio')->willReturnSelf(); $this->imageHelperMock->expects($this->any())->method('keepFrame')->willReturnSelf(); $this->imageHelperMock->expects($this->any())->method('getUrl')->willReturn('http://full_path_to_image/magento1.png'); $this->productRepoMock->expects($this->any())->method('getById')->with(95)->willReturn($this->productMock); $mediaObject = $this->getMock('\\Magento\\Framework\\DataObject', [], [], '', false); $iterator = new \ArrayIterator([$mediaObject]); $mediaCollectionMock = $this->getMock('\\Magento\\Framework\\Data\\Collection', [], [], '', false); $mediaCollectionMock->expects($this->any())->method('getIterator')->willReturn($iterator); $mediaObject->method('getData')->withConsecutive(['value_id'], ['file'])->willReturnOnConsecutiveCalls(0, $image); $this->productMock->method('getMediaGalleryImages')->willReturn($mediaCollectionMock); $this->swatchHelperObject->getProductMediaGallery($this->productMock); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecuteWithoutData() { $productId = 11; $formData = ''; /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); /** @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject $forwardMock */ $forwardMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Forward')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->exactly(2))->method('create')->willReturnMap([[\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [], $redirectMock], [\Magento\Framework\Controller\ResultFactory::TYPE_FORWARD, [], $forwardMock]]); $this->validatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true); $this->requestMock->expects($this->once())->method('getParam')->willReturnMap([['id', null, $productId]]); /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */ $productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])->getMockForAbstractClass(); $this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock); $productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(true); $this->registryMock->expects($this->once())->method('register')->willReturnMap([['product', $productMock, false, null]]); $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($formData); $forwardMock->expects($this->once())->method('forward')->with('noroute')->willReturnSelf(); $this->assertEquals($forwardMock, $this->model->execute()); }
public function testAroundSave() { $productId = 5494; $websiteId = 1; $storeId = 2; $sku = 'my product that needs saving'; $this->productMock->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtensionMock); $this->productExtensionMock->expects($this->once())->method('getStockItem')->willReturn($this->stockItemMock); $storeMock = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId); $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock); $this->savedProductMock->expects($this->once())->method('getId')->willReturn($productId); $this->savedProductMock->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId); $this->savedProductMock->expects($this->atLeastOnce())->method('getSku')->willReturn($sku); $this->stockItemMock->expects($this->once())->method('setProductId')->with($productId); $this->stockItemMock->expects($this->once())->method('setWebsiteId')->with($websiteId); $this->stockRegistry->expects($this->once())->method('updateStockItemBySku')->with($sku, $this->stockItemMock); $newProductMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->disableOriginalConstructor()->getMock(); $this->productRepositoryMock->expects($this->once())->method('get')->with($sku, false, $storeId, true)->willReturn($newProductMock); $this->assertEquals($newProductMock, $this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock)); }
/** * @param int|\Magento\Wishlist\Model\Item|\PHPUnit_Framework_MockObject_MockObject $itemId * @param \Magento\Framework\Object $buyRequest * @param null|array|\Magento\Framework\Object $param * @throws \Magento\Framework\Exception\LocalizedException * * @dataProvider updateItemDataProvider */ public function testUpdateItem($itemId, $buyRequest, $param) { $storeId = 1; $productId = 1; $stores = [(new \Magento\Framework\Object())->setId($storeId)]; $newItem = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->getMock(); $newItem->expects($this->any())->method('setProductId')->will($this->returnSelf()); $newItem->expects($this->any())->method('setWishlistId')->will($this->returnSelf()); $newItem->expects($this->any())->method('setStoreId')->will($this->returnSelf()); $newItem->expects($this->any())->method('setOptions')->will($this->returnSelf()); $newItem->expects($this->any())->method('setProduct')->will($this->returnSelf()); $newItem->expects($this->any())->method('setQty')->will($this->returnSelf()); $newItem->expects($this->any())->method('getItem')->will($this->returnValue(2)); $this->itemFactory->expects($this->once())->method('create')->will($this->returnValue($newItem)); $this->storeManager->expects($this->any())->method('getStores')->will($this->returnValue($stores)); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($stores[0])); $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $product->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $instanceType = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\AbstractType')->disableOriginalConstructor()->getMock(); $instanceType->expects($this->once())->method('processConfiguration')->will($this->returnValue($this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock())); $newProduct = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $newProduct->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $newProduct->expects($this->once())->method('getTypeInstance')->will($this->returnValue($instanceType)); $item = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->getMock(); $item->expects($this->once())->method('getProduct')->will($this->returnValue($product)); $items = $this->getMockBuilder('Magento\\Wishlist\\Model\\Resource\\Item\\Collection')->disableOriginalConstructor()->getMock(); $items->expects($this->once())->method('addWishlistFilter')->will($this->returnSelf()); $items->expects($this->once())->method('addStoreFilter')->will($this->returnSelf()); $items->expects($this->once())->method('setVisibilityFilter')->will($this->returnSelf()); $items->expects($this->once())->method('getItemById')->will($this->returnValue($item)); $items->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$item]))); $this->itemsFactory->expects($this->any())->method('create')->will($this->returnValue($items)); $this->productRepository->expects($this->once())->method('getById')->with($productId, false, $storeId)->will($this->returnValue($newProduct)); $this->assertInstanceOf('Magento\\Wishlist\\Model\\Wishlist', $this->wishlist->updateItem($itemId, $buyRequest, $param)); }