public function testGetUsedProducts() { $attributeCollection = $this->getMockBuilder('\\Magento\\ConfigurableProduct\\Model\\Resource\\Product\\Type\\Configurable\\Attribute\\Collection')->setMethods(['setProductFilter', 'addFieldToFilter', 'walk'])->disableOriginalConstructor()->getMock(); $attributeCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf()); $this->_attributeCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($attributeCollection)); $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['dataHasChangedFor', 'getConfigurableAttributesData', 'getStoreId', 'getId', 'getData', 'hasData', 'getAssociatedProductIds', '__wakeup', '__sleep'])->disableOriginalConstructor()->getMock(); $product->expects($this->any())->method('getConfigurableAttributesData')->will($this->returnValue($this->attributeData)); $product->expects($this->any())->method('getStoreId')->will($this->returnValue(5)); $product->expects($this->any())->method('getId')->will($this->returnValue(1)); $product->expects($this->any())->method('getAssociatedProductIds')->will($this->returnValue([2])); $product->expects($this->any())->method('hasData')->will($this->returnValueMap([['_cache_instance_used_product_attribute_ids', 1], ['_cache_instance_products', 0], ['_cache_instance_configurable_attributes', 1]])); $product->expects($this->any())->method('getData')->will($this->returnValue(1)); $productCollection = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Resource\\Product\\Type\\Configurable\\Product\\Collection')->setMethods(['setFlag', 'setProductFilter', 'addStoreFilter', 'addAttributeToSelect', 'addFilterByRequiredOptions', 'setStoreId'])->disableOriginalConstructor()->getMock(); $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf()); $productCollection->expects($this->any())->method('setFlag')->will($this->returnSelf()); $productCollection->expects($this->any())->method('addFilterByRequiredOptions')->will($this->returnSelf()); $productCollection->expects($this->any())->method('setStoreId')->with(5)->will($this->returnValue([])); $this->_productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($productCollection)); $this->_model->getUsedProducts($product); }