Skip to content

Conversation

@terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Aug 24, 2025

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

Summary by CodeRabbit

  • Tests
    • Added a dedicated stateless HTTP routing test suite covering POST bodies, query parameters, route parameters, and combined scenarios with assertions on JSON responses, status codes, and headers.
    • Consolidated related cases into the new suite for clearer structure and maintainability.
    • Removed duplicate/overlapping tests from the older suite to reduce redundancy and flakiness.
    • Improves test reliability and confidence in routing behavior.

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

coderabbitai bot commented Aug 24, 2025

Walkthrough

Adds a new PHPUnit test class ApplicationRoutingTest with four stateless routing tests and removes the corresponding four routing tests from ApplicationTest. No production code changed.

Changes

Cohort / File(s) Summary
Add dedicated routing tests
tests/http/stateless/ApplicationRoutingTest.php
Added ApplicationRoutingTest final class with four tests validating stateless routing: POST body, GET query, combined route+query, and route-parameter handling. Each asserts 200 status, application/json; charset=UTF-8, and expected JSON responses.
Remove routing tests from existing suite
tests/http/stateless/ApplicationTest.php
Removed four routing-related test methods (site/post, site/get, site/query/foo, site/update/{id}) from ApplicationTest, leaving other tests intact.

Sequence Diagram(s)

No sequence diagrams provided — changes are a test-suite reorganization without control-flow or runtime behavior modifications.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A rabbit hops through lines of code, so spry,
I split the tests and watched them fly.
POST, GET, routes in tidy rows,
JSON gleams where neatness grows.
I nibble carrots, tests pass—hi! 🥕


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f90cf17 and e247b2b.

📒 Files selected for processing (1)
  • tests/http/stateless/ApplicationRoutingTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/http/stateless/ApplicationRoutingTest.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
✨ 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-122

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.
    • 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.
  • 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 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/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 24, 2025

Codecov Report

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

Additional details and impacted files
@@             Coverage Diff             @@
##                main      #141   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       318       318           
===========================================
  Files             12        12           
  Lines            808       808           
===========================================
  Hits             808       808           

☔ 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: 1

🧹 Nitpick comments (4)
tests/http/stateless/ApplicationRoutingTest.php (4)

28-29: Normalize REQUEST_URI and path assertions to start with “/”

PSR-7 URIs conventionally use absolute paths. Normalizing REQUEST_URI to start with “/” makes the tests more portable across different ServerRequestCreator implementations and avoids brittle assumptions when switching creators or server environments. If you adopt this, update the path assertion accordingly.

Apply this diff:

-            'REQUEST_URI' => 'site/post',
+            'REQUEST_URI' => '/site/post',
@@
-            'REQUEST_URI' => 'site/get',
+            'REQUEST_URI' => '/site/get',
@@
-            'REQUEST_URI' => 'site/query/foo?q=1',
+            'REQUEST_URI' => '/site/query/foo?q=1',
@@
-            'REQUEST_URI' => 'site/update/123',
+            'REQUEST_URI' => '/site/update/123',
@@
-            'site/update/123',
+            '/site/update/123',

Also applies to: 68-69, 103-104, 134-135, 159-160


45-52: Avoid heredoc for exact-JSON string comparisons (trailing newline risk)

Heredoc adds a trailing newline and can introduce indentation surprises. Using a plain string removes this risk and keeps the assertion strict.

Apply this diff:

