New Feature: #[SkipOpenApi] 属性で auto-assert を個別テスト単位でオプトアウト#55
Merged
Conversation
Add a reflection-based resolver that detects method-level or class-level #[SkipOpenApi(reason: '...')] attributes, with method-level taking precedence over class-level for fine-grained opt-out. Refs #40
… warning maybeAutoAssertOpenApiSchema() now early-returns when the current test method or its class carries #[SkipOpenApi], so no validation or coverage recording happens on intentionally skipped tests. Calling assertResponseMatchesOpenApiSchema() explicitly on a skipped test still runs the assertion but emits E_USER_DEPRECATED via a swappable $skipWarningHandler to flag the contradictory intent. Refs #40
Add an Auto-assert subsection covering method-level and class-level usage of #[SkipOpenApi], the optional reason parameter, and the deprecation-warning behavior when assertResponseMatchesOpenApiSchema() is called explicitly on a skipped test. Refs #40
…ribute The resolveSkipOpenApiReason() helper returned an empty string both when no #[SkipOpenApi] attribute existed and when one existed with an empty reason, conflating two distinct states. Drop the helper and have callers work directly with the nullable attribute. assertResponseMatchesOpenApiSchema() now resolves the attribute once and passes it to emitSkipOpenApiWarning(), avoiding a duplicate reflection pass on the skip-plus-explicit-call path. maybeAutoAssertOpenApiSchema() uses the same null check to align the two entry points.
…punit default config trigger_error(E_USER_DEPRECATED) alone is effectively silent under PHPUnit's default display configuration — only a "1 deprecation" tally appears in the summary, not the actual message body. Operators relying on the run summary never saw why the contradictory-intent warning was raised. Also emit the formatted message to STDERR so CI logs always include the class/method/reason, regardless of whether displayDetailsOnTestsThatTriggerDeprecations is enabled downstream. The trigger_error call is retained so tooling that counts deprecations keeps working.
…vel warning, and POST skip Fills coverage gaps identified during PR review: - New ValidatesOpenApiSchemaDefaultWarningHandlerTest exercises the default trigger_error(E_USER_DEPRECATED) path via set_error_handler so a future refactor cannot silently drop the deprecation emission. - ValidatesOpenApiSchemaSkipTest asserts the warning message contains the var_export-formatted "reason: '...'" segment, locking in the user-facing format. - ValidatesOpenApiSchemaClassLevelSkipTest adds an explicit-assert case that verifies the class-level reason surfaces in the warning and that the handler is reset in tearDown. - AutoAssertIntegrationTest adds a POST skip case through the Testbench integration path so a regression that only consulted skip on GET would be caught.
- Clarify that a method-level #[SkipOpenApi] fully shadows the class-
level attribute. The prior wording ("the reason of the method-level
attribute wins") implied only the reason field was overridden, but in
reality the method-level attribute replaces the class-level one
entirely during resolution.
- Document that coverage is recorded when a #[SkipOpenApi] test still
calls assertResponseMatchesOpenApiSchema() explicitly. The previous
wording implied the skip attribute always suppressed coverage.
- Note that class-level attributes on abstract parents are not inherited
by subclasses, since resolution uses ReflectionClass on the direct
class only.
Collaborator
Author
レビューフィードバック対応 (4 commits)
🔴 Critical 対応
🟠 Important 対応
🟡 その他
品質ゲート
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
auto-assert モード下で個別テストを契約検証から除外するための
#[SkipOpenApi]属性を追加します。わざと spec 違反を返すテストや、契約が固まっていない実験的エンドポイントを扱うテストで利用できます。変更内容
反射ベースの属性で method-level / class-level の双方をサポートし、
reasonパラメータを受け取れます。method-level が class-level を上書きします。src/SkipOpenApi.php: 属性クラス(TARGET_CLASS | TARGET_METHOD、reason: string = '')src/SkipOpenApiResolver.php:OpenApiSpecResolverと同じ流儀の reflection ベース resolver trait(shouldSkipOpenApi()/resolveSkipOpenApiReason())src/Laravel/ValidatesOpenApiSchema.php:maybeAutoAssertOpenApiSchema()で skip なら早期 return(検証なし・OpenApiCoverageTrackerにも未記録 = 未カバレッジ扱い)assertResponseMatchesOpenApiSchema()明示呼び出しは 常に走る(option A の意図表明尊重)。ただし#[SkipOpenApi]付きテストで明示呼び出しするとE_USER_DEPRECATEDを発行し、矛盾した意図を可視化$skipWarningHandlerstatic プロパティ経由で差し替え可能(テスタビリティのため)tests/Unit/SkipOpenApiResolver{,ClassLevel}Test.php: resolver 単体テスト(no attr / method / class / method-reason override)tests/Unit/ValidatesOpenApiSchema{,ClassLevel}SkipTest.php: auto-assert スキップ挙動 + 警告挙動tests/Integration/Laravel/AutoAssertIntegrationTest.php: Testbench 経由の method-level skip 統合テストREADME.md: Auto-assert セクション下に#[SkipOpenApi]の使い方・セマンティクス・警告挙動を追記設計メモ(レビュー観点)
E_USER_DEPRECATEDに: phpunit.xml.dist はfailOnWarning=trueのためE_USER_WARNINGは使えない。failOnDeprecationはデフォルト false なので deprecation 通知はテストを落とさず PHPUnit サマリに可視化される(Symfony/Laravel でも馴染みのパターン)。reasonは method 側が優先されるよう実装。品質ゲート
関連情報