Example #1
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);
 }
Example #2
0
 /**
  * Handles the given command.
  *
  * @param RenameFileCommand $aCommand The command
  *
  * @throws FileDoesNotExistException when file does not exist
  */
 public function __invoke(RenameFileCommand $aCommand)
 {
     $id = new FileId($aCommand->id());
     $name = new FileName($aCommand->name());
     $file = $this->repository->fileOfId($id);
     if (null === $file) {
         throw new FileDoesNotExistException();
     }
     $this->filesystem->rename($file->name(), $name);
     $file->rename($name);
     $this->repository->persist($file);
 }