Skip to content

Conversation

@terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Aug 6, 2025

Q A
Is bugfix? ✔️
New feature?
Breaks BC?

Summary by CodeRabbit

  • New Features

    • Added support for handling and returning combined route and query parameters in JSON responses for specific routes.
    • Introduced a new endpoint that returns both route and query parameters in its JSON output.
  • Tests

    • Added tests to verify correct handling and response of combined route and query parameters for the new endpoint.
  • Chores

    • Updated URL routing rules to support new endpoint patterns with dynamic parameters.

@terabytesoftw terabytesoftw added the bug Something isn't working label Aug 6, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

This change introduces caching of merged query parameters in the ServerRequestAdapter class, updates the resolve() and getQueryParams() methods to use this cache, and adds a new URL rule and corresponding controller action for handling test queries. A new test verifies the correct merging and retrieval of route and query parameters in JSON responses.

Changes

Cohort / File(s) Change Summary
ServerRequestAdapter Query Parameter Caching
src/adapter/ServerRequestAdapter.php
Added a private $queryParams property to cache merged query parameters; updated resolve() to store merged parameters in this property; modified getQueryParams() to return the cached array if available.
URL Routing Rule Addition
tests/TestCase.php
Added a new URL rule to the urlManager configuration to route site/query/<test:\w+> to site/query.
Controller Action for Query Testing
tests/support/stub/SiteController.php
Introduced actionQuery(string $test), returning JSON with the test parameter, query parameter q, and all query parameters.
Test for Query Parameter Merging
tests/http/StatelessApplicationTest.php
Added testReturnJsonResponseWithQueryParamsForSiteQueryRoute to verify correct merging and retrieval of route and query parameters in JSON responses.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant App
    participant ServerRequestAdapter
    participant SiteController

    Client->>App: Send GET /site/query/foo?q=1
    App->>ServerRequestAdapter: resolve(request)
    ServerRequestAdapter->>ServerRequestAdapter: Merge route + query params, cache in $queryParams
    App->>SiteController: actionQuery(test='foo')
    SiteController->>ServerRequestAdapter: getQueryParams()
    ServerRequestAdapter->>SiteController: Return cached $queryParams
    SiteController->>App: Return JSON response (test, q, queryParams)
    App->>Client: Send JSON response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

A bunny hopped through fields of code,
Merging queries on the road.
With caching tucked behind its ear,
It fetched parameters, crisp and clear.
Now tests and routes all work in sync—
A JSON treat, quick as a wink! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36b16de and fcf39d4.

