Skip to content

機能追加: FirestoreClientType プロトコルを追加 - #69

Merged
fummicc1 merged 1 commit into
mainfrom
feature/firestore-client-protocol
Feb 11, 2026
Merged

機能追加: FirestoreClientType プロトコルを追加#69
fummicc1 merged 1 commit into
mainfrom
feature/firestore-client-protocol

Conversation

@fummicc1

Copy link
Copy Markdown
Owner

概要

FirestoreClient (actor) のモック可能な抽象化レイヤーとして FirestoreClientType プロトコルを追加します。

背景

  • FirestoreClient は actor であるため、Mockolo 等のモック生成ツールでモッククラスを生成できない
  • 依存先プロジェクト(ToiletMap)の Repository 層ユニットテストで FirestoreClient のモックが必要
  • プロトコルを抽出することで、any FirestoreClientType としてモック注入が可能になる

主要な変更点

新規ファイル: Sources/Firestore/FirestoreClientType.swift

  • FirestoreClientType プロトコル定義(21メソッド)
    • FirestoreModel: write / get / listen / listenChanges / delete
    • SubCollectionModel: create / update / get / listen / listenChanges
    • CollectionGroup: getCollectionGroup / listenCollectionGroup / listenCollectionGroupChanges
    • Listener Management: stopListening (3種) / stopListeningAll
  • /// @mockable アノテーション付き(Mockolo対応)
  • Protocol extension でデフォルト引数を提供する convenience メソッド(20メソッド)

変更ファイル: Sources/Firestore/FirestoreClient.swift

  • 末尾に extension FirestoreClient: FirestoreClientType {} を追加(2行のみ)
  • 既存メソッドのシグネチャが protocol requirement と一致するため、追加実装は不要

設計判断

判断 理由
全メソッド async actor-isolated メソッドは async protocol requirement を満たせる(SE-0306)
writeTransaction 除外 WritableKeyPath + tuple closure の複雑なシグネチャ。必要時に追加可能
convenience extension プロトコルではデフォルト引数不可のため、extension で同等の呼び出しを提供

後方互換性

100% 後方互換

  • プロトコル追加と conformance 宣言のみ
  • 既存の FirestoreClient API は一切変更なし

テスト

  • swift build (Xcode toolchain Swift 6.2.3): ✅ ビルド成功
  • 既存テスト(Emulator ベース統合テスト): 変更なし
  • Sendable 関連 warning 2件: 既存コードの問題(本PR スコープ外)

レビューポイント

  1. プロトコルのメソッドシグネチャが FirestoreClient と正確に対応しているか
  2. convenience extension のデフォルト引数が適切か
  3. writeTransaction 以外に除外すべきメソッドがないか

FirestoreClient (actor) のモック可能な抽象化レイヤーとして
FirestoreClientType プロトコルを導入。

- 全パブリックメソッド(21メソッド)をプロトコル要件として定義
- デフォルト引数を提供する convenience extension を追加
- FirestoreClient の既存APIに変更なし(後方互換性100%)
- writeTransaction は複雑なシグネチャのため除外

これにより、依存先プロジェクトで Mockolo 等を使用した
ユニットテスト用モックの生成が可能になる。
@fummicc1
fummicc1 merged commit 96aea79 into main Feb 11, 2026
4 checks passed
@fummicc1
fummicc1 deleted the feature/firestore-client-protocol branch February 11, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant