/** * @expectedException \Magento\Framework\Exception\NoSuchEntityException */ public function testRemoveNoSuchEntityException() { $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->productTypeMock->expects($this->once())->method('getConfigurableAttributeCollection')->with($this->equalTo($this->productMock))->will($this->returnValue($this->attributeCollectionMock)); $this->attributeCollectionMock->expects($this->once())->method('getItemById')->with($this->equalTo($optionId))->will($this->returnValue(null)); $this->writeService->remove($productSku, $optionId); }
/** * @expectedException \Magento\Framework\Exception\NoSuchEntityException * @expectedExceptionMessage Requested option doesn't exist: 3 */ public function testGetNoSuchEntityException() { $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)->will($this->returnSelf()); $this->configurableAttributeCollection->expects($this->once())->method('getFirstItem')->will($this->returnValue($this->option)); $this->option->expects($this->once())->method('getId')->will($this->returnValue(null)); $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->model->get($productSku, $optionId); }