Skip to content

test: remove 22 redundant test cases#98

Merged
valbeat merged 1 commit into
mainfrom
test/prune-redundant-cases
Jul 7, 2026
Merged

test: remove 22 redundant test cases#98
valbeat merged 1 commit into
mainfrom
test/prune-redundant-cases

Conversation

@valbeat

@valbeat valbeat commented Jul 7, 2026

Copy link
Copy Markdown
Owner

概要

テストスイートのレビューで特定した、固有の失敗モードを持たない冗長テスト 22 件を削除します(99 → 77 tests、削除のみ 206 行)。実行時間ではなく、仕様変更時に同じ原因で複数テストが一斉に落ちるノイズと保守コストの削減が目的です。

削除の内訳

グループ 件数 理由
値の型バリエーション(string/array/object/int を unwrap 系に通すだけ) 8 アクセサは分岐のない 1 文の return で、値の型でコードパスが変わらない。各メソッドの基本形テストは残置
falsy 値ピンの過剰分(0 / '' 4 null(isset 系)と false(truthiness 系)で失敗モードは尽きており、両方とも各クラスに残置
ランタイムの「型が変わる」系(map/mapErr/match/andThen) 7 PHP は動的型付けで基本形と同一パス。型合成の関心事は tests/Types/result.php の assertType が正しいレイヤーでピン留め済み
進化の名残(強いテストに厳密包含される弱いアサーション) 3 expect_throws_withGivenMessage 等は *_throwsUnwrapException 変種に包含。UnwrapException extends LogicException の事実は残置テスト(unwrap_throws_exception\LogicException を期待してパス)でピン留め継続

残しているもの(一見冗長だが意図あり)

  • unwrap_throws_exception のメッセージプレフィックス検証 — 前方一致に依存する利用者への BC ピン
  • match_supportsNamedArguments の Ok/Err 両方 — PHP はインターフェースとの引数名一致を強制しないため、クラスごとに独立してドリフトし得る
  • describe() のエッジテスト群 — 各々が別分岐をピン
  • null / false の falsy ピン — リファクタリング保険として残置

検証

  • 削除された各テストは同一コードパスを検証する残置テストと対になっているため、src/ の行カバレッジは不変(codecov project/patch チェックで CI 上も確認可能)
  • 77 tests / 121 assertions パス、PHPStan level max エラーなし(未使用ヘルパー警告なし)、cs-fixer クリーン

https://claude.ai/code/session_017XTM7pxbWPVNLV639i5WgK

Summary by CodeRabbit

  • Tests
    • テスト構成を見直し、一部のケースを整理しました。
    • unwrapmapandThenmatch などの検証対象を簡素化し、unwrapOr の確認を追加しました。
    • 0 や空文字などの境界値に関するテストの一部を削除しました。

Remove tests that pin no distinct failure mode, in four groups:

- value-type variations (string/array/object/int payloads through
  unwrap/unwrapErr/unwrapOr): the accessors are single-statement
  returns with no branching, so payload type cannot change the code
  path; the base test per method remains
- falsy-value pins: keep null (isset-style bugs) and false
  (truthiness bugs) per class; 0 and '' repeat the false failure mode
- runtime 'type change' tests (map/mapErr/match/andThen with
  different value or error types): PHP is dynamically typed, so these
  re-run the same path as the base tests; the type-composition claims
  they alluded to are pinned at the right layer by assertType tests
  in tests/Types/result.php
- evolution leftovers subsumed by stronger tests:
  expect_throws_withGivenMessage and expectErr_throws_withGivenMessage
  are strictly implied by the *_throwsUnwrapException variants, and
  unwrapException_remainsCatchableAsLogicException is the conjunction
  of unwrap_throws_exception (LogicException) and
  unwrap_throwsUnwrapException_withErrorValueInMessage

Every removed test has a kept twin exercising the same code path, so
line coverage of src/ is unchanged (verified: 77 tests green, PHPStan
level max clean).

Claude-Session: https://claude.ai/code/session_017XTM7pxbWPVNLV639i5WgK
@valbeat valbeat self-assigned this Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

tests/ErrTest.php から、Err の例外処理・型変換・境界値・エラー保持等に関する複数のテストメソッドが削除され、unwrapOr_returns_default テストが追加された。公開エンティティの変更はなし。

Changes

Errテストの整理

Layer / File(s) Summary
expect/unwrap系例外テストの削除
tests/ErrTest.php
expect_throws_withGivenMessageunwrapException_remainsCatchableAsLogicException を削除。
unwrapErr/unwrapOr系テストの整理
tests/ErrTest.php
unwrapErr の複数型別テストと unwrapOr_withDifferentTypes_returns_default を削除し、unwrapOr_returns_default を追加。
mapErr/andThen/matchテストの削除
tests/ErrTest.php
mapErr_withTypeChange_transforms_typeandThen_withDifferentErrorType_keeps_original_errormatch_withDifferentReturnTypes_returns_err_branch を削除。
境界値・例外値テストの削除
tests/ErrTest.php
err_withZeroValue_handles_zeroerr_withEmptyString_handles_empty_stringexceptionAsErrorValue_handles_exception を削除。

Estimated code review effort: 2 (Simple) | ~10 minutes

関連する懸念事項(レビューコメント):

  • 削除されたテスト群(型変換、境界値、例外の互換性検証など)は Err/Ok の不変条件を担保する重要なケースが多く含まれています。特に unwrapException_remainsCatchableAsLogicException のようなPHPの例外階層(LogicException)依存の互換性テストや、0・空文字といった falsy 値の境界値テストは、型安全性の観点から再度必要性を確認した方がよいかと思います。
  • 今回のサマリーには tests/OkTest.php の変更も含まれていますが、提供された range 情報には含まれていないため、そちらのカバレッジ低下についても別途確認が必要です。
  • 単純な削除のみで実装コード側(Err/Ok クラス本体)への変更が見当たらないため、テストの意図的な整理なのか、意図せぬ欠落なのか、PR説明での背景明記をお願いします。

Suggested labels: tests, needs-discussion

Suggested reviewers: valbeat

🐰 テストの数が 減りゆく夜に
   境界値たちは どこへ行くのかな
   0と空文字 忘れないでね
   型の安全 守る子たちだよ
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 変更内容と一致しており、冗長なテストケースの削除という主目的を簡潔に表しています。
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/prune-redundant-cases

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request simplifies the test suites in tests/ErrTest.php and tests/OkTest.php by removing numerous redundant test cases, including those verifying specific type behaviors, empty values, and exception handling. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (dc383f0) to head (45d8917).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #98   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity        65        65           
===========================================
  Files              4         4           
  Lines            130       130           
===========================================
  Hits             130       130           
Flag Coverage Δ
unittests 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@valbeat valbeat marked this pull request as ready for review July 7, 2026 11:05
Copilot AI review requested due to automatic review settings July 7, 2026 11:05
@valbeat valbeat merged commit 308fd0d into main Jul 7, 2026
12 checks passed
@valbeat valbeat deleted the test/prune-redundant-cases branch July 7, 2026 11:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces maintenance noise in the PHP Result test suite by removing redundant test cases that don’t exercise distinct failure modes, aiming to keep coverage signal while lowering duplicated assertions.

Changes:

  • Removes redundant Ok tests that only vary input types or return-type shapes (unwrap, map, andThen, match) without changing code paths.
  • Removes redundant Err tests for value-type variations and return-type variations where behavior is already covered by remaining core tests.
  • Keeps “unique failure mode” tests in place (e.g., exception/message assertions and named-argument support), while trimming strictly subsumed variants.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/OkTest.php Deletes redundant Ok-path tests (type-variation and return-shape variants) while retaining core behavior and exception/message coverage.
tests/ErrTest.php Deletes redundant Err-path tests (type-variation and return-shape variants) while retaining core unwrap/expect exception/message coverage and named-argument checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants