/** * @covers \Magento\ConfigurableProduct\Helper\Product\Options\Loader::load */ public function testLoad() { $option = ['value_index' => 23]; $this->product->expects(static::once())->method('getTypeInstance')->willReturn($this->configurable); $attribute = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->setMethods(['getOptions', 'setValues'])->getMock(); $attributes = [$attribute]; $iterator = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $iterator->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator($attributes)); $this->configurable->expects(static::once())->method('getConfigurableAttributeCollection')->with($this->product)->willReturn($iterator); $attribute->expects(static::once())->method('getOptions')->willReturn([$option]); $optionValue = $this->getMockForAbstractClass(OptionValueInterface::class); $this->optionValueFactory->expects(static::once())->method('create')->willReturn($optionValue); $optionValue->expects(static::once())->method('setValueIndex')->with($option['value_index']); $attribute->expects(static::once())->method('setValues')->with([$optionValue]); $options = $this->loader->load($this->product); static::assertSame([$attribute], $options); }
/** * @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); }