예제 #1
0
 /**
  * @test
  */
 public function it_only_returns_valid_uploaded_files()
 {
     $invalid_file = new UploadedFile($real_path = '', $original_ext = '', $is_readable = false, $is_valid = false);
     $SUT = new CreatePostCommand($entry = [], $files = [$invalid_file], $token = "");
     $expected = [];
     $result = $SUT->getFiles();
     $this->assertEquals($expected, $result);
 }
예제 #2
0
 public function handle(CreatePostCommand $command)
 {
     try {
         $response = $this->accessTokenRepository->getTokenFromAuthCode($command->getAccessToken());
     } catch (\Exception $e) {
         $message = sprintf("Invalid access token [%s]", $command->getAccessToken());
         return new Unauthorized(["message" => $message]);
     }
     try {
         $post = new NewPost($command->getEntry(), $command->getFiles());
         $this->postRepository->save($post, $command->getFiles());
         return new OK(["items" => [$post]]);
     } catch (\Exception $e) {
         $message = sprintf("Failed to save new post [%s]", $e->getMessage());
         return new ServerError(["message" => $message]);
     }
 }