public function it_can_handle_exception_during_request(RequestInterface $request) { $path = '/path/to/a/file.ext'; $request->offsetGet('path')->willReturn($path); $request->getAcceptContentType()->willReturn('*/*'); $this->fileRepository->getByFullPath($path)->willThrow(new \RuntimeException()); $this->shouldThrow(ResponseException::class)->duringExecuteRequest($request); }
/** * @param UploadedFileInterface[] $uploadedFiles * @param string $path * @return File[] */ private function createFiles(array $uploadedFiles, string $path) : array { $files = []; foreach ($uploadedFiles as $uploadedFile) { $files[] = $file = $this->fileRepository->fromInput(substr($uploadedFile->getClientFilename(), 0, 92), $path, $uploadedFile->getClientMediaType(), $uploadedFile->getStream()); $this->fileRepository->createFromUpload($file); } return $files; }
public function executeRequest(RequestInterface $request) : ResponseInterface { try { $path = $request['path']; $directories = $this->fileRepository->getDirectoriesInPath($path); $fileNames = $this->fileRepository->getFileNamesInPath($path); return new Response(self::MESSAGE, ['data' => ['path' => $path, 'directories' => $directories, 'files' => $fileNames]], $request); } catch (\Throwable $exception) { $this->log(LogLevel::ERROR, $exception->getMessage()); throw new ResponseException('An error occurred during GetDirectoryListingHandler.', new ServerErrorResponse([], $request)); } }
public function executeRequest(RequestInterface $request) : ResponseInterface { try { $file = $this->fileRepository->getByFullPath($request['path']); return new Response(self::MESSAGE, ['data' => $file], $request); } catch (NoUniqueResultException $e) { return new NotFoundResponse([], $request); } catch (\Throwable $exception) { $this->log(LogLevel::ERROR, $exception->getMessage()); throw new ResponseException('An error occurred during DownloadFileHandler.', new ServerErrorResponse([], $request)); } }
public function it_can_handle_exception_during_request(RequestInterface $request, UploadedFileInterface $file) { $path = '/path/To/a'; $file->getClientFilename()->willReturn($name = 'file.ext'); $file->getClientMediaType()->willReturn($mime = 'text/xml'); $file->getStream()->willReturn($stream = tmpfile()); $files = [$file]; $request->offsetGet('path')->willReturn($path); $request->offsetGet('files')->willReturn($files); $request->getAcceptContentType()->willReturn('application/json'); $this->fileRepository->fromInput($name, $path, $mime, $stream)->willThrow(new \RuntimeException()); $this->shouldThrow(ResponseException::class)->duringExecuteRequest($request); }
public function it_can_create_an_image(File $oldFile) { $name = FileNameValue::get('oldName.jpg'); $path = FilePathValue::get('/path/to/something'); $mime = MimeTypeValue::get('image/jpg'); $oldFile->getName()->willReturn($name); $oldFile->getPath()->willReturn($path); $oldFile->getMimeType()->willReturn($mime); $imageContents = tmpfile(); $this->fileRepository->createFromUpload(new Argument\Token\TypeToken(File::class)); $newImage = $this->createImage($oldFile, $imageContents); $newImage->getUuid()->shouldHaveType(Uuid::class); $newImage->getName()->shouldReturn($name); $newImage->getPath()->shouldReturn($path); $newImage->getMimeType()->shouldReturn($mime); $newImage->getStream()->shouldReturn($imageContents); }
public function createImage(File $file, $imageContents) : File { $newFile = new File(Uuid::uuid4(), $file->getName(), $file->getPath(), $file->getMimeType(), $imageContents); $this->fileRepository->createFromUpload($newFile); return $newFile; }