-
-
Notifications
You must be signed in to change notification settings - Fork 1
refactor(tests): Move server parameter tests to new ServerParamsPsr7Test class for better organization and clarity.
#72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…Test` class for better organization and clarity.
WalkthroughA new test class, Changes
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)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. |
There was a problem hiding this 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 keysYou 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 globalsTo 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
📒 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 groupingGood 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 setTest 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 verifiedThe
FactoryHelper::createRequest()method declares a$serverParamsparameter, and theRequestclass implements bothsetPsr7Request()andgetServerParams(). Named‐argument usage forserverParamsis valid—no changes required.
Summary by CodeRabbit