Skip to content

Conversation

@terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Aug 19, 2025

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

Summary by CodeRabbit

  • Tests
    • Added a test validating stateless exception pages render expected details (HTTP 500, Content-Type text/html; charset=UTF-8) and include the exception class, exact message, and file references while preserving output state and test environment.
  • Style
    • Minor whitespace cleanup in error-rendering code with no behavioral change.

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

coderabbitai bot commented Aug 19, 2025

Walkthrough

Adds a PHPUnit test that verifies template-based exception rendering receives the exception parameter and checks response details; also a whitespace-only insertion in ErrorHandler's HTML render branch and added PHP function imports in the test file.

Changes

Cohort / File(s) Summary
Tests: Stateless exception rendering
tests/http/StatelessApplicationTest.php
Adds testRenderExceptionPassesExceptionParameterToTemplateView(): configures errorAction = null, triggers an exception, asserts HTTP 500, Content-Type: text/html; charset=UTF-8, response body contains exception class, exact message, and a reference to SiteController.php; preserves output buffer, toggles YII_ENV_TEST, installs a custom error handler to capture warnings, and imports set_error_handler, restore_error_handler, and str_contains.
Error handling (whitespace)
src/http/ErrorHandler.php
Whitespace-only change: inserts a blank line after $file assignment in renderException() HTML path; no behavioral change.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I nibble at tests with eager paws,
A template caught my error cause.
500 echoes, HTML in sight,
The trace and message gleam so bright.
Hooray — a rabbit's hop of delight! 🐇✨


📜 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 a76bf49 and b947292.

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

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

Codecov Report

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

Additional details and impacted files
@@             Coverage Diff             @@
##                main      #106   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       320       320           
===========================================
  Files             12        12           
  Lines            810       810           
===========================================
  Hits             810       810           

☔ 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 (1)
tests/http/StatelessApplicationTest.php (1)

939-944: Reduce brittleness of exception heading assertion.

This assert hardcodes the exact HTML and phrasing of the exception heading. Minor template or encoder changes (e.g., quotes, spacing, or prefix text) will break it. Prefer asserting the essentials: class and message presence.

Example refactor:

-        self::assertStringContainsString(
-            '<pre>Exception (Exception) &apos;yii\base\Exception&apos; with message &apos;Exception error message.&apos;',
-            $responseBody,
-            "Response 'body' should contain exception class and message when 'exception' parameter is passed to " .
-            "'renderFile()' method in 'StatelessApplication'.",
-        );
+        self::assertStringContainsString(
+            'yii\base\Exception',
+            $responseBody,
+            "Response 'body' should contain exception class when 'exception' parameter is passed to 'renderFile()'.",
+        );
+        self::assertStringContainsString(
+            'Exception error message.',
+            $responseBody,
+            "Response 'body' should contain exception message when 'exception' parameter is passed to 'renderFile()'.",
+        );
📜 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 b9fcf0a and 7d0dd25.

📒 Files selected for processing (1)
  • tests/http/StatelessApplicationTest.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/http/StatelessApplicationTest.php (3)
tests/support/FactoryHelper.php (2)
  • FactoryHelper (46-268)
  • createServerRequestCreator (154-161)
tests/TestCase.php (1)
  • statelessApplication (124-187)
src/http/StatelessApplication.php (1)
  • handle (269-295)
🪛 GitHub Actions: build
tests/http/StatelessApplicationTest.php

[error] 949-949: PHPUnit test failed: StatelessApplicationTest::testRenderExceptionPassesExceptionParameterToTemplateView. Assertion failed: Response body should contain stack trace information when an exception is passed to renderFile() in StatelessApplication. Command: vendor/bin/phpunit --colors=always --coverage-clover=coverage.xml --log-junit junit.xml.

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: 2

📜 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 0c568e2 and 922ed35.

📒 Files selected for processing (2)
  • src/http/ErrorHandler.php (1 hunks)
  • tests/http/StatelessApplicationTest.php (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/http/ErrorHandler.php
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-03T16:24:09.241Z
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
🧬 Code Graph Analysis (1)
tests/http/StatelessApplicationTest.php (4)
tests/http/ErrorHandlerTest.php (1)
  • RequiresPhpExtension (22-61)
tests/support/FactoryHelper.php (2)
  • FactoryHelper (46-268)
  • createServerRequestCreator (154-161)
tests/TestCase.php (1)
  • statelessApplication (124-187)
src/http/StatelessApplication.php (1)
  • handle (269-295)
🪛 GitHub Actions: build
tests/http/StatelessApplicationTest.php

[error] 958-958: Response 'body' should contain file path where exception occurred when 'exception' parameter is passed to 'renderFile()'.


[warning] 904-904: Risky test: StatelessApplicationTest::testRenderExceptionPassesExceptionParameterToTemplateView. Test code or tested code closed output buffers other than its own.

⏰ 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). (1)
  • GitHub Check: phpunit / PHP 8.2-windows-latest

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

♻️ Duplicate comments (1)
tests/http/StatelessApplicationTest.php (1)

906-965: Always restore output buffers and YII_ENV_TEST via try/finally.

If any assertion fails, cleanup won’t run, leaving altered buffering levels and YII_ENV_TEST=false for later tests. Wrap the main body in try/finally so cleanup is guaranteed.

Apply this diff:

         @\runkit_constant_redefine('YII_ENV_TEST', false);

         $initialBufferLevel = ob_get_level();

