Skip to content

Cover ResponseAwareException fully - #5

Merged
loevgaard merged 1 commit into
1.xfrom
response-aware-exception-coverage
Aug 6, 2026
Merged

Cover ResponseAwareException fully#5
loevgaard merged 1 commit into
1.xfrom
response-aware-exception-coverage

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Closes the coverage gap on ResponseAwareException — previously 4/8 methods and 89.8% of lines; now 8/8 and 100%.

What was uncovered

  • getResponse() — never called by any test
  • the lazy parse path: parseBody() reading from the response stream when no $body was passed at construction (every SDK-internal throw passes $body, so only direct construction reaches it)
  • getErrorCode()'s defensive int→string cast
  • getValidationErrors()'s non-map errors branch

New behavior pins

Two of the six new tests assert behavior this class exists for, which was exercised but never asserted:

  • Pre-read body wins over a drained stream — the non-seekable-stream robustness described in the class docblock: with an empty response stream, only the pre-read $body keeps the getters working.
  • The default message embeds a sanitized request context — query string and fragment stripped, asserted character-exact, so consumer-supplied secrets can never silently start leaking into exception messages/logs.

Result

  • Tests: 103 → 109 (PHPStan max, ECS green)
  • Mutation score: MSI 80% → 85%, covered MSI 82% → 85% (gate: 70)
  • The four remaining escaped mutants in the class are behaviorally equivalent (idempotent re-decode, trims of never-padded strings, sprintf's implicit cast).

getResponse(), the lazy stream-read parse path, the integer error_code
cast and the non-map errors branch were uncovered (50% of methods,
89.8% of lines). New tests cover them all, plus two that pin behavior
the class exists for:

- the pre-read $body wins over an already-drained response stream
  (the non-seekable-stream robustness described in the docblock)
- the default message embeds a SANITIZED request context - query string
  and fragment stripped so consumer secrets never leak into messages

ResponseAwareException: 8/8 methods, 100% lines. Suite MSI 80% -> 85%,
covered MSI 82% -> 85%. The four remaining escaped mutants in the class
are behaviorally equivalent (idempotent re-decode, trims of never-padded
strings, sprintf's implicit string cast).
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.50%. Comparing base (52dd84a) to head (cd28cb4).

Additional details and impacted files
@@             Coverage Diff              @@
##                1.x       #5      +/-   ##
============================================
+ Coverage     97.00%   98.50%   +1.49%     
  Complexity      146      146              
============================================
  Files            24       24              
  Lines           401      401              
============================================
+ Hits            389      395       +6     
+ Misses           12        6       -6     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@loevgaard
loevgaard merged commit 52e7959 into 1.x Aug 6, 2026
35 checks passed
@loevgaard
loevgaard deleted the response-aware-exception-coverage branch August 6, 2026 09:44
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.

1 participant