Example #1
0
 public function it_can_execute_a_request(RequestInterface $request, File $file)
 {
     $path = '/path/to/a/file.ext';
     $request->offsetGet('path')->willReturn($path);
     $request->getAcceptContentType()->willReturn('*/*');
     $this->fileRepository->getByFullPath($path)->willReturn($file);
     $this->fileRepository->delete($file)->shouldBeCalled();
     $response = $this->executeRequest($request);
     $response->shouldHaveType(ResponseInterface::class);
     $response->getResponseName()->shouldReturn(DeleteFileHandler::MESSAGE);
     $response['data']->shouldBe($file);
 }
Example #2
0
 public function executeRequest(RequestInterface $request) : ResponseInterface
 {
     try {
         $file = $this->fileRepository->getByFullPath($request['path']);
         $this->fileRepository->delete($file);
         return new Response(self::MESSAGE, ['data' => $file], $request);
     } catch (NoUniqueResultException $e) {
         return new NotFoundResponse([], $request);
     } catch (\Throwable $e) {
         $this->log(LogLevel::ERROR, $e->getMessage());
         throw new ResponseException('An error occurred during DeleteFileHandler.', new ServerErrorResponse([], $request));
     }
 }