Esempio n. 1
0
 public function testGet()
 {
     $productSku = 'oneSku';
     $optionId = 3;
     $this->productRepository->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(ConfigurableType::TYPE_CODE));
     $this->productType->expects($this->once())->method('getConfigurableAttributeCollection')->with($this->equalTo($this->product))->will($this->returnValue($this->configurableAttributeCollection));
     $this->configurableAttributeCollection->expects($this->once())->method('addFieldToFilter')->with(self::ATTRIBUTE_ID_FIELD_NAME, $optionId);
     $this->configurableAttributeCollection->expects($this->once())->method('getFirstItem')->will($this->returnValue($this->option));
     $this->option->expects($this->once())->method('getId')->will($this->returnValue($optionId));
     $this->attributeResource->expects($this->once())->method('getIdFieldName')->will($this->returnValue(self::ATTRIBUTE_ID_FIELD_NAME));
     $this->configurableAttributeCollection->expects($this->once())->method('getResource')->will($this->returnValue($this->attributeResource));
     $this->optionConverter->expects($this->once())->method('convertFromModel')->with($this->equalTo($this->option))->will($this->returnValue($this->metadata));
     $this->assertEquals($this->metadata, $this->model->get($productSku, $optionId));
 }
 /**
  * #@expectedException \Magento\Framework\Exception\CouldNotSaveException
  */
 public function testUpdateCouldNotSaveException()
 {
     $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->productMock->expects($this->any())->method('getId')->will($this->returnValue($optionId));
     $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($optionId));
     $this->attributeMock->expects($this->any())->method('getProductId')->will($this->returnValue($optionId));
     $this->attributeMock->expects($this->any())->method('save')->will($this->returnCallback(function () {
         throw new \Exception();
     }));
     $this->optionConverterMock->expects($this->once())->method('getModelFromData')->with($this->equalTo($this->optionMock), $this->equalTo($this->attributeMock))->will($this->returnValue($this->attributeMock));
     $this->writeService->update($productSku, $optionId, $this->optionMock);
 }