protected function setUp() { $helper = new ObjectManager($this); $this->configurableAttribute = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute')->setMethods(['setData', 'getData', 'addData', '__wakeup', 'getId', 'setId', 'getAttributeId', 'setAttributeId', 'setValues'])->disableOriginalConstructor()->getMock(); $this->option = $this->getMockBuilder('Magento\\ConfigurableProduct\\Service\\V1\\Data\\Option')->setMethods(['__toArray', 'getValues', 'getAttributeId', 'getPosition', 'isUseDefault', 'getLabel'])->disableOriginalConstructor()->getMock(); $this->valueConverter = $this->getMockBuilder('Magento\\ConfigurableProduct\\Service\\V1\\Data\\Option\\ValueConverter')->setMethods(['convertArrayFromData'])->disableOriginalConstructor()->getMock(); $this->value = $this->getMockBuilder('Magento\\ConfigurableProduct\\Service\\V1\\Data\\Option\\Value')->disableOriginalConstructor()->getMock(); $this->attributeFactory = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\AttributeFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->attributeFactory->expects($this->any())->method('create')->will($this->returnValue($this->configurableAttribute)); $this->converter = $helper->getObject('Magento\\ConfigurableProduct\\Service\\V1\\Data\\OptionConverter', ['attributeFactory' => $this->attributeFactory, 'valueConverter' => $this->valueConverter]); }
/** * @expectedException \Magento\Framework\Exception\NoSuchEntityException */ public function testUpdateNoSuchEntityException() { $productSku = 'productSku'; $optionId = 3; $this->productRepositoryMock->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->productMock)); $this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(ConfigurableType::TYPE_CODE)); $this->confAttributeFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->attributeMock)); $this->attributeMock->expects($this->once())->method('load')->with($this->equalTo($optionId)); $this->attributeMock->expects($this->any())->method('getId')->will($this->returnValue(0)); $this->writeService->update($productSku, $optionId, $this->optionMock); }
/** * @covers \Magento\ConfigurableProduct\Helper\Product\Options\Factory::create */ public function testCreate() { $attributeId = 90; $valueIndex = 12; $item = ['attribute_id' => $attributeId, 'values' => [['value_index' => $valueIndex]]]; $data = [$item]; $attribute = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->setMethods(['setValues', 'setData', '__wakeup'])->getMock(); $this->attributeFactory->expects(static::once())->method('create')->willReturn($attribute); $eavAttribute = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock(); $this->productAttributeRepository->expects(static::once())->method('get')->with($attributeId)->willReturn($eavAttribute); $this->configurable->expects(static::once())->method('canUseAttribute')->with($eavAttribute)->willReturn(true); $option = $this->getMock(OptionValueInterface::class); $option->expects(static::once())->method('setValueIndex')->with($valueIndex)->willReturnSelf(); $this->optionValueFactory->expects(static::once())->method('create')->willReturn($option); $attribute->expects(static::once())->method('setData')->with($item); $attribute->expects(static::once())->method('setValues')->with([$option]); $result = $this->factory->create($data); static::assertSame([$attribute], $result); }