コード例 #1
0
 function it_does_not_overwrite_because_id_does_not_exist(OverwriteFileCommand $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);
 }
コード例 #2
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);
 }