示例#1
0
 /**
  * @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();
 }