/** * @expectedException \Magento\Framework\Exception\CouldNotDeleteException */ public function testDeleteByIdException() { $id = 1; $this->stockStatusFactoryMock->expects($this->once())->method('create')->willReturn($this->stockStatusMock); $this->stockStatusResourceMock->expects($this->once())->method('load')->with($this->stockStatusMock, $id); $this->stockStatusResourceMock->expects($this->once())->method('delete')->with($this->stockStatusMock)->willThrowException(new \Exception()); $this->assertTrue($this->model->deleteById($id)); }
/** * @param StockStatusInterface $stockStatus * @return bool|true * @throws CouldNotDeleteException */ public function delete(StockStatusInterface $stockStatus) { try { $this->resource->delete($stockStatus); } catch (\Exception $exception) { throw new CouldNotDeleteException(__($exception->getMessage())); } return true; }
/** * @param StockStatusInterface $stockStatus * @return bool|true * @throws CouldNotDeleteException */ public function delete(StockStatusInterface $stockStatus) { try { $this->resource->delete($stockStatus); $this->getStockRegistryStorage()->removeStockStatus($stockStatus->getProductId()); } catch (\Exception $exception) { throw new CouldNotDeleteException(__('Unable to remove Stock Status for product %1', $stockStatus->getProductId()), $exception); } return true; }