-
Notifications
You must be signed in to change notification settings - Fork 0
Make snapshot updates possible without modifying test code #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make snapshot updates possible without modifying test code #4
Conversation
ウォークスルーGitHub Actionsのテストジョブに環境変数を追加し、READMEにテスト/スナップショット/キャッシュ運用を追記。テスト基底クラスに 変更箇所
シーケンス図sequenceDiagram
autonumber
participant TestRunner as テストランナー
participant Pages as PagesTestCase
participant FS as ファイルシステム
TestRunner->>Pages: テスト開始 -> getCacheMode()
Note right of Pages `#e6f7ff`: 環境変数優先\n`UPDATE_EMBED_SNAPSHOTS` / `EMBED_STRICT_CACHE`\nなければ定数を使用
Pages->>Pages: getEmbed() 実行
Pages->>FS: fixture 存在確認
alt fixture が存在
FS-->>Pages: fixture を返す
Pages->>TestRunner: 通常アサーション実行
else fixture が欠如
alt strict モード
Pages->>TestRunner: テスト失敗(fixture 必須)
else update fixtures モード
Pages->>FS: fixture を書き込み
Pages->>TestRunner: 保存メッセージ出力 + テストをスキップ
else 非 strict モード
Pages->>FS: fixture を書き込み
Pages->>TestRunner: 保存メッセージ出力 + テストをスキップ
end
end
推定レビュー工数🎯 3(Moderate) | ⏱️ ~20分
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (3)
.github/workflows/test.yml(1 hunks)README.md(1 hunks)tests/PagesTestCase.php(3 hunks)
🔇 Additional comments (1)
tests/PagesTestCase.php (1)
18-39: CACHE / FIXTURES 定数とモードのドキュメントは分かりやすいですキャッシュモード・フィクスチャモードの意味と、環境変数による上書きの関係が docblock で丁寧に説明されていて、テスト挙動を追いやすくなっていると思います。また
static::CACHE/static::FIXTURESを使っているので、サブクラス側で定数を上書きしてテストごとにデフォルトモードを変えられる設計も良いです。
795216b to
b30b26a
Compare
Add UPDATE_EMBED_SNAPSHOTS environment variable to update both HTTP response cache and fixtures together when running tests. Changes: - Add UPDATE_EMBED_SNAPSHOTS=1 to fetch from network and update snapshots - Add EMBED_STRICT_CACHE=1 to fail if cache is missing (for CI) - Update GitHub Actions workflow to use EMBED_STRICT_CACHE - Add comprehensive documentation for snapshot testing in README Usage: UPDATE_EMBED_SNAPSHOTS=1 ./vendor/bin/phpunit --filter testYoutube
b30b26a to
cfbe805
Compare
PRとしては完成しているので、これを手動レビュー、動作確認して上流にPRを送る。
Why
Updating test snapshots required modifying constants inside the test suite.
This made the workflow unnecessarily awkward and error-prone:
As a result, contributors could not easily refresh snapshots, raising
the barrier for maintaining or improving tests.
This PR introduces a simple environment-based switch so contributors can
update snapshots without touching the codebase.
What
New environment variables
UPDATE_EMBED_SNAPSHOTS=1EMBED_STRICT_CACHE=1Developer workflow
Developers can now refresh snapshots with a single command:
No code edits and no numeric flags are required.
CI updates
GitHub Actions now runs with:
to ensure snapshot files are always present and up to date.
Documentation
A new "Testing" section has been added to the README, describing how
snapshots are updated and how strict mode behaves in CI.
Usage Examples
Summary by CodeRabbit
リリースノート
Documentation
Tests
Chores