Skip to content

Comments

Bugfix: ValidatesOpenApiSchema trait fails on non-JSON responses#16

Merged
wadakatu merged 2 commits intomainfrom
fix/non-json-response-handling
Feb 21, 2026
Merged

Bugfix: ValidatesOpenApiSchema trait fails on non-JSON responses#16
wadakatu merged 2 commits intomainfrom
fix/non-json-response-handling

Conversation

@wadakatu
Copy link
Collaborator

概要

assertResponseMatchesOpenApiSchema() が非JSONレスポンス(HTMLリダイレクトなど)で $response->json() を呼び出してクラッシュする問題を修正。Content-Type ヘッダーを確認してからJSONパースを行うようにした。

変更内容

  • ValidatesOpenApiSchema トレイトに extractJsonBody() メソッドを追加し、Content-Type ヘッダーに json が含まれない場合は null を返すように変更
  • CreatesTestResponse ヘルパーにヘッダーサポートを追加($headers パラメータ追加)
  • 非JSONレスポンスに関する3つのテストケースを追加
  • PHPStan設定にマジックプロパティアクセスと匿名クラス型のignoreルールを追加

関連情報

…review

- Fail with Content-Type mismatch message instead of misleading "body is empty"
- Wrap json() in try-catch for clear error on unparseable body
- Case-insensitive Content-Type check for HTTP spec compliance
- Add tests for charset, vendor JSON types, and missing header
- Simplify header bag constructor with array_change_key_case()
@wadakatu wadakatu merged commit 203559c into main Feb 21, 2026
8 checks passed
@wadakatu wadakatu deleted the fix/non-json-response-handling branch February 21, 2026 03:16
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.

ValidatesOpenApiSchema trait fails on non-JSON responses (302 redirects, text/html)

1 participant