Example #1
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);
 }
Example #2
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);
 }