예제 #1
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);
 }
예제 #2
0
 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);
 }