Exemplo n.º 1
0
 function it_does_not_get_the_file_because_the_name_does_not_exist(FileRepository $repository, FileOfNameQuery $query)
 {
     $query->name()->shouldBeCalled()->willReturn('file.pdf');
     $name = new FileName('file.pdf');
     $repository->fileOfName($name)->shouldBeCalled()->willReturn(null);
     $this->shouldThrow(FileDoesNotExistException::class)->during__invoke($query);
 }
Exemplo n.º 2
0
 function it_does_not_get_the_file_because_the_id_does_not_exist(FileRepository $repository, FileOfIdQuery $query)
 {
     $query->id()->shouldBeCalled()->willReturn('file-id');
     $id = new FileId('file-id');
     $repository->fileOfId($id)->shouldBeCalled()->willReturn(null);
     $this->shouldThrow(FileDoesNotExistException::class)->during__invoke($query);
 }
Exemplo n.º 3
0
 function it_does_not_handle_because_file_id_does_not_exist(FileRepository $repository, RemoveFileCommand $command)
 {
     $command->id()->shouldBeCalled()->willReturn('file-id');
     $id = new FileId('file-id');
     $repository->fileOfId($id)->shouldBeCalled()->willReturn(null);
     $this->shouldThrow(FileDoesNotExistException::class)->during__invoke($command);
 }
Exemplo n.º 4
0
 function it_does_not_rename_because_id_does_not_exist(RenameFileCommand $command, FileRepository $repository)
 {
     $command->id()->shouldBeCalled()->willReturn('file-id');
     $command->name()->shouldBeCalled()->willReturn('dummy-file.pdf');
     $id = new FileId('file-id');
     $repository->fileOfId($id)->shouldBeCalled()->willReturn(null);
     $this->shouldThrow(FileDoesNotExistException::class)->during__invoke($command);
 }
Exemplo n.º 5
0
 /**
  * Handles the given query.
  *
  * @param AllFilesQuery $aQuery The query
  *
  * @return mixed
  */
 public function __invoke(AllFilesQuery $aQuery)
 {
     $files = $this->repository->all();
     $result = array_map(function (File $file) {
         $this->dataTransformer->write($file);
         return $this->dataTransformer->read();
     }, $files);
     return $result;
 }
Exemplo n.º 6
0
 function it_does_not_handle_because_file_already_exists(FileRepository $repository, Filesystem $filesystem, ByHashUploadFileCommand $command)
 {
     $command->id()->shouldBeCalled()->willReturn('file-id');
     $id = new FileId('file-id');
     $command->name()->shouldBeCalled()->willReturn('dummy-file-name.pdf');
     $repository->fileOfId($id)->shouldBeCalled()->willReturn(null);
     $filesystem->has(Argument::type(FileName::class))->shouldBeCalled()->willReturn(true);
     $this->shouldThrow(FileAlreadyExistsException::class)->during__invoke($command);
 }
Exemplo n.º 7
0
 /**
  * Handles the given command.
  *
  * @param RemoveFileCommand $aCommand The command
  *
  * @throws FileDoesNotExistException when file is already exists
  */
 public function __invoke(RemoveFileCommand $aCommand)
 {
     $id = new FileId($aCommand->id());
     $file = $this->repository->fileOfId($id);
     if (null === $file) {
         throw new FileDoesNotExistException();
     }
     $this->filesystem->delete($file->name());
     $this->repository->remove($file);
 }
Exemplo n.º 8
0
 /**
  * Handles the given query.
  *
  * @param FileOfNameQuery $aQuery The query
  *
  * @throws FileDoesNotExistException when the file name does not exist
  *
  * @return mixed
  */
 public function __invoke(FileOfNameQuery $aQuery)
 {
     $fileName = new FileName($aQuery->name());
     $file = $this->repository->fileOfName($fileName);
     if (null === $file) {
         throw new FileDoesNotExistException();
     }
     $this->dataTransformer->write($file);
     return $this->dataTransformer->read();
 }
Exemplo n.º 9
0
 /**
  * Handles the given command.
  *
  * @param OverwriteFileCommand $aCommand The command
  *
  * @throws FileDoesNotExistException when file does not exist
  */
 public function __invoke(OverwriteFileCommand $aCommand)
 {
     $id = new FileId($aCommand->id());
     $name = new FileName($aCommand->name());
     $file = $this->repository->fileOfId($id);
     if (null === $file) {
         throw new FileDoesNotExistException();
     }
     $this->filesystem->delete($file->name());
     $file->overwrite($name, new FileMimeType($aCommand->mimeType()));
     $this->filesystem->write($name, $aCommand->uploadedFile());
     $this->repository->persist($file);
 }
Exemplo n.º 10
0
 /**
  * Handles the given command.
  *
  * @param ByHashUploadFileCommand $aCommand The command
  *
  * @throws FileAlreadyExistsException when file is already exists
  */
 public function __invoke(ByHashUploadFileCommand $aCommand)
 {
     $id = new FileId($aCommand->id());
     $file = $this->repository->fileOfId($id);
     if (null !== $file) {
         throw new FileAlreadyExistsException();
     }
     $name = FileName::fromHash($aCommand->name());
     if (true === $this->filesystem->has($name)) {
         throw new FileAlreadyExistsException();
     }
     $this->filesystem->write($name, $aCommand->uploadedFile());
     $file = $this->factory->build($id, $name, new FileMimeType($aCommand->mimeType()));
     $this->repository->persist($file);
 }
Exemplo n.º 11
0
 function it_gets_files_when_the_list_is_empty(AllFilesQuery $query, FileRepository $repository)
 {
     $repository->all()->shouldBeCalled()->willReturn([]);
     $this->__invoke($query)->shouldReturn([]);
 }