Example #1
0
 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));
     }
 }
Example #2
0
 public function it_can_execute_a_request(RequestInterface $request)
 {
     $path = '/path/to';
     $directories = ['first', 'second'];
     $files = ['file.ext', 'about.txt'];
     $request->offsetGet('path')->willReturn($path);
     $request->getAcceptContentType()->willReturn('*/*');
     $this->fileRepository->getDirectoriesInPath($path)->willReturn($directories);
     $this->fileRepository->getFileNamesInPath($path)->willReturn($files);
     $response = $this->executeRequest($request);
     $response->shouldHaveType(ResponseInterface::class);
     $response->getResponseName()->shouldReturn(GetDirectoryListingHandler::MESSAGE);
     $response['data']['path']->shouldBe($path);
     $response['data']['directories']->shouldBe($directories);
     $response['data']['files']->shouldBe($files);
 }