-        $_SERVER = [
+        try {
+            $_SERVER = [
             'REQUEST_METHOD' => 'GET',
             'REQUEST_URI' => 'site/trigger-exception',
-        ];
+            ];

-        $request = FactoryHelper::createServerRequestCreator()->createFromGlobals();
+            $request = FactoryHelper::createServerRequestCreator()->createFromGlobals();

-        $app = $this->statelessApplication(
-            [
-                'components' => [
-                    'errorHandler' => [
-                        'errorAction' => null,
-                    ],
-                ],
-            ],
-        );
+            $app = $this->statelessApplication(
+                [
+                    'components' => [
+                        'errorHandler' => [
+                            'errorAction' => null,
+                        ],
+                    ],
+                ],
+            );

-        $response = $app->handle($request);
+            $response = $app->handle($request);

-        self::assertSame(
+            self::assertSame(
             500,
             $response->getStatusCode(),
             "Response 'status code' should be '500' when exception occurs and template rendering is used in " .
             "'StatelessApplication'.",
-        );
-        self::assertSame(
+            );
+            self::assertSame(
             'text/html; charset=UTF-8',
             $response->getHeaderLine('Content-Type'),
             "Response 'Content-Type' should be 'text/html; charset=UTF-8' for exception template rendering in " .
             "'StatelessApplication'.",
-        );
+            );

-        $responseBody = $response->getBody()->getContents();
+            $responseBody = $response->getBody()->getContents();

-        self::assertStringContainsString(
+            self::assertStringContainsString(
             'yii\base\Exception',
             $responseBody,
             "Response 'body' should contain exception class when 'exception' parameter is passed to 'renderFile()'.",
-        );
-        self::assertStringContainsString(
+            );
+            self::assertStringContainsString(
             'Exception error message.',
             $responseBody,
             "Response 'body' should contain exception message when 'exception' parameter is passed to 'renderFile()'.",
-        );
-        self::assertStringContainsString(
-            '[internal function]: yii2\extensions\psrbridge\tests\support\stub\SiteController-&gt;actionTriggerException()',
-            $responseBody,
-            "Response 'body' should contain exception trace when 'exception' parameter is passed to 'renderFile()'.",
-        );
-
-        while (ob_get_level() < $initialBufferLevel) {
-            ob_start();
-        }
-
-        @\runkit_constant_redefine('YII_ENV_TEST', true);
+            );
+            // See separate comment to switch this to a resilient regex assertion.
+        } finally {
+            while (ob_get_level() < $initialBufferLevel) {
+                ob_start();
+            }
+            @\runkit_constant_redefine('YII_ENV_TEST', true);
+        }
🧹 Nitpick comments (1)
tests/http/StatelessApplicationTest.php (1)

954-958: Make the stack-trace assertion resilient to formatting differences.

The exact trace line can vary across PHP/Yii versions and formatting (e.g., optional “[internal function]: ” prefix, HTML-escaped vs raw “->”). Prefer a tolerant regex to avoid future flakes.

Apply this diff:

-        self::assertStringContainsString(
-            '[internal function]: yii2\extensions\psrbridge\tests\support\stub\SiteController-&gt;actionTriggerException()',
-            $responseBody,
-            "Response 'body' should contain exception trace when 'exception' parameter is passed to 'renderFile()'.",
-        );
+        self::assertMatchesRegularExpression(
+            // Accept optional "[internal function]:", allow HTML-escaped or raw '->'
+            '~(?:\[internal function\]:\s*)?yii2\\\\extensions\\\\psrbridge\\\\tests\\\\support\\\\stub\\\\SiteController-(?:&gt;|->)actionTriggerException\(\)~',
+            $responseBody,
+            "Response 'body' should reference SiteController::actionTriggerException() in the stack trace (robust to HTML escaping and optional '[internal function]').",
+        );
📜 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 922ed35 and a76bf49.

📒 Files selected for processing (1)
  • tests/http/StatelessApplicationTest.php (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📚 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/http/StatelessApplicationTest.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/http/StatelessApplicationTest.php
📚 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/http/StatelessApplicationTest.php
📚 Learning: 2025-08-08T15:24:06.085Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#71
File: tests/TestCase.php:23-27
Timestamp: 2025-08-08T15:24:06.085Z
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/http/StatelessApplicationTest.php
📚 Learning: 2025-08-08T15:28:00.166Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#71
File: tests/adapter/ServerRequestAdapterTest.php:2215-2215
Timestamp: 2025-08-08T15:28:00.166Z
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/http/StatelessApplicationTest.php
📚 Learning: 2025-08-08T15:28:00.166Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#71
File: tests/adapter/ServerRequestAdapterTest.php:2215-2215
Timestamp: 2025-08-08T15:28:00.166Z
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/http/StatelessApplicationTest.php
🧬 Code Graph Analysis (1)
tests/http/StatelessApplicationTest.php (4)
tests/http/ErrorHandlerTest.php (1)
  • RequiresPhpExtension (22-61)
tests/support/FactoryHelper.php (2)
  • FactoryHelper (46-268)
  • createServerRequestCreator (154-161)
tests/TestCase.php (1)
  • statelessApplication (124-187)
src/http/StatelessApplication.php (1)
  • handle (269-295)
🔇 Additional comments (1)
tests/http/StatelessApplicationTest.php (1)

929-953: Solid coverage of status, headers, and key exception details.

Asserting 500 status, HTML content type, exception class, and message looks good and is aligned with how ErrorHandler renders in HTML mode with errorAction disabled.

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