Skip to content

Conversation

@terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Aug 9, 2025

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

Summary by CodeRabbit

  • Tests
    • Added new tests to verify server parameter handling when using PSR-7 requests.
    • Relocated related test cases to a dedicated test class for improved organization.

…Test` class for better organization and clarity.
@coderabbitai
Copy link

coderabbitai bot commented Aug 9, 2025

Walkthrough

A new test class, ServerParamsPsr7Test, is introduced to verify server parameter handling when using PSR-7 requests in the adapter. Simultaneously, three corresponding server parameter tests are removed from the existing ServerRequestAdapterTest class. No other logic or functional changes are made.

Changes

Cohort / File(s) Change Summary
New PSR-7 Server Params Test Class
tests/adapter/ServerParamsPsr7Test.php
Adds a new PHPUnit test class with three methods to validate server parameter handling when using a PSR-7 request adapter. Tests focus on overriding and ignoring global $_SERVER values and handling of null/missing parameters.
Removed Server Params Tests from Adapter Test
tests/adapter/ServerRequestAdapterTest.php
Removes three test methods related to server parameter handling with PSR-7 requests, which are now covered in the new dedicated test class. No other changes to the file.

Sequence Diagram(s)

sequenceDiagram
    participant Test as ServerParamsPsr7Test
    participant Factory as PSR7RequestFactory
    participant Adapter as Request Adapter
    participant PSR7Req as PSR-7 Request

    Test->>Factory: Create PSR-7 Request (with/without server params)
    Factory-->>Test: Return PSR-7 Request
    Test->>Adapter: Set PSR-7 Request
    Test->>Adapter: Call getServerParams()
    Adapter->>PSR7Req: Retrieve server parameters
    Adapter-->>Test: Return server parameters (override or ignore $_SERVER)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested labels

bug

Poem

A bunny with tests, so clever and neat,
Hopped from one class to a brand new seat.
Old checks removed, new ones in place,
Ensuring server params keep a steady pace.
With PSR-7, the code’s now tight—
The garden of tests is blooming right! 🐇


📜 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 147836f and 017d078.

📒 Files selected for processing (1)
  • tests/adapter/ServerParamsPsr7Test.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/adapter/ServerParamsPsr7Test.php
⏰ 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). (3)
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
✨ 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_59

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 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d8d9800) to head (017d078).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #72   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       309       309           
===========================================
  Files             12        12           
  Lines            784       784           
===========================================
  Hits             784       784           

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
tests/adapter/ServerParamsPsr7Test.php (3)

67-71: Clarify assertion message (it's explicitly set to null, not “not set”)

Message says “not set”, but the test explicitly passes null in serverParams. Suggest rewording for accuracy.

-            "Server parameter 'REQUEST_TIME' should be 'null' when not set in PSR-7 'serverParams', even if present " .
-            'in global $_SERVER.',
+            "Server parameter 'REQUEST_TIME' should be null when explicitly set to null in PSR-7 'serverParams', even if present in global \$_SERVER.",

60-72: Optional: strengthen coverage by asserting other overridden keys

You already assert REMOTE_ADDR and a null override. Consider also asserting other overridden fields from the PSR-7 request for completeness.

         $serverParams = $request->getServerParams();

         self::assertSame(
             '10.0.0.50',
             $serverParams['REMOTE_ADDR'] ?? null,
             "Server parameter 'REMOTE_ADDR' should be taken from PSR-7 'serverParams', not from global \$_SERVER.",
         );
         self::assertNull(
             $serverParams['REQUEST_TIME'] ?? null,
-            "Server parameter 'REQUEST_TIME' should be 'null' when not set in PSR-7 'serverParams', even if present " .
-            'in global $_SERVER.',
+            "Server parameter 'REQUEST_TIME' should be null when explicitly set to null in PSR-7 'serverParams', even if present in global \$_SERVER.",
         );
+        self::assertSame(
+            '203.0.113.1',
+            $serverParams['HTTP_X_FORWARDED_FOR'] ?? null,
+            "'HTTP_X_FORWARDED_FOR' should be taken from PSR-7 'serverParams'.",
+        );
+        self::assertSame(
+            'new.example.com',
+            $serverParams['SERVER_NAME'] ?? null,
+            "'SERVER_NAME' should be taken from PSR-7 'serverParams'.",
+        );

89-105: Optional: assert no extra keys leak from globals

To ensure only PSR-7 serverParams are returned, assert the count. This keeps the intent while avoiding brittle key-order checks.

         $serverParams = $request->getServerParams();

         self::assertSame(
             '203.0.113.1',
             $serverParams['HTTP_X_FORWARDED_FOR'] ?? null,
             "'HTTP_X_FORWARDED_FOR' should match the value from PSR-7 'serverParams'.",
         );
         self::assertSame(
             '1234567890',
             $serverParams['REQUEST_TIME'] ?? null,
             "'REQUEST_TIME' should match the value from PSR-7 'serverParams'.",
         );
+        self::assertCount(
+            2,
+            $serverParams,
+            'Only parameters present in PSR-7 serverParams should be returned.',
+        );
         self::assertNull(
             $serverParams['REMOTE_ADDR'] ?? null,
             "'REMOTE_ADDR' should not be set when not present in PSR-7 'serverParams'.",
         );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d8d9800 and 147836f.

📒 Files selected for processing (2)
  • tests/adapter/ServerParamsPsr7Test.php (1 hunks)
  • tests/adapter/ServerRequestAdapterTest.php (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/adapter/ServerRequestAdapterTest.php
🧰 Additional context used
🧠 Learnings (9)
📓 Common learnings
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#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.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#71
File: tests/adapter/ServerRequestAdapterTest.php:2215-2215
Timestamp: 2025-08-08T15:28:00.137Z
Learning: In yii2-extensions/psr-bridge, tests extend tests/TestCase which defines a protected const COOKIE_VALIDATION_KEY. Test code should use self::COOKIE_VALIDATION_KEY instead of hardcoded cookieValidationKey literals.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#71
File: tests/adapter/ServerRequestAdapterTest.php:2215-2215
Timestamp: 2025-08-08T15:28:00.137Z
Learning: In yii2-extensions/psr-bridge tests, prefer using self::COOKIE_VALIDATION_KEY from tests/TestCase over hardcoded 'cookieValidationKey' strings to avoid secret scanners FP and improve maintainability.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#71
File: tests/TestCase.php:23-27
Timestamp: 2025-08-08T15:24:06.045Z
Learning: In yii2-extensions/psr-bridge (tests/TestCase.php), maintainer preference: it’s acceptable to use random-looking strings for test-only constants like COOKIE_VALIDATION_KEY; no need to replace with an obviously non-secret value unless CI/secret scanners become problematic.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#64
File: tests/http/StatelessApplicationTest.php:1939-1967
Timestamp: 2025-08-06T22:52:05.608Z
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#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.
📚 Learning: 2025-07-20T16:33:57.495Z
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/adapter/ServerParamsPsr7Test.php
📚 Learning: 2025-07-20T16:35:15.341Z
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/adapter/ServerParamsPsr7Test.php
📚 Learning: 2025-07-20T16:35:15.341Z
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/adapter/ServerParamsPsr7Test.php
📚 Learning: 2025-08-08T15:24:06.045Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#71
File: tests/TestCase.php:23-27
Timestamp: 2025-08-08T15:24:06.045Z
Learning: In yii2-extensions/psr-bridge (tests/TestCase.php), maintainer preference: it’s acceptable to use random-looking strings for test-only constants like COOKIE_VALIDATION_KEY; no need to replace with an obviously non-secret value unless CI/secret scanners become problematic.

Applied to files:

  • tests/adapter/ServerParamsPsr7Test.php
📚 Learning: 2025-08-08T15:28:00.137Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#71
File: tests/adapter/ServerRequestAdapterTest.php:2215-2215
Timestamp: 2025-08-08T15:28:00.137Z
Learning: In yii2-extensions/psr-bridge tests, prefer using self::COOKIE_VALIDATION_KEY from tests/TestCase over hardcoded 'cookieValidationKey' strings to avoid secret scanners FP and improve maintainability.

Applied to files:

  • tests/adapter/ServerParamsPsr7Test.php
📚 Learning: 2025-08-08T15:28:00.137Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#71
File: tests/adapter/ServerRequestAdapterTest.php:2215-2215
Timestamp: 2025-08-08T15:28:00.137Z
Learning: In yii2-extensions/psr-bridge, tests extend tests/TestCase which defines a protected const COOKIE_VALIDATION_KEY. Test code should use self::COOKIE_VALIDATION_KEY instead of hardcoded cookieValidationKey literals.

Applied to files:

  • tests/adapter/ServerParamsPsr7Test.php
📚 Learning: 2025-08-06T22:52:05.608Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#64
File: tests/http/StatelessApplicationTest.php:1939-1967
Timestamp: 2025-08-06T22:52:05.608Z
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.

Applied to files:

  • tests/adapter/ServerParamsPsr7Test.php
📚 Learning: 2025-07-22T00:50:26.546Z
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.

Applied to files:

  • tests/adapter/ServerParamsPsr7Test.php
⏰ 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 (3)
tests/adapter/ServerParamsPsr7Test.php (3)

12-16: Solid separation and grouping

Good move isolating PSR-7 server params behavior into its own class and grouping with PHPUnit attributes. Clear and maintainable.


17-35: Correct: ignores global $_SERVER when PSR-7 request is set

Test intent and assertions are correct. Also aligned with project’s TestCase behavior (auto cleanup of $_SERVER), so no manual restoration needed.


27-31: Helper signature and Request methods verified

The FactoryHelper::createRequest() method declares a $serverParams parameter, and the Request class implements both setPsr7Request() and getServerParams(). Named‐argument usage for serverParams is valid—no changes required.

@terabytesoftw terabytesoftw merged commit 6674027 into main Aug 9, 2025
29 checks passed
@terabytesoftw terabytesoftw deleted the fix_mini_59 branch August 9, 2025 10:36
@terabytesoftw terabytesoftw added the bug Something isn't working label Aug 9, 2025
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