Skip to content

[TEST] Add dedicated unit tests for RequestContext (689 lines, only tested indirectly)Β #104

Description

@jeromesinolanka

Priority: 🟑 Medium

Description

src/Fetch/Support/RequestContext.php is 689 lines and serves as the immutable per-request state container. Every single HTTP request flows through it, yet it has no dedicated test file β€” it is only exercised indirectly when integration tests make full requests.

Testing it in isolation is valuable because:

  • It is immutable (readonly properties), so constructor argument handling is the only path to test
  • It has a complex set of constructor parameters with defaults, and it's easy for a refactor to change a default silently
  • Any bug here affects every request made by the library

Current gap

No RequestContextTest.php in tests/Unit/.

Recommended Fix

Create tests/Unit/RequestContextTest.php covering:

  1. All constructor arguments β€” verify each property is set correctly when explicitly passed
  2. Default values β€” verify each optional parameter's default matches documented behavior
  3. Immutability β€” verify attempting to assign to a readonly property throws an Error
  4. Type correctness β€” verify that passing invalid types (e.g., a negative timeout) surfaces an error at construction time (or document that it doesn't, so the behavior is explicit)
  5. Accessor methods β€” if any exist, verify they return the constructed values

Impact

Without these tests, a change to a constructor default (e.g., changing the default timeout from 30 to 0) is invisible until a production request times out immediately.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

needs-triageNeeds review before work beginspriority: mediumCode quality, completeness, or maintainabilitytestingTest coverage, fixtures, or testing infrastructure

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions