コード例 #1
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);
 }
コード例 #2
0
ファイル: RemoveFileHandler.php プロジェクト: bengor/file
 /**
  * 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);
 }
コード例 #3
0
ファイル: RemoveFileHandlerSpec.php プロジェクト: bengor/file
 function it_handles(RemoveFileCommand $command, Filesystem $filesystem, FileRepository $repository, File $file)
 {
     $command->id()->shouldBeCalled()->willReturn('file-id');
     $id = new FileId('file-id');
     $name = new FileName('file.pdf');
     $repository->fileOfId($id)->shouldBeCalled()->willReturn($file);
     $file->name()->shouldBeCalled()->willReturn($name);
     $filesystem->delete($name)->shouldBeCalled();
     $repository->remove($file)->shouldBeCalled();
     $this->__invoke($command);
 }
コード例 #4
0
ファイル: OverwriteFileHandler.php プロジェクト: bengor/file
 /**
  * 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);
 }
コード例 #5
0
ファイル: RenameFileHandlerSpec.php プロジェクト: bengor/file
 function it_renames(RenameFileCommand $command, FileRepository $repository, File $file, Filesystem $filesystem)
 {
     $command->id()->shouldBeCalled()->willReturn('file-id');
     $command->name()->shouldBeCalled()->willReturn('dummy-file.pdf');
     $id = new FileId('file-id');
     $name = new FileName('dummy-file.pdf');
     $repository->fileOfId($id)->shouldBeCalled()->willReturn($file);
     $oldName = new FileName('old-file-name.pdf');
     $file->name()->shouldBeCalled()->willReturn($oldName);
     $filesystem->rename($oldName, $name)->shouldBeCalled();
     $file->rename($name)->shouldBeCalled();
     $repository->persist($file)->shouldBeCalled();
     $this->__invoke($command);
 }
コード例 #6
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);
 }
コード例 #7
0
 function it_overwrites(OverwriteFileCommand $command, FileRepository $repository, File $file, Filesystem $filesystem)
 {
     $command->id()->shouldBeCalled()->willReturn('file-id');
     $command->name()->shouldBeCalled()->willReturn('dummy-file.pdf');
     $command->mimeType()->shouldBeCalled()->willReturn('application/pdf');
     $command->uploadedFile()->shouldBeCalled()->willReturn('file content');
     $id = new FileId('file-id');
     $name = new FileName('dummy-file.pdf');
     $mimeType = new FileMimeType('application/pdf');
     $repository->fileOfId($id)->shouldBeCalled()->willReturn($file);
     $oldName = new FileName('old-file-name.pdf');
     $file->name()->shouldBeCalled()->willReturn($oldName);
     $filesystem->delete($oldName)->shouldBeCalled();
     $file->overwrite($name, $mimeType)->shouldBeCalled();
     $filesystem->write($name, 'file content')->shouldBeCalled();
     $repository->persist($file)->shouldBeCalled();
     $this->__invoke($command);
 }