Improve code coverage for HttpTransport#45
Merged
Conversation
This commit addresses code coverage gaps in `src/Transport/HttpTransport.php`.
Key changes include:
- **receive method**: I added tests to cover invalid item structures within batch JSON-RPC requests. I ensured that if an item in a batch is not a valid JSON object (e.g., a string or a list), a `TransportException` is thrown.
- **send method**: I investigated an `else` branch previously thought to be reachable. I determined that PHP's runtime type hinting for method parameters (`JsonRpcMessage|array|null`) makes this branch effectively unreachable. I removed the unreachable `else` block.
- **isStreamOpen method**: I added a test to confirm it correctly returns `false`, as the simplified transport does not support streaming.
- **isClosed method**: I added tests to verify its state:
- Returns `false` immediately after transport instantiation.
- Returns `true` after the `send()` method has been called.
- **getResponse method**: I added a test using reflection to cover a fallback scenario where the internal `$this->response` property might be `null`. This test ensures the method generates a proper error response in such a case.
All new tests pass, and existing tests continue to pass. Linters (PHPCS, PHPStan) also pass with these changes. The overall goal was to increase test coverage for the specified methods and conditions.
🧪 Test Results SummaryPHPUnit Tests✅ All tests passed! Details: OK (238 tests, 954 assertions)
Code Quality
📁 Detailed Reports
This comment will update automatically when you push new commits. Code Coverage
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
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.
This commit addresses code coverage gaps in
src/Transport/HttpTransport.php.Key changes include:
TransportExceptionis thrown.elsebranch previously thought to be reachable. I determined that PHP's runtime type hinting for method parameters (JsonRpcMessage|array|null) makes this branch effectively unreachable. I removed the unreachableelseblock.false, as the simplified transport does not support streaming.falseimmediately after transport instantiation.trueafter thesend()method has been called.$this->responseproperty might benull. This test ensures the method generates a proper error response in such a case.All new tests pass, and existing tests continue to pass. Linters (PHPCS, PHPStan) also pass with these changes. The overall goal was to increase test coverage for the specified methods and conditions.