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); }
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 getByFullPath(string $path) : File { return $this->fileRepository->getByFullPath($path); }
public function it_can_retrieve_an_image(File $file) { $path = '/path/to/file.ext'; $this->fileRepository->getByFullPath($path)->willReturn($file); $this->getByFullPath($path)->shouldReturn($file); }