/**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGenerateSimpleProducts()
 {
     $productsData = [6 => ['image' => 'image.jpg', 'name' => 'config-red', 'configurable_attribute' => '{"new_attr":"6"}', 'sku' => 'config-red', 'quantity_and_stock_status' => ['qty' => ''], 'weight' => '333']];
     $stockData = ['manage_stock' => '0', 'use_config_enable_qty_increments' => '1', 'use_config_qty_increments' => '1', 'use_config_manage_stock' => 0, 'is_decimal_divided' => 0];
     $parentProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'getNewVariationsAttributeSetId', 'getStockData', 'getQuantityAndStockStatus', 'getWebsiteIds'])->disableOriginalConstructor()->getMock();
     $newSimpleProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'save', 'getId', 'setStoreId', 'setTypeId', 'setAttributeSetId', 'getTypeInstance', 'getStoreId', 'addData', 'setWebsiteIds', 'setStatus', 'setVisibility'])->disableOriginalConstructor()->getMock();
     $attributeMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['isInSet', 'setAttributeSetId', 'setAttributeGroupId', 'save'])->disableOriginalConstructor()->getMock();
     $attributeSetMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->setMethods(['load', 'addSetInfo', 'getDefaultGroupId'])->disableOriginalConstructor()->getMock();
     $eavEntityMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity')->setMethods(['setType', 'getTypeId'])->disableOriginalConstructor()->getMock();
     $productTypeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type')->setMethods(['getSetAttributes'])->disableOriginalConstructor()->getMock();
     $editableAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['getIsUnique', 'getAttributeCode', 'getFrontend', 'getIsVisible'])->disableOriginalConstructor()->getMock();
     $frontendAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend')->setMethods(['getInputType'])->disableOriginalConstructor()->getMock();
     $this->configurableProduct->expects($this->once())->method('getUsedProductAttributes')->willReturn([$attributeMock]);
     $parentProductMock->expects($this->any())->method('getNewVariationsAttributeSetId')->willReturn('new_attr_set_id');
     $this->_attributeSetFactory->expects($this->once())->method('create')->willReturn($attributeSetMock);
     $attributeSetMock->expects($this->once())->method('load')->with('new_attr_set_id')->willReturnSelf();
     $this->_entityFactoryMock->expects($this->once())->method('create')->willReturn($eavEntityMock);
     $eavEntityMock->expects($this->once())->method('setType')->with('catalog_product')->willReturnSelf();
     $eavEntityMock->expects($this->once())->method('getTypeId')->willReturn('type_id');
     $attributeSetMock->expects($this->once())->method('addSetInfo')->with('type_id', [$attributeMock]);
     $attributeMock->expects($this->once())->method('isInSet')->with('new_attr_set_id')->willReturn(false);
     $attributeMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $attributeSetMock->expects($this->once())->method('getDefaultGroupId')->with('new_attr_set_id')->willReturn('default_group_id');
     $attributeMock->expects($this->once())->method('setAttributeGroupId')->with('default_group_id')->willReturnSelf();
     $attributeMock->expects($this->once())->method('save')->willReturnSelf();
     $this->_productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
     $newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getTypeInstance')->willReturn($productTypeMock);
     $productTypeMock->expects($this->once())->method('getSetAttributes')->with($newSimpleProductMock)->willReturn([$editableAttributeMock]);
     $editableAttributeMock->expects($this->once())->method('getIsUnique')->willReturn(false);
     $editableAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn('some_code');
     $editableAttributeMock->expects($this->any())->method('getFrontend')->willReturn($frontendAttributeMock);
     $frontendAttributeMock->expects($this->any())->method('getInputType')->willReturn('input_type');
     $editableAttributeMock->expects($this->any())->method('getIsVisible')->willReturn(false);
     $parentProductMock->expects($this->once())->method('getStockData')->willReturn($stockData);
     $parentProductMock->expects($this->once())->method('getQuantityAndStockStatus')->willReturn(['is_in_stock' => 1]);
     $newSimpleProductMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
     $this->_stockConfiguration->expects($this->once())->method('getManageStock')->with('store_id')->willReturn(1);
     $newSimpleProductMock->expects($this->once())->method('addData')->willReturnSelf();
     $parentProductMock->expects($this->once())->method('getWebsiteIds')->willReturn('website_id');
     $newSimpleProductMock->expects($this->once())->method('setWebsiteIds')->with('website_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setVisibility')->with(1)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('save')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getId')->willReturn('product_id');
     $this->assertEquals(['product_id'], $this->_model->generateSimpleProducts($parentProductMock, $productsData));
 }
 public function testPrepareAttributeSet()
 {
     $productMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['getNewVariationsAttributeSetId'])->disableOriginalConstructor()->getMock();
     $attributeMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['isInSet', 'setAttributeSetId', 'setAttributeGroupId', 'save'])->disableOriginalConstructor()->getMock();
     $attributeSetMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->setMethods(['load', 'addSetInfo', 'getDefaultGroupId'])->disableOriginalConstructor()->getMock();
     $eavEntityMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity')->setMethods(['setType', 'getTypeId'])->disableOriginalConstructor()->getMock();
     $productMock->expects($this->once())->method('getNewVariationsAttributeSetId')->willReturn('new_attr_set_id');
     $this->configurableProduct->expects($this->once())->method('getUsedProductAttributes')->with($productMock)->willReturn([$attributeMock]);
     $this->attributeSetFactory->expects($this->once())->method('create')->willReturn($attributeSetMock);
     $attributeSetMock->expects($this->once())->method('load')->with('new_attr_set_id')->willReturnSelf();
     $this->entityFactoryMock->expects($this->once())->method('create')->willReturn($eavEntityMock);
     $eavEntityMock->expects($this->once())->method('setType')->with('catalog_product')->willReturnSelf();
     $eavEntityMock->expects($this->once())->method('getTypeId')->willReturn('type_id');
     $attributeSetMock->expects($this->once())->method('addSetInfo')->with('type_id', [$attributeMock]);
     $attributeMock->expects($this->once())->method('isInSet')->with('new_attr_set_id')->willReturn(false);
     $attributeMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $attributeSetMock->expects($this->once())->method('getDefaultGroupId')->with('new_attr_set_id')->willReturn('default_group_id');
     $attributeMock->expects($this->once())->method('setAttributeGroupId')->with('default_group_id')->willReturnSelf();
     $attributeMock->expects($this->once())->method('save')->willReturnSelf();
     $this->model->prepareAttributeSet($productMock);
 }