-        self::assertSame(
-            <<<JSON
-            {"foo":"bar","a":{"b":"c"}}
-            JSON,
-            $response->getBody()->getContents(),
+        self::assertSame(
+            '{"foo":"bar","a":{"b":"c"}}',
+            $response->getBody()->getContents(),
             "Response body should match expected JSON string '{\"foo\":\"bar\",\"a\":{\"b\":\"c\"}}' for " .
             "'site/post' route.",
         );
@@
-        self::assertSame(
-            <<<JSON
-            {"foo":"bar","a":{"b":"c"}}
-            JSON,
-            $response->getBody()->getContents(),
+        self::assertSame(
+            '{"foo":"bar","a":{"b":"c"}}',
+            $response->getBody()->getContents(),
             "Response body should match expected JSON string '{\"foo\":\"bar\",\"a\":{\"b\":\"c\"}}' for " .
             "'site/get' route.",
         );

Optional: if you want robustness to key ordering/whitespace changes, use PHPUnit’s JSON comparator instead of exact string equality:

-        self::assertSame('{"foo":"bar","a":{"b":"c"}}', $response->getBody()->getContents(), ...);
+        self::assertJsonStringEqualsJsonString('{"foo":"bar","a":{"b":"c"}}', (string) $response->getBody(), ...);

Also applies to: 85-92


100-104: Redundant source of query params

You set q=1 in both $_GET and the REQUEST_URI. One source is enough; prefer the URI for clarity in these routing tests.

Apply this diff:

-        $_GET = ['q' => '1'];
-        $_SERVER = [
+        $_SERVER = [
             'REQUEST_METHOD' => 'GET',
-            'REQUEST_URI' => 'site/query/foo?q=1',
+            'REQUEST_URI' => '/site/query/foo?q=1',
         ];

20-35: Reduce global-state coupling: build requests explicitly instead of using superglobals

These tests currently rely on mutating superglobals and createFromGlobals(). That’s fine, but it’s slightly brittle and impedes parallelization. Constructing ServerRequest instances directly yields cleaner, side-effect-free tests and mirrors how the app would be used in production.

Apply this diff to create explicit requests (pattern shown for all four tests):

@@
-        $_POST = [
-            'foo' => 'bar',
-            'a' => [
-                'b' => 'c',
-            ],
-        ];
-        $_SERVER = [
-            'REQUEST_METHOD' => 'POST',
-            'REQUEST_URI' => 'site/post',
-        ];
-
         $app = $this->statelessApplication();
-
-        $response = $app->handle(FactoryHelper::createServerRequestCreator()->createFromGlobals());
+        $request = FactoryHelper::createRequest(
+            method: 'POST',
+            uri: '/site/post',
+            headers: ['Content-Type' => 'application/x-www-form-urlencoded'],
+            parsedBody: [
+                'foo' => 'bar',
+                'a' => ['b' => 'c'],
+            ],
+        );
+        $response = $app->handle($request);
@@
-        $_GET = [
-            'foo' => 'bar',
-            'a' => [
-                'b' => 'c',
-            ],
-        ];
-        $_SERVER = [
-            'REQUEST_METHOD' => 'GET',
-            'REQUEST_URI' => 'site/get',
-        ];
-
         $app = $this->statelessApplication();
-
-        $response = $app->handle(FactoryHelper::createServerRequestCreator()->createFromGlobals());
+        $request = FactoryHelper::createRequest(
+            method: 'GET',
+            uri: '/site/get?foo=bar&a[b]=c',
+        );
+        $response = $app->handle($request);
@@
-        $_GET = ['q' => '1'];
-        $_SERVER = [
-            'REQUEST_METHOD' => 'GET',
-            'REQUEST_URI' => 'site/query/foo?q=1',
-        ];
-
         $app = $this->statelessApplication();
-
-        $response = $app->handle(FactoryHelper::createServerRequestCreator()->createFromGlobals());
+        $request = FactoryHelper::createRequest(
+            method: 'GET',
+            uri: '/site/query/foo?q=1',
+        );
+        $response = $app->handle($request);
@@
-        $_SERVER = [
-            'REQUEST_METHOD' => 'GET',
-            'REQUEST_URI' => 'site/update/123',
-        ];
-
-        $request = FactoryHelper::createServerRequestCreator()->createFromGlobals();
-
         $app = $this->statelessApplication();
-
+        $request = FactoryHelper::createRequest(
+            method: 'GET',
+            uri: '/site/update/123',
+        );
         $response = $app->handle($request);

If you keep createFromGlobals(), consider marking this test group as non-parallel in your phpunit.xml to avoid cross-test interference. See the follow-up below.

Also applies to: 60-74, 100-109, 132-142

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 53cfe84 and f90cf17.

📒 Files selected for processing (2)
  • tests/http/stateless/ApplicationRoutingTest.php (1 hunks)
  • tests/http/stateless/ApplicationTest.php (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/http/stateless/ApplicationTest.php
🧰 Additional context used
🧠 Learnings (1)
📚 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/http/stateless/ApplicationRoutingTest.php
🧬 Code graph analysis (1)
tests/http/stateless/ApplicationRoutingTest.php (3)
tests/support/FactoryHelper.php (2)
  • FactoryHelper (46-268)
  • createServerRequestCreator (154-161)
tests/TestCase.php (2)
  • TestCase (23-227)
  • statelessApplication (134-197)
src/http/StatelessApplication.php (1)
  • handle (269-295)
⏰ 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 (1)
tests/http/stateless/ApplicationRoutingTest.php (1)

12-14: Good extraction and focused scope

Creating a dedicated ApplicationRoutingTest and grouping it under http clarifies intent and keeps routing concerns isolated from broader application tests. The tests also correctly go through $app->handle($request), which aligns with our prior learning about initializing components before exercising request-dependent logic.

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