コード例 #1
0
ファイル: RemoveFileHandlerSpec.php プロジェクト: bengor/file
 function it_does_not_handle_because_file_id_does_not_exist(FileRepository $repository, RemoveFileCommand $command)
 {
     $command->id()->shouldBeCalled()->willReturn('file-id');
     $id = new FileId('file-id');
     $repository->fileOfId($id)->shouldBeCalled()->willReturn(null);
     $this->shouldThrow(FileDoesNotExistException::class)->during__invoke($command);
 }
コード例 #2
0
ファイル: RemoveFileHandler.php プロジェクト: bengor/file
 /**
  * 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);
 }