public function testGenerateVariation() { $data = ['someKey' => 'someValue']; $attributeOption = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Option', [], [], '', false); $attributeOption->expects($this->once())->method('getData')->willReturn(['key' => 'value']); $attribute = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $attribute->expects($this->any())->method('getOptions')->willReturn([$attributeOption]); $attribute->expects($this->once())->method('getAttributeCode')->willReturn(10); $this->option->expects($this->any())->method('getAttributeId')->willReturn(1); $this->attributeRepository->expects($this->once())->method('get')->with(1)->willReturn($attribute); $this->option->expects($this->any())->method('getData')->willReturn($data); $expectedAttributes = [1 => ['someKey' => 'someValue', 'options' => [['key' => 'value']], 'attribute_code' => 10]]; $this->productVariationBuilder->expects($this->once())->method('create')->with($this->product, $expectedAttributes)->willReturn(['someObject']); $expected = ['someObject']; $this->assertEquals($expected, $this->model->generateVariation($this->product, [$this->option])); }
/** * {@inheritdoc} */ public function generateVariation(ProductInterface $product, $options) { $attributes = $this->getAttributesForMatrix($options); $products = $this->productVariationBuilder->create($product, $attributes); return $products; }