📒 Files selected for processing (4)
  • src/adapter/ServerRequestAdapter.php (4 hunks)
  • tests/TestCase.php (1 hunks)
  • tests/http/StatelessApplicationTest.php (1 hunks)
  • tests/support/stub/SiteController.php (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#21
File: tests/http/PSR7ResponseTest.php:0-0
Timestamp: 2025-07-22T00:50:26.546Z
Learning: In yii2-extensions/psr-bridge, the ResponseAdapter::formatCookieHeader() method uses `$expire !== 1` to skip validation for Yii2's special deletion cookies, but this should be extended to handle all expired cookies, not just the special case where expire=1.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.341Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods, so individual test methods that extend TestCase don't need manual $_SERVER restoration.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.341Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods (lines 28 and 32), so individual test methods that extend TestCase don't need manual $_SERVER restoration.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#21
File: tests/http/PSR7ResponseTest.php:0-0
Timestamp: 2025-07-22T01:01:13.426Z
Learning: In yii2-extensions/psr-bridge, expired cookies should not be hashed/validated because they are deletion cookies meant to remove existing cookies from the client browser. The validation logic should only apply to live cookies (expire=0 or expire >= current time) and skip validation for both the special Yii2 deletion case (expire=1) and regular expired cookies.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#64
File: tests/http/StatelessApplicationTest.php:1939-1967
Timestamp: 2025-08-06T22:52:05.363Z
Learning: In yii2-extensions/psr-bridge tests, when testing specific component methods like Request::resolve(), it's necessary to call $app->handle($request) first to initialize all application components before testing the method in isolation. This ensures proper component lifecycle initialization.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1564-1578
Timestamp: 2025-07-20T16:33:57.495Z
Learning: The TestCase class in yii2-extensions/psr-bridge automatically handles $_SERVER superglobal cleanup by saving its original state before each test and restoring it afterward in setUp() and tearDown() methods. Manual $_SERVER cleanup in individual test methods is unnecessary when extending this TestCase.
📚 Learning: in the yii2-extensions/psr-bridge project, the base testcase class already handles $_server cleanup ...
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.341Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods (lines 28 and 32), so individual test methods that extend TestCase don't need manual $_SERVER restoration.

Applied to files:

  • tests/TestCase.php
📚 Learning: the testcase class in yii2-extensions/psr-bridge automatically handles $_server superglobal cleanup ...
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1564-1578
Timestamp: 2025-07-20T16:33:57.495Z
Learning: The TestCase class in yii2-extensions/psr-bridge automatically handles $_SERVER superglobal cleanup by saving its original state before each test and restoring it afterward in setUp() and tearDown() methods. Manual $_SERVER cleanup in individual test methods is unnecessary when extending this TestCase.

Applied to files:

  • tests/TestCase.php
📚 Learning: in the yii2-extensions/psr-bridge project, the base testcase class already handles $_server cleanup ...
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.341Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods, so individual test methods that extend TestCase don't need manual $_SERVER restoration.

Applied to files:

  • tests/TestCase.php
📚 Learning: in yii2-extensions/psr-bridge, the statelessapplication creates a new response instance for each req...
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#53
File: src/http/ErrorHandler.php:258-272
Timestamp: 2025-08-03T16:24:09.241Z
Learning: In yii2-extensions/psr-bridge, the StatelessApplication creates a new Response instance for each request in the reset() method, then passes it to ErrorHandler::setResponse(). This means the template response is not shared across requests, so calling clear() on it in createErrorResponse() is safe and doesn't cause side effects.

Applied to files:

  • tests/http/StatelessApplicationTest.php
📚 Learning: in yii2-extensions/psr-bridge, the statelessapplication creates a new response instance for each req...
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#53
File: src/http/ErrorHandler.php:258-272
Timestamp: 2025-08-03T16:24:09.241Z
Learning: In yii2-extensions/psr-bridge, the StatelessApplication creates a new Response instance for each request in the reset() method (line 408: `$this->response = new Response($this->components['response'] ?? []);`), then passes it to ErrorHandler::setResponse(). This means the template response is not shared across requests, so calling clear() on it in createErrorResponse() is safe and doesn't cause side effects.

Applied to files:

  • tests/http/StatelessApplicationTest.php
🧬 Code Graph Analysis (1)
tests/support/stub/SiteController.php (2)
src/adapter/ServerRequestAdapter.php (1)
  • getQueryParams (245-252)
src/http/Request.php (1)
  • getQueryParams (358-365)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
🔇 Additional comments (6)
tests/TestCase.php (1)

152-152: LGTM! URL rule addition supports query parameter testing.

The new URL rule properly maps parameterized requests to the query action, enabling tests that verify the correct merging of route parameters and query parameters between PSR-7 and Yii2 Request implementations.

tests/support/stub/SiteController.php (1)

234-246: LGTM! Controller action properly supports query parameter testing.

The implementation correctly:

  • Accepts the route parameter $test from the URL pattern
  • Retrieves individual query parameters via $this->request->get('q')
  • Retrieves all query parameters via $this->request->getQueryParams()
  • Returns comprehensive JSON data for testing parameter merging behavior

This design effectively supports testing the consistency between PSR-7 and Yii2 Request query parameter handling.

tests/http/StatelessApplicationTest.php (1)

1241-1272: LGTM! Comprehensive test validates query parameter merging behavior.

The test effectively validates the PR objective by:

  • Testing a request with both route parameters (foo) and query parameters (?q=1)
  • Verifying that queryParams contains the merged result: {"test":"foo","q":"1"}
  • Ensuring individual parameter access works correctly (q: "1")
  • Confirming proper JSON response format and HTTP status codes

This test case provides solid coverage for the query parameter consistency fix between PSR-7 and Yii2 Request implementations.

src/adapter/ServerRequestAdapter.php (3)

51-56: LGTM! Well-implemented caching property.

The private $queryParams property is properly documented, typed, and initialized. The caching approach will improve performance by avoiding redundant parameter merging operations.


228-252: LGTM! Efficient caching implementation.

The caching logic is well-implemented with proper fallback behavior. The method maintains backward compatibility while providing performance benefits when parameters have been resolved and cached.


411-413: LGTM! Proper caching integration.

The modification correctly populates the cache with merged parameters and returns the cached result. This ensures consistent behavior between resolve() and getQueryParams() methods, aligning with the PR objective of standardizing query parameter handling.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_mini_52

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (36b16de) to head (fcf39d4).

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #65   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       296       297    +1     
===========================================
  Files             12        12           
  Lines            757       759    +2     
===========================================
+ Hits             757       759    +2     

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

@terabytesoftw terabytesoftw merged commit 3e00276 into main Aug 7, 2025
29 checks passed
@terabytesoftw terabytesoftw deleted the fix_mini_52 branch August 7, 2025 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants