示例#1
0
 /**
  * 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);
 }
示例#2
0
 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);
 }