/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Exception! */ public function testBeforeSaveWithException() { $value = 'value'; $groupId = 1; $field = 'field'; $tmpFileName = 'tmp_file_name'; $name = 'name'; $path = 'path'; $scope = 'scope'; $scopeId = 2; $uploadDir = 'upload_dir'; $fieldConfig = ['upload_dir' => $uploadDir]; $fileData = ['tmp_name' => $tmpFileName, 'name' => $name]; $exception = 'Exception!'; $this->model->setValue($value); $this->model->setPath($path); $this->model->setScope($scope); $this->model->setScopeId($scopeId); $this->model->setFieldConfig($fieldConfig); $_FILES['groups']['tmp_name'][$groupId]['fields'][$field]['value'] = $tmpFileName; $this->requestDataMock->expects($this->once())->method('getTmpName')->with($path)->willReturn($tmpFileName); $this->requestDataMock->expects($this->once())->method('getName')->with($path)->willReturn($name); $this->uploaderFactoryMock->expects($this->any())->method('create')->with(['fileId' => $fileData])->willReturn($this->uploaderMock); $this->uploaderMock->expects($this->once())->method('save')->with($uploadDir, null)->willThrowException(new \Exception($exception)); $this->model->beforeSave(); }
/** * @param Context $context * @param Registry $registry * @param ScopeConfigInterface $config * @param TypeListInterface $cacheTypeList * @param UploaderFactory $uploaderFactory * @param RequestDataInterface $requestData * @param Filesystem $filesystem * @param Config $imageConfig * @param AbstractResource|null $resource * @param AbstractDb|null $resourceCollection * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct(Context $context, Registry $registry, ScopeConfigInterface $config, TypeListInterface $cacheTypeList, UploaderFactory $uploaderFactory, RequestDataInterface $requestData, Filesystem $filesystem, Config $imageConfig, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = []) { parent::__construct($context, $registry, $config, $cacheTypeList, $uploaderFactory, $requestData, $filesystem, $resource, $resourceCollection, $data); $this->imageConfig = $imageConfig; }