Example #1
0
 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);
 }
Example #2
0
 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));
     }
 }
Example #3
0
 public function getByFullPath(string $path) : File
 {
     return $this->fileRepository->getByFullPath($path);
 }
Example #4
0
 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);
 }